Daniel Voigt Godoy - Deep Learning with PyTorch Step-by-Step A Beginner’s Guide-leanpub

peiying410632
from peiying410632 More from this publisher
22.02.2024 Views

Figure 2.5 - Scalars on TensorBoardNot very useful, eh? We need to incorporate these elements into our modelconfiguration and model training codes, which look like this now:Run - Data Preparation V2%run -i data_preparation/v2.pyTensorBoard | 159

Define - Model Configuration V31 %%writefile model_configuration/v3.py23 device = 'cuda' if torch.cuda.is_available() else 'cpu'45 # Sets learning rate - this is "eta" ~ the "n"-like Greek letter6 lr = 0.178 torch.manual_seed(42)9 # Now we can create a model and send it at once to the device10 model = nn.Sequential(nn.Linear(1, 1)).to(device)1112 # Defines an SGD optimizer to update the parameters13 optimizer = optim.SGD(model.parameters(), lr=lr)1415 # Defines an MSE loss function16 loss_fn = nn.MSELoss(reduction='mean')1718 # Creates the train_step function for our model,19 # loss function and optimizer20 train_step_fn = make_train_step_fn(model, loss_fn, optimizer)2122 # Creates the val_step function for our model and loss function23 val_step_fn = make_val_step_fn(model, loss_fn)2425 # Creates a Summary Writer to interface with TensorBoard26 writer = SummaryWriter('runs/simple_linear_regression') 127 # Fetches a single mini-batch so we can use add_graph28 x_dummy, y_dummy = next(iter(train_loader))29 writer.add_graph(model, x_dummy.to(device))1 Creating SummaryWriter to interface with TensorBoardRun - Model Configuration V3%run -i model_configuration/v3.py160 | Chapter 2: Rethinking the Training Loop

Figure 2.5 - Scalars on TensorBoard

Not very useful, eh? We need to incorporate these elements into our model

configuration and model training codes, which look like this now:

Run - Data Preparation V2

%run -i data_preparation/v2.py

TensorBoard | 159

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!