【问题标题】:keras sequential model for image data用于图像数据的 keras 顺序模型
【发布时间】:2021-03-14 12:11:38
【问题描述】:

我正在尝试为图像训练密集网络。

火车集合形状返回:

train_X.shape
(26032, 32, 32)

网络架构是:

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

但是当我尝试训练它时出现错误:

检查输入时出错:预期的 dense_17_input 有 4 个维度,但得到的数组的形状为 (73257, 32, 32)

你能帮忙吗?

【问题讨论】:

    标签: python tensorflow keras tensorflow2.0


    【解决方案1】:

    对于这种特定的架构,您不需要第 4 维。在input_shape 中,您无需添加1

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

    您只需要为 CNN 这样做。

    【讨论】:

    • 您能否评论一下不展平 32x32 图像并使用这种展平数组作为输入的利弊? (我知道的一个是权重从 32x32xunits 减少到 32xunits)
    猜你喜欢
    • 1970-01-01
    • 2021-05-09
    • 1970-01-01
    • 2019-11-08
    • 2020-07-13
    • 1970-01-01
    • 2019-12-23
    • 1970-01-01
    • 2018-07-17
    相关资源
    最近更新 更多