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?






can you share your CustomLayer implementation ?

– sdcbr
Sep 6 '18 at 6:26


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.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)