【发布时间】:2018-03-22 06:14:21
【问题描述】:
我用 Keras (tensorflow) 实现了以下模型:
Layer (type) Output Shape Param #
=================================================================
conv2d_1 (Conv2D) (None, None, None, 32) 896
_________________________________________________________________
conv2d_2 (Conv2D) (None, None, None, 32) 9248
_________________________________________________________________
max_pooling2d_1 (MaxPooling2 (None, None, None, 32) 0
_________________________________________________________________
dropout_1 (Dropout) (None, None, None, 32) 0
_________________________________________________________________
conv2d_3 (Conv2D) (None, None, None, 64) 18496
_________________________________________________________________
conv2d_4 (Conv2D) (None, None, None, 64) 36928
_________________________________________________________________
dropout_2 (Dropout) (None, None, None, 64) 0
_________________________________________________________________
global_average_pooling2d_1 ( (None, 64) 0
_________________________________________________________________
dense_1 (Dense) (None, 256) 16640
_________________________________________________________________
dropout_3 (Dropout) (None, 256) 0
_________________________________________________________________
dense_2 (Dense) (None, 14) 3598
=================================================================
Total params: 85,806
Trainable params: 85,806
Non-trainable params: 0
我的数据集是 Leed 运动集,其中包含可变宽度和高度的图像。根据 Keras documentation 和 github issue,我只需将 inputshape 设置为 (None, None, Num_Channels)。为了准备我的数据集,我将注释和图像加载为 numpy 数组,如下所示:
# Train Input, contains paths of images first
x_train = image_list[train_indexes]
print("Converting x_train images to numpy...")
x_train = np.array([misc.imread(path) for path in x_train])
print(x_train.shape)
print(x_train[0].shape)
print(x_train[1].shape)
打印调用的输出是:
(9600,) # x_train
(188, 282, 3) # x_train first image
(686, 1024, 3) # x_train second image
如果我现在将 x_train 提供给我的模型,它会抛出以下错误:
ValueError: Error when checking input: expected conv2d_1_input to have 4 dimensions, but got array with shape (9600, 1)
如何塑造我的训练集以让我的模型接受?
【问题讨论】:
标签: python tensorflow machine-learning keras