A powerful deep learning framework that provides flexibility and speed for research and production
PyTorch is an open-source machine learning library developed by Facebook's AI Research lab. It's known for its dynamic computational graph and intuitive interface, making it popular among researchers and developers for deep learning projects.
# Install PyTorch
pip install torch torchvision
# Import PyTorch
import torch
import torch.nn as nn
# Create a simple neural network
class SimpleNN(nn.Module):
def __init__(self):
super(SimpleNN, self).__init__()
self.layer1 = nn.Linear(784, 128)
self.layer2 = nn.Linear(128, 10)
def forward(self, x):
x = torch.relu(self.layer1(x))
x = self.layer2(x)
return x