简体   繁体   English

keras 顺序 model 用于图像数据

[英]keras sequential model for image data

i'm trying to train a dense network for images.我正在尝试为图像训练一个密集的网络。

the train set shape returns:火车集合形状返回:

train_X.shape
(26032, 32, 32)

and the network architecture is:网络架构是:

def get_model(input_shape):
    model = Sequential([
    Dense(16, activation='relu', input_shape=(input_shape[1],input_shape[2],1)),
    Dense(8, activation='relu'),
    Dense(64, activation='relu'),
    Flatten(),
    Dense(10, activation='softmax')]) 
    return model

but i get an error when i try to train it:但是当我尝试训练它时出现错误:

Error when checking input: expected dense_17_input to have 4 dimensions, but got array with shape (73257, 32, 32)检查输入时出错:预期的 dense_17_input 有 4 个维度,但得到了形状为 (73257, 32, 32) 的数组

can u assist please?你能帮忙吗?

For this specific architecture, you don't need a 4th dimension.对于这个特定的架构,您不需要第四维。 In input_shape , you won't need to add a 1 .input_shape中,您不需要添加1

 input_shape=(input_shape[1], input_shape[2])

You will only need to do so for a CNN.您只需要为 CNN 执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM