I'm using the subclassing API to build a simple conv net and I want to use the summary method to get an idea of what the architecture looks like for my model. However, when I call model.summary(), the layers are out of order and the output shape is not shown either. Is there a clean way of getting around this? or do I need to override the model.summary() method in the model class.
Here are the layers in question:
class thing(keras.Model):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.conv1 = keras.layers.convolutional.Conv2D(96,
kernel_size= (11, 11),
strides= 4,
activation = "relu",
data_format="channels_last",
input_shape= (277,277, 3))
self.flatten = keras.layers.Flatten(data_format="channels_last")
self.dense = keras.layers.Dense(4096, activation= "relu")
self.pool = keras.layers.pooling.MaxPooling2D(pool_size= (3,3), strides = 2,
data_format="channels_last")
def call(self, inputs):
conv1 = self.conv1(inputs)
pool1 = self.pool(conv1)
flatten_conv = self.flatten(pool1)
ff_1 = self.dense(flatten_conv)
return ff_1
a = thing()
a.build(input_shape=(None, 277, 277, 3))
a.summary()
OUTPUT:
Model: "thing_9"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv2d_9 (Conv2D) multiple 34944
_________________________________________________________________
flatten_9 (Flatten) multiple 0
_________________________________________________________________
dense_14 (Dense) multiple 415240192
_________________________________________________________________
max_pooling2d_9 (MaxPooling2 multiple 0
=================================================================
Total params: 415,275,136
Trainable params: 415,275,136
Non-trainable params: 0
_________________________________________________________________