Jump to content

PyTorch: Difference between revisions

596 bytes added ,  2 March 2020
No edit summary
Line 7: Line 7:
# If using conda, python 3.5+, and CUDA 10.0 (+ compatible cudnn)
# If using conda, python 3.5+, and CUDA 10.0 (+ compatible cudnn)
conda install pytorch torchvision cudatoolkit=10.0 -c pytorch
conda install pytorch torchvision cudatoolkit=10.0 -c pytorch
</syntaxhighlight>
==Getting Started==
* [https://pytorch.org/tutorials/ PyTorch Tutorials]
<syntaxhighlight lang="python">
import torch
import torch.nn as nn
# Training
for epoch in range(epochs):
  running_loss = 0.0
    for i, data in enumerate(trainloader, 0):
        # get the inputs; data is a list of [inputs, labels]
        inputs, labels = data
        # zero the parameter gradients
        optimizer.zero_grad()
        # forward + backward + optimize
        outputs = net(inputs)
        loss = criterion(outputs, labels)
        loss.backward()
        optimizer.step()
</syntaxhighlight>
</syntaxhighlight>