- PyTorch Workflow Fundamentals
- Getting data ready
- Train model
- Saving and loading a model
Exercise
- Building a model
- Putting it all together
- Making predictions and evaluating a model (inference)
Split data into training and test sets
Data
PyTorch model building essentials
Checking the contents of a PyTorch model
Making predictions using torch.inference_mode()
torch.nn.Module
torch.optim
torch.nn.Parameter
def forward()
torch.nn
.parameters().
.state_dict().
optimization function
PyTorch training loop
loss function
PyTorch testing loop
(with torch.inference_mode(): y_preds = model_0(X_test)).
All predictions should be made with objects on the same device (e.g. data and model on GPU only or data and model on CPU only).
evaluation mode (model.eval()).
Saving a PyTorch model's state_dict()
Loading a saved PyTorch model's state_dict()
torch.save
torch.load
torch.nn.Module.load_state_dict
6.3 Training
6.2 Building a PyTorch linear model
6.4 Making predictions
6.1 Data
6.5 Saving and loading a model
Create Data
Create Know Parameters
Validation set (10-20%)
Testing set (10-20%)
Training set (60-80%)
Plot predictions
Draw
Create a Linear Regression model class + Forward
Zero gradients
Perform backpropagation on the loss
Calculate the loss
Update the optimizer (gradient descent)
Forward pass
Forward pass
Calculate the loss
Calulate evaluation metrics (optional)
Save the model state dict
Create model save path
Create models directory
Load the state_dict
Instantiate a new instance