How to build my own modules(change cnn network structure)?
<SCODE>    I want to build a model like that. But I don't know how to use PyTorch basic modules to do that. I plan to train the  horizontal  parameters(CNN) at first. Then,train the vertical parameters(RNN). But,I don't know how to combine them together and train this.<ECODE>
hongyuan
This model looks like a Stacked Convolutional Recurrent Neural Network. <SCODE>import torch.nn as nn
from torch.autograd import Variable

class RNN(nn.Module):
    def __init__(self, input_size, hidden_size, output_size):
        super(RNN, self).__init__()
        
        self.hidden_size = hidden_size
        
        self.i2h = nn.Linear(input_size + hidden_size, hidden_size)
        self.i2o = nn.Linear(input_size + hidden_size, output_size)
        self.softmax = nn.LogSoftmax()
    
    def forward(self, input, hidden):
        combined = torch.cat((input, hidden), 1)
        hidden = self.i2h(combined)
        output = self.i2o(combined)
        output = self.softmax(output)
        return output, hidden

    def initHidden(self):
        return Variable(torch.zeros(1, self.hidden_size))

n_hidden = 128
rnn = RNN(n_letters, n_hidden, n_categories)
<ECODE>
pranav
Thank you! I’ll try.
hongyuan