Conteúdo do Curso
PyTorch Essentials
PyTorch Essentials
1. PyTorch Introduction
What is PyTorch?Introduction to TensorsTensor Creation FunctionsChallenge: Initializing TensorsCreating Random TensorsChallenge: Initializing Model Weights and BiasesMathematical Operations with TensorsChallenge: Performing Mathematical OperationsShapes and Dimensions in PyTorchChallenge: Reshaping Tensors
3. Neural Networks in PyTorch
Challenge: Classifying Flowers
Tarefa
Swipe to start coding
Your goal is to train and evaluate a simple neural network using the Iris dataset, which consists of flower measurements and species classification.
- Split the dataset into training and testing sets allocating 20% for the test set and setting random state to
42
. - Convert
X_train
andX_test
into PyTorch tensors of typefloat32
. - Convert
y_train
andy_test
into PyTorch tensors of typelong
. - Define a neural network model by creating the
IrisModel
class. - Implement two fully connected layers and apply the ReLU activation function in the hidden layer.
- Initialize the model with the correct input size, hidden layer size equal to
16
, and output size. - Define the loss as cross-entropy loss and the optimizer as Adam with a learning rate of
0.01
. - Train the model for 100 epochs by performing forward propagation, computing loss, performing backpropagation, and updating the model's parameters.
- Set the model to evaluation mode after training.
- Disable gradient computation during testing to improve efficiency.
- Compute predictions on the test set using the trained model.
- Determine the predicted class labels based on raw predictions.
Solução
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 3. Capítulo 4
Challenge: Classifying Flowers
Tarefa
Swipe to start coding
Your goal is to train and evaluate a simple neural network using the Iris dataset, which consists of flower measurements and species classification.
- Split the dataset into training and testing sets allocating 20% for the test set and setting random state to
42
. - Convert
X_train
andX_test
into PyTorch tensors of typefloat32
. - Convert
y_train
andy_test
into PyTorch tensors of typelong
. - Define a neural network model by creating the
IrisModel
class. - Implement two fully connected layers and apply the ReLU activation function in the hidden layer.
- Initialize the model with the correct input size, hidden layer size equal to
16
, and output size. - Define the loss as cross-entropy loss and the optimizer as Adam with a learning rate of
0.01
. - Train the model for 100 epochs by performing forward propagation, computing loss, performing backpropagation, and updating the model's parameters.
- Set the model to evaluation mode after training.
- Disable gradient computation during testing to improve efficiency.
- Compute predictions on the test set using the trained model.
- Determine the predicted class labels based on raw predictions.
Solução
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 3. Capítulo 4