【发布时间】:2016-10-27 01:43:44
【问题描述】:
('x_train shape:', (50000, 32, 32, 3))
# Basic info
self.batch_num = 50
self.img_row = 32
self.img_col = 32
self.img_channels = 3
self.nb_classes = 10
img = tf.placeholder(tf.float32, shape=(self.batch_num, self.img_col, self.img_row, self.img_channels))
labels = tf.placeholder(tf.float32, shape=(self.batch_num, self.nb_classes))
x = Convolution2D(16, 3, 3, border_mode='same')(img)
x = BatchNormalization(axis=3)(x)
x = Activation('relu')(x)
x = AveragePooling2D(pool_size=(8, 8), strides=None, border_mode='valid')(x)
x = Flatten()(x)
preds = Dense(self.nb_classes, activation='softmax')(x)
我遇到以下错误:
Traceback (most recent call last):
File "cnn.py", line 176, in <module>
a.step()
File "cnn.py.py", line 156, in step
preds = Dense(self.nb_classes, activation='softmax')(x)
File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 487, in __call__
self.build(input_shapes[0])
File "/usr/local/lib/python2.7/dist-packages/keras/layers/core.py", line 695, in build
name='{}_W'.format(self.name))
File "/usr/local/lib/python2.7/dist-packages/keras/initializations.py", line 58, in glorot_uniform
s = np.sqrt(6. / (fan_in + fan_out))
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
由于我需要的灵活性,我将它与 TensorFlow 一起使用。但是我把它分解成一个简单的例子,我不明白为什么我会因为这样一个简单的问题而出错。
【问题讨论】:
标签: keras