expected input to have 4 dimensions, but got array with shape

允我心安 提交于 2020-02-27 07:11:56

问题


I have this error

Error when checking input: expected input_13 to have 4 dimensions, but got array with shape (7, 100, 100)

For the following code how should I reshape array to fit with 4-dimensions, I searched for it but didn't understand the previous solutions. Please ask if not clear its very common issue in convolution neural network.

inputs=Input(shape=(100,100,1))

x=Conv2D(16,(3,3), padding='same')(inputs)
x=Activation('relu')(x)
x=Conv2D(8,(3,3))(x)
x=Activation('relu')(x)
x=MaxPooling2D(pool_size=(2,2))(x)
x=Dropout(0.2)(x)
x=Dense(num_classes)(x)
x=Activation('softmax')(x)
output=Activation('softmax')(x)
model=Model([inputs], output)

回答1:


If x is your data array you should simply apply the following transformation:

x = x.reshape((-1, 100, 100, 1))


来源:https://stackoverflow.com/questions/48794214/expected-input-to-have-4-dimensions-but-got-array-with-shape

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!