22.02.2024 Views

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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

of the output according to the formula below (d stands for dilation size):

Equation 8.16 - Resulting shape with dilation

If any of the resulting dimensions are not an integer, they must be rounded down.

Data Preparation

The data preparation step is very much like that of the previous models except for

the fact that we need to permute the dimensions to comply with 1D convolutions'

"sequence-last" (NFL) shape:

Data Preparation

1 train_data = TensorDataset(

2 torch.as_tensor(points).float().permute(0, 2, 1),

3 torch.as_tensor(directions).view(-1, 1).float()

4 )

5 test_data = TensorDataset(

6 torch.as_tensor(test_points).float().permute(0, 2, 1),

7 torch.as_tensor(test_directions).view(-1, 1).float()

8 )

9 train_loader = DataLoader(

10 train_data, batch_size=16, shuffle=True

11 )

12 test_loader = DataLoader(test_data, batch_size=16)

Model Configuration & Training

The model is quite simple: a single nn.Conv1d layer followed by an activation

function (ReLU), a flattening layer (which is only squeezing the channel dimension

out), and a linear layer to combine the outputs (three values for each sequence, as

shown in Figure 8.31) into logits for our binary classification.

676 | Chapter 8: Sequences

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

Saved successfully!

Ooh no, something went wrong!