microsoft / CNTK

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

ONNX Model ToBatchAxisNode Err #3507

Open YanYas opened 5 years ago

YanYas commented 5 years ago

Loading ONNX models (version 1.2) I come across an error when I try to evaluate them.

ToBatchAxis4441 ToBatchAxisNode operation can only operate on tensor without minibatch data (no layout)

My current test SqueezeNet model: Input('data_0', [224 x 224 x 3 x 1], []) Output('Block4416_Output_0', [1 x 1 x 1000 x *], []) I try replacing the input: Input('My image', [224 x 224 x 3 x 1], [*, #]) The resulting string of the Function: Composite(Softmax_onnx): Input('My image', [224 x 224 x 3 x 1], [*, #]) -> Output('Block5319_Output_0', [1 x 1 x 1000 x *], [])

I'm not actually using a minibatch, but I am using a Batch operation to create the Value so I have greater flexibility. However, the whole value, including the number of images is set in the shape of the Batch. Does the Value need to be created in a different manner?

YanYas commented 5 years ago

To add, I'm using CNTK 2.6 with C#. The model I downloaded can be found in the Onnx official model zoo.

Further testing with the creation of the Value hasn't changed the error, so the "1 x 1 x 1000 x *" is perhaps a problem from the Onnx model loader? I can't use MLNET for evaluation at the moment, so is there a chance this problem has a fix in the CNTK 2.7 betas?

YanYas commented 5 years ago

Was anyone able to replicate this error or is this only something I'm seeing on my side?

elevir commented 5 years ago

@YanYas I have the same problem. I've loaded YoloV2 onnx where input layer has shape [416, 416, 3, -3] (-3 is batch axis), but I need shape ([w, h, 3], [*, #]). Well, with some tricks I've achieved my goal and got this shape, but now I have same error.

YanYas commented 5 years ago

Hi @elevir, I think I finally figured this one out.

Assuming that you have the shape right, and it certainly looks like you do the problem was fixed by reconciling the dynamic axes of the imported model and input that you want to use for it.

A bit of pseudocode for you to get the gist:

input = inputvariable();
model = loadModel("model.onnx"); 
model = reconcileDynamicAxis(model, input);
output = model.evaluate(input);

Let me know if it helps

lordofmaster commented 3 years ago

hi @YanYas, I tried to read the onnx model into cntk, so I saw the same error. I am trying to solve it with reconciledynamicaxis, but I am not sure, so I ask.

In the case of imagenet classification, since the above input corresponds to an image, it has a dimension of 224,224,3, and the corresponding onnx model is read from cntk, so the argument is 224,224,3,1.

Even if after reconcileDynamicAxis, 224,224,3,1 does not change and an error occurs as it is.

I need more detail, please.

YanYas commented 3 years ago

Hi @lordofmaster, sorry I didn't see this sooner and I haven't used CNTK is a while. If you see the model asString what sorts of symbols does it show? do you see 224,224,3,# ? The reconciled model should have that