microsoft / CNTK

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

Save Object Detection model to ONNX format #3833

Open alexberd opened 3 years ago

alexberd commented 3 years ago

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_this:: 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

delzac commented 3 years ago

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.

mattans commented 2 years ago

@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?

delzac commented 2 years ago

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

mattans commented 2 years ago

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?

delzac commented 2 years ago

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.

mattans commented 2 years ago

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