Search code examples
pythoncoremlcoremltools

Coreml: How to reshape an array (1, 3, 80, 80, 19) to (3, 6400, 19) or (1, 3, 6400, 19)


I have an input which is (1, 3, 80, 80, 19) and I want to reshape it to (3, 6400, 19) or (1, 3, 6400, 19). I tried like this

 input_features = [
    ("714", datatypes.Array(1, 3, 80, 80, 19))]

builder.add_reshape(name='714_reshape', input_name='714', output_name='714_reshape', target_shape=(3, 6400, 19), mode=0)

But I get this error Espresso exception: "Invalid argument": generic_reshape_kernel: Invalid bottom shape (19 80 80 3 1) for reshape to (19 6400 3 3 1)".

And it seems that coreml tries to output the same rank as my input. Is there a way to tell coreml that I want to reshape axis 1 and 2 from 80x80 to 6400?


Solution

  • Try add_reshape_static, which can handle tensors that are not rank 5. The old reshape layer is more limited in that way and can sometimes give strange behavior.