我在Keras中创建了一个自定义图层。为简单起见,您可以对自定义图层进行图像处理,使其接受任意数量的张量并将它们垂直求和。在I / O方面,它应该看起来像这样:
我的代码如下:
# data has shape (4, 3, 3), where 4 is the number of instances, 3 is
# the number of rows and the second 3 the number of columns.
data = np.array(...)
labels = np.array(...)
inputs = keras.layers.Input(shape=(None, 3), name='input')
custom = CustomLayer(name='c1')(inputs)
softmax = keras.layers.Dense(
units=2, activation='softmax',
name='softmax')(custom)
model = keras.models.Model(inputs=inputs, outputs=softmax)
model.compile(optimizer='sgd', loss='categorical_crossentropy')
model.fit(data, labels, epochs=2)
直到.fit()一切顺利,然后我总是收到错误消息:
File "/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/errors_impl.py", line 519, in __exit__
c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: Input to reshape is a tensor with 6 values, but the requested shape has 3
[[Node: c1/map/while/Reshape = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _class=["loc:@training/SGD/gradients/c1/map/while/Slice_grad/Pad"], _device="/job:loc
alhost/replica:0/task:0/device:CPU:0"](s1/map/while/TensorArrayReadV3, s1/map/while/Slice_1/size)]]
知道可能是什么问题吗?