Introdução ao Aprendizado Profundo com o PyTorch
Jasmin Ludolf
Senior Data Science Content Developer, DataCamp
$$
$$
$$
Possíveis saídas:
# Create binary classification model
model = nn.Sequential(
nn.Linear(6, 4), # First linear layer
nn.Linear(4, 1), # Second linear layer
nn.Sigmoid() # Sigmoid activation function
)
# Pass input data through model
output = model(input_data)
print(output)
tensor([[0.5188], [0.3761], [0.5015], [0.3718], [0.4663]],
grad_fn=<SigmoidBackward0>)
Saída: cinco probabilidades entre 0 e 1, uma para cada animal
Classificação (limite de 0.5):
0.5188
, 0.5015
) 0.3761
, 0.3718
, 0.4633
)n_classes = 3
# Create multi-class classification model model = nn.Sequential( nn.Linear(6, 4), # First linear layer nn.Linear(4, n_classes), # Second linear layer
nn.Softmax(dim=-1) # Softmax activation )
# Pass input data through model output = model(input_data) print(output.shape)
torch.Size([5, 3])
# Create regression model
model = nn.Sequential(
nn.Linear(6, 4), # First linear layer
nn.Linear(4, 1) # Second linear layer
)
# Pass input data through model
output = model(input_data)
# Return output
print(output)
tensor([[0.3818],
[0.0712],
[0.3376],
[0.0231],
[0.0757]],
grad_fn=<AddmmBackward0>)
Introdução ao Aprendizado Profundo com o PyTorch