I am trying to follow up on this code in Pytorch. I have been trying for days but reading tensor flow docs then PyTorch docs has made me totally confused.
input_data = Input(shape=(256, 64, 1), name=‘input’)
inner = Conv2D(32, (3, 3), padding=‘same’, name=‘conv1’, kernel_initializer=‘he_normal’)(input_data)
inner = BatchNormalization()(inner)
inner = Activation(‘relu’)(inner)
inner = MaxPooling2D(pool_size=(2, 2), name=‘max1’)(inner)
inner = Conv2D(64, (3, 3), padding=‘same’, name=‘conv2’, kernel_initializer=‘he_normal’)(inner)
inner = BatchNormalization()(inner)
inner = Activation(‘relu’)(inner)
inner = MaxPooling2D(pool_size=(2, 2), name=‘max2’)(inner)
inner = Dropout(0.3)(inner)
inner = Conv2D(128, (3, 3), padding=‘same’, name=‘conv3’, kernel_initializer=‘he_normal’)(inner)
inner = BatchNormalization()(inner)
inner = Activation(‘relu’)(inner)
inner = MaxPooling2D(pool_size=(1, 2), name=‘max3’)(inner)
inner = Dropout(0.3)(inner)
CNN to RNN
inner = Reshape(target_shape=((64, 1024)), name=‘reshape’)(inner)
inner = Dense(64, activation=‘relu’, kernel_initializer=‘he_normal’, name=‘dense1’)(inner)
RNN
inner = Bidirectional(LSTM(256, return_sequences=True), name = ‘lstm1’)(inner)
inner = Bidirectional(LSTM(256, return_sequences=True), name = ‘lstm2’)(inner)
OUTPUT
inner = Dense(num_of_characters, kernel_initializer=‘he_normal’,name=‘dense2’)(inner)
y_pred = Activation(‘softmax’, name=‘softmax’)(inner)
model = Model(inputs=input_data, outputs=y_pred)
and I tried
class Net(nn.Module):
def init(self):
super(Net,self).init()
    self.input_data = input_size
    self.conv1 = nn.Conv2d(32,3,3)
    self.conv2 = nn.Conv2d(64,3,3)
    self.conv3 = nn.Conv2d(128,3,3)
    
    #self.conv_bn = nn.BatchNorm2d()
    self.dropout = nn.Dropout(0.3)
    self.maxp = torch.nn.MaxPool2d((2,2))
    
    
    #CNN to RNN
    self.linear1 = nn.Linear(256*62*62,64)
    
    #RNN
    self.lstm = torch.nn.LSTM(256, 10,bidirectional = True)
    
    #output
    self.linear2 = nn.Linear(64,num_of_chars)
    
def forward(self,x,input_size):
    
     
    x = self.conv1(input_size)
    x = nn.BatchNorm2d(x)
    x = F.relu(x)
    x = self.maxp(x)
    x = self.conv2(x)
    x = nn.BatchNorm2d(x)
    x = F.relu(x)
    x = self.maxp(x)
    x = self.dropout(x)
    x = self.conv3(x)
    x = nn.BatchNorm2d(x)
    x = F.relu(x)
    x = self.maxp(x)
    x = self.dropout(x)
    x = x.view((64,1024))
    x = self.linear1(x)
    
    x = self.lstm(x)
    x = self.lstm(x)
    
    x = self.linear2(x)
    x = nn.Softmax(x,dim=1)
    return x

But the model summary is not at all same. I am very confused by the parameters. Any help would be appreciated. Tell me if you need anything. Thanks