22.02.2024 Views

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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Model Configuration

1 torch.manual_seed(21)

2 model = nn.Sequential()

3 model.add_module('conv1d', nn.Conv1d(in_channels=2,

4 out_channels=1,

5 kernel_size=2))

6 model.add_module('relu', nn.ReLU())

7 model.add_module('flatten', nn.Flatten())

8 model.add_module('output', nn.Linear(3, 1))

9

10 loss = nn.BCEWithLogitsLoss()

11 optimizer = optim.Adam(model.parameters(), lr=0.01)

Model Training

1 sbs_conv1 = StepByStep(model, loss, optimizer)

2 sbs_conv1.set_loaders(train_loader, test_loader)

3 sbs_conv1.train(100)

fig = sbs_conv1.plot_losses()

Figure 8.33 - Losses—the edge model

StepByStep.loader_apply(test_loader, sbs_conv1.correct)

1D Convolutions | 677

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

Saved successfully!

Ooh no, something went wrong!