user19863392
user19863392

Reputation:

how can I solve the dimention error in input shape for Conv network?

I was trying to use the class method (not something I always use) for building a Conv network but some-reason the input dimention is not matching with the training dimentions. I had seen another similar question but in that answer it was said to use numpy to expand the dimentions. I tried both numpy and tensorflow for expanding but it gives another new error.

So, if someone can help me out, it'll be really helpfulol.

Model:

    class ANet(tf.keras.Model):
  def __init__(self):
    super(ANet, self).__init__()
    # self.shape = Input(shape=(256, 256, 3))
    self.conv1 = Conv2D(32, 3, activation='relu')
    self.pooling = MaxPool2D()
    self.flatten = Flatten()
    self.d1 = Dense(64)
    self.d2 = Dense(10)

  def call(self, x):
    x = self.conv1(x)
    x = self.flatten(x)
    x = self.d1(x)
    return self.d2(x)

model_net = ANet()


input_shape=(256, 256, 3)
model_net.build(input_shape)
model_net.summary()

Error Code

ValueError: Input 0 of layer "conv2d_8" is incompatible with the layer: expected min_ndim=4, found ndim=3. Full shape received: (256, 256, 3)

Upvotes: 0

Views: 198

Answers (1)

user19863392
user19863392

Reputation:

I have solved the problem. Tensorflow raised an error as I didn't inlcude None in the input_shape.

I changed my code to this-

# input_shape=(256, 256, 3)
model_net.build(input_shape=(None, 256, 256, 3))
model_net.summary()

And it worked!

Upvotes: 1

Related Questions