I am trying to convert the following Pytorch Model to Keras.
class Net(nn.Module):
def init(self):
super(Net, self).init()
self.fc1 = nn.Linear(28 * 28, 128)
self.fc2 = nn.Linear(128, 64)
self.fc3 = nn.Linear(64, 10)
def forward(self, x):
x = x.view(-1, 28 * 28)
x = F.relu(self.fc1(x))
x = F.relu(self.fc2(x))
x = self.fc3(x)
return x
input_shape is (28,28,1). Since Linear layer in Pytorch is equivalent to Dense in Keras, I tried the following:
model = Sequential()
model.add(Dense(128, input_shape=(28,28,1)))
model.add(Activation(‘relu’))
model.add(Dropout(0.2))
model.add(Flatten())
model.add(Dense(64, input_shape=(28,28,128)))
model.add(Activation(‘relu’))
model.add(Dropout(0.2))
model.add(Dense(10,input_shape=(28,28,64)))
Is this conversion correct?
Many thanks for your help!