Keras: Input to reshape is a tensor with 6 values, but the requested shape has 3
Keras: Input to reshape is a tensor with 6 values, but the requested shape has 3
I created a custom layers in Keras. For simplicity you can image the custom layer accepts any number of tensor and sum them together vertically. In terms of I/O it should look something like this:
My code looks something like:
# 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)
Up until .fit() everything goes alright, then I always get an error:
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)]]
Any idea what the issue could be?
CustomLayer
0
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
can you share your
CustomLayer
implementation ?– sdcbr
Sep 6 '18 at 6:26