facebookresearch / Detic

Code release for "Detecting Twenty-thousand Classes using Image-level Supervision".
Apache License 2.0
1.86k stars 211 forks source link

How to export detic to onnx? #61

Open Edwardmark opened 2 years ago

Edwardmark commented 2 years ago

Hi, I see that there are tools to convert detectron model to onnx, so how to convert detic model to onnx?

xingyizhou commented 2 years ago

Hi,

Please check the instructinos here.

Best, Xingyi

anshudaur commented 2 years ago

@xingyizhou Yes I have tried this option .

I get KeyError: "No object named 'CustomRCNN' found in 'META_ARCH' registry!" And I think we don't need to register CustomRCNN , as it already inherits GeneralizedRCNN which is registered with detectron2. Do you have any other suggestion?

anshudaur commented 2 years ago

@xingyizhou I was able to figure it out. All we need is to import the Custom RCNN class in train_net (even though we are not using it directly). :)

But now the error is w.r.t symbolic ops :

site-packages/torch/onnx/symbolic_opset9.py", line 2065, in to return g.op("Cast", self, to_i=sym_help.cast_pytorch_to_onnx[dtype]) KeyError: 'UNKNOWN_SCALAR'

Even though I have set symbolic onset parameter in detectron2 to 11 , it still keeps going to symbolic_opset9 files.

Do you know how can this be fixed.. I tried rebuilding detectron2 after changing the opset version ?

Thanks Anshu

anshudaur commented 2 years ago

@xingyizhou I have also upgraded torch and torch vision versions to : torch==1.11 torchvision==0.12.0

before building detectron2 for STABLE_ONNX_OPSET_VERSION=14

anshudaur commented 2 years ago

you can refer to : https://github.com/facebookresearch/Detic/issues/63#issuecomment-1234345981

npzl commented 1 year ago

@xingyizhou I was able to figure it out. All we need is to import the Custom RCNN class in train_net (even though we are not using it directly). :)

But now the error is w.r.t symbolic ops :

site-packages/torch/onnx/symbolic_opset9.py", line 2065, in to return g.op("Cast", self, to_i=sym_help.cast_pytorch_to_onnx[dtype]) KeyError: 'UNKNOWN_SCALAR'

Even though I have set symbolic onset parameter in detection to 11 , it still keeps going to symbolic_opset9 files.

Do you know how can this be fixed.. I tried rebuilding detection after changing the opset version ?

Thanks Anshu

hello,sorry to boring you.Have you solve the problem,I meet the same problem.

anshudaur commented 1 year ago

@npzl you can comment the opset=9 in detectron's files and rebuild detectron. or override it in torch.onnx.export method's parameters.

npzl commented 1 year ago

@npzl you can comment the opset=9 in detectron's files and rebuild detectron. or override it in torch.onnx.export method's parameters.

    with PathManager.open(os.path.join(args.output, "model.onnx"), "wb") as f:
        torch.onnx.export(traceable_model, (image,), f, opset_version=9)

is that right??