Training a convolutional neural network
Convolutional neural networks (CNNs) are a class of neural networks particularly effective for tasks involving grid-like input data such as images, audio spectrograms, and even certain types of time series data.
Getting ready
The central idea of CNNs is to apply a convolution operation on the input data with convolutional filters (also known as kernels), which slide over the input data to produce output feature maps.
How to do it…
For simplicity, let’s define a single-layer 1D
convolutional neural network, which is particularly suited for time series and sequence data. In PyTorch
, we can use the nn.Conv1d
layer for this:
class ConvNet(nn.Module): def __init__(self, input_size, hidden_size, output_size, ...