Chapter1 Intro
Chapter1 Intro
learning with
PyTorch
INTRODUCTION TO DEEP LEARNING WITH PYTORCH
Self-driving cars
Medical diagnostics
Chatbots
import torch
PyTorch supports
image data with torchvision
torch.Size([2, 3])
Deep learning often requires a GPU, which,
Tensor data type compared to a CPU can offer:
a + b a + c
tensor([[2, 2],
[6, 6]])
tensor([[-0.2415, -0.1604]],
grad_fn=<AddmmBackward0>)
linear_layer.weight linear_layer.bias
y0 = W0 ⋅ X + b0
out_features = 2
Output dimensions: 1 × 2
tensor([[-0.0014, 0.4038, 1.0305, 0.7521, 0.7489, -0.3968, 0.0113, -1.3844, 0.8705, -0.9743]])
input_tensor = torch.tensor([[6.0]])
sigmoid = nn.Sigmoid()
output = sigmoid(input_tensor)
tensor([[0.9975]])
Note. Sigmoid as last step in network of linear layers is equivalent to traditional logistic
regression.
print(output_tensor)