I'm running a 2d convolution network. My input has 3 dimension however I am getting this 4-dimension error: dimension error
As you can see my input has the correct dimensions:
correct input dimension
here is my code:
from keras import models
from keras import layers
model = models.Sequential()
model.add(layers.Conv2D(32, (3, 3), activation='relu', input_shape=(8,6171,4)))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
model.add(layers.Flatten())
model.add(layers.Dense(64, activation='relu'))
model.add(layers.Dense(10, activation='softmax'))
Why then is it asking me for 4-D when I only built a 3-D input layer?
Please help. Thanks.
You need to use
new_image = tf.expand_dims(image,0)
because the model expects a dataset instead of single images.
Add an outer batch axis by passing axis=0
, 0 is the location of the new dim (1, 416, 416, 3) if -1 will be at end
image_data = tf.expand_dims(image_data, axis=0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With