I am trying to build a model by `subclassing` tge tf.keras.Model. Here is what my code looks like:
class CustomModel(tf.keras.Model):
def __init__(self):
super(CustomModel, self).__init__()
self.conv1 = Conv2D(32, (3, 3), padding='same')
self.conv2 = Conv2D(64, (3, 3), padding='same')
self.pool = MaxPooling2D(pool_size=(2, 2))
self.bn = BatchNormalization()
self.relu = Activation("relu")
self.softmax = Activation("softmax")
self.drop1 = Dropout(0.25)
self.drop2 = Dropout(0.5)
self.dense1 = Dense(512)
self.dense2 = Dense(10)
self.flat = Flatten()
def call(self, inputs, train):
z = self.conv1(inputs)
z = self.bn(z, training=train)
z = self.relu(z)
z = self.conv1(z)
z = self.bn(z, training=train)
z = self.relu(z)
z = self.pool(z)
z = self.drop1(z, training=train)
z = self.conv2(z)
z = self.bn(z, training=train)
z = self.relu(z)
z = self.conv2(z)
z = self.bn(z, training=train)
z = self.relu(z)
z = self.pool(z)
z = self.drop1(z, training=train)
z = self.flat(z)
z = self.dense1(z)
z = self.relu(z)
z = self.drop2(z, training=train)
z = self.dense2(z)
z = self.softmax(z)
return z
When I am calling my model on some random input to check if it is working fine, it is failing on the first conv layer. Here is what I am doing:
random_input = np.random.rand(32,32, 3).astype(np.float32)
random_input = np.expand_dims(random_input, axis=0)
preds = model(random_input, train=False)
print(preds)
I am getting this error:
InvalidArgumentError: input depth must be evenly divisible by filter depth: 32 vs 3 [Op:Conv2D]
Can someone please tell me what is going on here?
Regards,
Aakash Nain