Keras,输入形状不正确

时间:2017-06-27 04:50:28

标签: python image keras convolution

我收到关于展平图层输入尺寸的错误。

ValueError: The shape of the input to "Flatten" is not fully defined (got (0, 12, 10). Make sure to pass a complete "input_shape" or "batch_input_shape" argument to the first layer in your model.

我收到此错误,因为我的一个尺寸为零,对吗?试图找出为什么它被降低到零,但不确定这个错误发生在哪里。

我一直在尝试计算在展平图层之前卷积图层之后输出应该是什么。与model.summary()相比,我无法让他们排队。

我不确定model.summary()输出形状是如何格式化的,是无,宽度,长度,深度?

我用来计算输出形状的公式:(width - filter_size + 2(padding)/shifting) + 1

格式:深度,宽度,高度

第一卷积形状:10,14,14
第二卷积形状:10,12,12

有人可以解释为什么在下面的model.summary()输出形状列中减少第一个整数值的深度?

```

_________________________________________________________________
_________________________________________________________________
Layer (type)                 Output Shape              Param #
=================================================================
conv2d_9 (Conv2D)            (None, 2, 14, 10)         1450
_________________________________________________________________
activation_9 (Activation)    (None, 2, 14, 10)         0
_________________________________________________________________
conv2d_10 (Conv2D)           (None, 0, 12, 10)         910
_________________________________________________________________
activation_10 (Activation)   (None, 0, 12, 10)         0
=================================================================
Total params: 2,360
Trainable params: 2,360
Non-trainable params: 0

```

在我的Convolution2D图层中输入的形状似乎输入不正确,但我已根据文档建议输入。

```

model = Sequential()

batch_size = 20
nb_epoch = 20

nb_filters = 10 
kernel_size = (3, 3)
input_shape = (4, 16, 16)
pool_size =(2, 2)

model.add(Convolution2D(nb_filters, (kernel_size[0], kernel_size[1]), input_shape=input_shape, kernel_initializer='TruncatedNormal'))
model.add(Activation('relu'))
model.add(Convolution2D(nb_filters, (kernel_size[0], kernel_size[1]), kernel_initializer='TruncatedNormal'))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=pool_size))
model.summary()

# model.add(Dropout(0.5))
model.add(Flatten())
model.add(Dense(64, activation='relu'))
model.add(Dropout(.3))
model.add(Dense(1, activation='sigmoid'))

model.compile(loss = 'binary_crossentropy', optimizer='Adamax', metrics=['accuracy'])

```

后端:Theano

0 个答案:

没有答案