I have model written in Tensorflow and I would like to convert it to Pytorch. However I am having a lot of problems in converting because I am getting confused between functions, for instance, for Tensorflow BatchNormalization should I use BatchNorm1d or BatchNorm2?
The code in Tensorflow is this:
input = Input(shape=(216, 1025, 1))
norm_inp1 = BatchNormalization()(input)
img_1 = Convolution2D(16, kernel_size=(3, 7), activation=activations.relu)(norm_inp1)
img_1 = Convolution2D(16, kernel_size=(3, 7), activation=activations.relu)(img_1)
img_1 = MaxPooling2D(pool_size=(3, 7))(img_1)
img_1 = Dropout(rate=0.1)(img_1)
img_1 = Convolution2D(32, kernel_size=3, activation=activations.relu)(img_1)
img_1 = Convolution2D(32, kernel_size=3, activation=activations.relu)(img_1)
img_1 = MaxPooling2D(pool_size=(3, 3))(img_1)
img_1 = Dropout(rate=0.1)(img_1)
img_1 = Convolution2D(128, kernel_size=3, activation=activations.relu)(img_1)
img_1 = GlobalMaxPool2D()(img_1)
img_1 = Dropout(rate=0.1)(img_1)
I have created a class that extends torch.nn.Module in which I apply this sequential:
features = torch.nn.Sequential(
torch.nn.BatchNorm2d(1025),
torch.nn.Conv1d(16, 1, kernel_size=(3, 7)),
torch.nn.ReLU(inplace=True),
torch.nn.Conv2d(16, 16, kernel_size=(3, 7)),
torch.nn.ReLU(inplace=True),
torch.nn.MaxPool2d(kernel_size=(3,7)),
torch.nn.Dropout2d(0.1),
torch.nn.Conv2d(16, 32, kernel_size=3),
torch.nn.ReLU(inplace=True),
torch.nn.Conv2d(32, 32, kernel_size=3),
torch.nn.ReLU(inplace=True),
torch.nn.MaxPool2d(kernel_size=(3,3)),
torch.nn.Dropout2d(0.1),
torch.nn.Conv2d(32, 128, kernel_size=3),
torch.nn.ReLU(inplace=True),
torch.nn.MaxPool2d(kernel_size=(20,44)),
torch.nn.Dropout2d(0.1)
)
Could someone help me to understand the errors in the second one? I have perfectly understood the code in Tensorflow. For complete network schema you can consult this link