我正在尝试运行在gru末尾附加conv2d的模型。 gru将返回所有序列,这意味着gru的输出应为28 * 28矩阵的批次。然后我想将它们输入到conv2d中,因为conv2d需要一个4d张量,所以我在图层中重塑了张量,但出现了错误。
因此,我认为重塑层存在一些问题,但是通过网络搜索似乎没有令人满意的答案。任何人都可以提供一些提示,谢谢。
def build_model(input_shape, num_classes):
x = Input(input_shape)
x = Embedding(10000, 64, input_length=28)(x)
forw = GRU(14, return_sequences=True)(x)
back = GRU(14, return_sequences=True, go_backwards=True)(x)
y = Concatenate(-1)([forw, back])
y = Reshape((None,28,28,1))(y)
y = Conv2D(32, (3, 3), activation='relu')(y)
y = MaxPooling2D((2,2))(y)
y = Conv2D(64, (3, 3), activation='relu')(y)
y = MaxPooling2D((2,2))(y)
y = Flatten()(y)
y = Dense(num_classes, activation='softmax')(y)
return Model(x,y)
File "/usr/local/lib/python2.7/dist-packages/keras/layers/core.py", line 401, in call
return K.reshape(inputs, (K.shape(inputs)[0],) + self.target_shape)
File "/usr/local/lib/python2.7/dist-packages/keras/backend/tensorflow_backend.py", line 1969, in reshape
return tf.reshape(x, shape)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_array_ops.py", line 7179, in reshape
"Reshape", tensor=tensor, shape=shape, name=name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 529, in _apply_op_helper
(input_name, err))
ValueError: Tried to convert 'shape' to a tensor and failed. Error: None values not supported.