Files
pytorch-study/17.ipynb

2.1 KiB

In [1]:
import torch
import torch.nn as nn

y = torch.randn(2)
print(y)

m = nn.Softmax(dim=0)
out = m(y)
print(out)
tensor([-0.9296, -0.1961])
tensor([0.3244, 0.6756])
In [2]:
x = torch.randint(0, 255, (1, 128 * 128), dtype=torch.float32)
fc = nn.Linear(128 * 128, 2)
y = fc(x)
print(y)
tensor([[59.5330, 43.6760]], grad_fn=<AddmmBackward0>)
In [3]:
output = nn.Softmax(dim=1)(y)
print(output)
tensor([[1.0000e+00, 1.2984e-07]], grad_fn=<SoftmaxBackward0>)