Hi,
My Keras model looks something like this:
def init(self, in_channels=1):
super(CNN, self).__init__()
self.base_model = ResNet50(weights='imagenet', include_top=False)
self.NUM_CLASSES = 22
self.DENSE_LAYER_ACTIVATION = 'softmax'
for layer in self.base_model.layers:
layer.trainable = True
#layer_name = 'conv1_relu'
self.layer_name = 'conv3_block4_2_relu'
#layer_name = 'conv2_block2_1_relu'
self.intermediate_layer_model = Model(inputs=self.base_model.input,
outputs=self.base_model.get_layer(self.layer_name).output)
#w = self.intermediate_layer_model.output
self.GAP = GlobalAveragePooling2D()
self.Dropout = Dropout(rate=0.2)
self.Dense1 = Dense(256, activation = 'relu')
self.Dense2 = Dense(128, activation = 'relu')
self.predictions = Dense(self.NUM_CLASSES,
activation = self.DENSE_LAYER_ACTIVATION)
def forward(self, x):
x=self.base_model.get_layer(self.layer_name)(x)
print(x.shape)
x=self.GAP(x)
x=self.Dropout(x)
x=self.Dense1(x)
x=self.Dropout(x)
x=self.Dense2(x)
x=self.Dropout(x)
x=self.predictions(x)
return x
I want to convert this to pytorch. Any help would be greatly appreciated.
Thanks.