microsoft / CNTK

Microsoft Cognitive Toolkit (CNTK), an open source deep-learning toolkit
https://docs.microsoft.com/cognitive-toolkit/
Other
17.49k stars 4.3k forks source link

when shape contains negative integer, input_variable should throw an error #3885

Open cheyennee opened 6 months ago

cheyennee commented 6 months ago

In following code, I want to generate an input. However, when the input shape contains a negative integer, the code wont throw errors. It just prints Input('Input3', [#], [1 x ? x 1]). This behaviour is quite different from other deep learning libraries. I think it would be better if there is input shape checking.

repo code:

x = C.input_variable((1, -1, 1), needs_gradient=True)
print(x)
Humayun-glitch commented 6 months ago

The issue you're encountering might be related to how CNTK handles negative integers in input shapes. In CNTK, the negative dimension is often used as a placeholder for sequences or variable-length dimensions. While other deep learning libraries might raise an error when encountering negative integers, CNTK might interpret it differently.

In your case, the shape (1, -1, 1) is likely interpreted as a sequence of vectors with one element, where the second dimension can vary in size (variable-length sequence), and each element has one value. This is a valid usage in CNTK for dealing with sequences.