When I used version 4.0b2 I was able to use -1 for batch in shape.
Now with version 4.0b3 it shows me error - Dimension cannot be None of -1. Use ct.RangeDim for runtime determined dimension. Dim 0: -1 See https://coremltools.readme.io/docs/flexible-inputs
import coremltools as ct
shape = ct.Shape(shape=(-1,224,224,3), default=(1,224,224,3))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/dist-packages/coremltools/converters/mil/input_types.py", line 300, in __init__
raise ValueError(msg.format(idx, s))
ValueError: Dimension cannot be None of -1. Use ct.RangeDim for runtime determined dimension. Dim 0: -1 See https://coremltools.readme.io/docs/flexible-inputs
import coremltools as ct
shape = ct.Shape(shape=(-1,224,224,3), default=(1,224,224,3))
Add any other context about the problem here.
Have you tried something like ct.Shape(shape=(ct.RangeDim(1, 32),224,224,3)) ?
Per examples in https://coremltools.readme.io/docs/flexible-inputs
In any case, the documentation might need an update if '-'1 is retired in favor of RangeDim()
Yes, RangeDim works. But I need the batch to be -1 (any batch size). And it worked in 4.0b2.
Looks like None or -1 are not allowed. Related PR https://github.com/apple/coremltools/pull/858
Docs should be updated: https://coremltools.readme.io/docs/flexible-inputs
It still says
A -1 denoted in shape acts like None in Tensorflow's placeholder. It allows arbitrary size of input in that dimension.
@apivovarov The API for the coremltools 4.0b3 is changed,
now you need to use ct.RangeDim() instead if -1.
Please reopen the issue if it doesn't fix your problem.
Nice! The doc has been updated for the new API:
https://coremltools.readme.io/docs/flexible-inputs.
Let us know if you get further question.
Thank you for looking into it.
I still see a couple places in the documentation which might be misleading
Case 1
It's a natural choice of using -1 for all flexible shaped dimension. However, it is recommended to use EnumeratedShapes for best performance
Not it is not a recommendation any more. -1 is not allowed.
Case 2
shape = ct.Shape(shape=(1, -1, 1024), default=(1, 50, 1024))
It is going to fail
@apivovarov I did a pass on the docs for this page. Hopefully it's more accurate now. Thanks for the feedback!