【问题标题】:Keras Conv2d dim errorKeras Conv2d 暗淡错误
【发布时间】:2019-01-11 05:01:01
【问题描述】:

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

当我尝试将 Conv2d 添加为我的第一层时,我得到了什么。我为网络提供了 [1000,32,32] 数组,它是一千张 32x32 的图片

model = keras.Sequential([
keras.layers.Conv2D(32, (3, 3), padding='same',data_format="channels_first", input_shape=(1,32,32)),
keras.layers.Dense(128, activation=tf.tanh),
keras.layers.Dense(128,activation=tf.tanh)
])

有什么问题?如何设置输入的尺寸?

【问题讨论】:

    标签: python-3.x tensorflow keras deep-learning conv-neural-network


    【解决方案1】:

    即使您只有一个通道,您的模型也需要输入中通道的明确维度。如果您的图片是np arrays,您可以添加如下维度:

    import numpy as np
    
    image = np.random.rand(1000,32,32)
    image = np.expand_dims(image, axis=1)
    image.shape
    
    output: (1000, 1, 32, 32)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-29
      • 1970-01-01
      相关资源
      最近更新 更多