apple / coremltools

Core ML tools contain supporting tools for Core ML model conversion, editing, and validation.
https://coremltools.readme.io
BSD 3-Clause "New" or "Revised" License
4.46k stars 648 forks source link

Using RangeDim in TensorSpec shape #890

Open lunixbochs opened 4 years ago

lunixbochs commented 4 years ago

It would be nice to use a RangeDim directly in the mb.TensorSpec() shape here instead of the symbol indirection:

flexible = ct.RangeDim()
@mb.program(input_specs=[mb.TensorSpec(shape=(1, 100, 100, flexible.symbol)),])
def prog(x):
    return x

Context:

I'm trying to write a converter for a model type with flexible input dimensions, because the automatic conversion doesn't work and it's not worth me fixing it (I'm already generating the Pytorch model from yet another framework, flashlight/wav2letter, so I'd rather generate the right ops directly for MIL than try to make the stacked abstractions make sense)

I originally got it working with the old-style NeuralNetworkBuilder, but couldn't figure out how to specify flexible input features. I just found the MIL builder and ported my code to that. It seems to accept a RangeDim in the program decorator for flexible input shape as shown, but only if I use the .symbol property on a RangeDim (which I had to dig around in source to find). Passing the RangeDim directly feels more intuitive to me.

lunixbochs commented 4 years ago

Note: it looks like this generally works, but also SAME convolution breaks when I do this - it seems SAME expects to know the input dimensions at compile time #891

TobyRoseman commented 2 years ago

Note: it looks like this generally works, but also SAME convolution breaks when I do this - it seems SAME expects to know the input dimensions at compile time #891

Looks like #891 has been addressed. @lunixbochs - you say things are generally working. Should this issue be closed? If not, please provide details on what is still not working.

lunixbochs commented 2 years ago

from #891:

flexible = ct.RangeDim()
@mb.program(input_specs=[mb.TensorSpec(shape=(1, 100, 100, flexible.symbol)),])

Is it possible to use RangeDim like this without manually using the .symbol property? It's been a while but I think I had to dig that out of the source and it wasn't really documented.