CNTK icon indicating copy to clipboard operation
CNTK copied to clipboard

Save Object Detection model to ONNX format

Open alexberd opened this issue 5 years ago • 6 comments

Thanks a lot for your effort developing this toolkit.

I tried to save both VGG and Alexnet Models to ONNX format using the following function.

eval_model.save(model_path, format=cntk.ModelFormat.ONNX)

Unfortunately this returns the followign error:

`

  Name Value Type
eval_model.save(model_path, format=cntk.ModelFormat.ONNX) RuntimeError("Node 'UserFunction: Output('rpn_cls_prob_reshape', [#], [18 x 54 x 54]), Output('rpn_bbox_pred', [#], [36 x 54 x 54]), Input('Input5', [#], [6]) -> Output('rpn_rois_raw', [#], [* x 4])': Unsupported node.\n\n[CALL STACK]\n > std::enable_shared_from_thisMicrosoft::MSR::CNTK::MatrixBase:: weak_from_this\n - CNTK:: XavierInitializer (x15)\n\n",) RuntimeError

`

Could you please advise if there is any model that currently could be used with the CTNK Object Detection methods and that can be saved to ONNX format?

If not, could you please add average pooling support for the ROIPooling layer of the Object-Detection-using-Faster-R-CNN to use the RESNET networks? (https://github.com/Microsoft/CNTK/issues/1905)

It seems that RESNET networks can be exported to ONNX Format. (https://github.com/onnx/tutorials/issues/53)

Many thanks, Alex

alexberd avatar Oct 25 '20 05:10 alexberd

Userfunction cannot be saved as ONNX. And object detection has a few very specific functions that cannot be exported too. I suggest you use YOLO architecture instead.

delzac avatar Nov 01 '20 10:11 delzac

@delzac I am getting a similar error but for the operation NotEqual. It's not a userfunction. Is there a way to still convert it to ONNX?

mattans avatar Jan 19 '22 09:01 mattans

Can you change the operation to equal and negate instead? It should give the same effect.

delzac avatar Jan 19 '22 09:01 delzac

Can you change the operation to equal and negate instead? It should give the same effect.

I don't have the access to the model's architecture. I only have the final .dnn file. Can it still be done?

mattans avatar Jan 19 '22 10:01 mattans

It will probably be very involved, but after loading the model file into cntk, you can probably swap out the notEqual node by getting the input and output node references.

delzac avatar Jan 19 '22 10:01 delzac

It will probably be very involved, but after loading the model file into cntk, you can probably swap out the notEqual node by getting the input and output node references.

Can you please explain how it can be done? I'm going through the attributes of the model object but I don't understand where the layers are stored. When I open the file in Netron I can see the NotEqual node. This is the architecture:

image

mattans avatar Jan 19 '22 11:01 mattans