预期输入具有4个维度,但数组具有形状 [英] expected input to have 4 dimensions, but got array with shape

查看:82
本文介绍了预期输入具有4个维度,但数组具有形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到此错误

检查输入时出错:预期input_13具有4维,但数组的形状为(7,100,100)

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

对于以下代码,我应该如何调整数组的形状以适合4维,我进行了搜索,但不了解先前的解决方案.请问是否不清楚其在卷积神经网络中非常普遍的问题.

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)

推荐答案

如果x是您的数据数组,则只需应用以下转换:

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

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

这篇关于预期输入具有4个维度,但数组具有形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆