Converting feedforward NN to CNN

Hi everyone,

I’m training a basic feedforward neural network to make amino acid predictions based on protein structure information.

Here is how the NN architecture is set up:

class NeuralNetwork(nn.Module):
    def __init__(self, input_nodes):
        super(NeuralNetwork, self).__init__()
        self.flatten = nn.Flatten()
        self.linear_relu_stack = nn.Sequential(
            nn.Linear(input_nodes, 64),             # input 
            nn.ReLU(),
            nn.Dropout(p=0.5),

            nn.Linear(64, 64),                      # hidden layer 1 
            nn.ReLU(),
            nn.Dropout(p=0.5),

            nn.Linear(64, 64),                      # hidden layer 2 
            nn.ReLU(),
            nn.Dropout(p=0.5),

            nn.Linear(64, 64),                      # hidden layer 3 
            nn.ReLU(),
            nn.Dropout(p=0.5),

            nn.Linear(64, 20)                       # output
        )

I’m wondering if its possible to make modifications to the set-up above in order to convert it to a convolutional NN?
I’m using a non-image dataset, so I’m wondering if a CNN would even be possible?

Yes, you could e.g. replace the nn.Linear layers with nn.ConvXd.

Yes, it would be possible as long as the inputs are in the expected shape, e.g. [batch_size, channels, height, width] for nn.Conv2d. It depends on your use case and how you are handling the data to claim it “makes sense”. If you think your input data has a correlation between neighboring “pixels” it sounds like a valid idea to try out a CNN on this data.