facebookresearch / facebookresearch/detectron2

export_model.py ONNX gives a model that does not work

Open
#5,431 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
34.7k
Forks
7.9k
PR merge metrics
No merged PRs in 30d

Description

## Instructions To Reproduce the 🐛 Bug:
1. Full runnable code or full changes you made:
No changes.

2. What exact command you run:
python detectron2/tools/deploy/export_model.py --config-file Detectron2/detectron2/configs/COCO-Detection/retinanet_R_101_FPN_3x.yaml --output ./output --export-method tracing --format onnx --sample-image image_1.bmp MODEL.DEVICE cuda MODEL.WEIGHTS Detectron2/output_object_detection/model_final.pth
3. __Full logs__ or other relevant observations:```
TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
assert tensor.dim() == 2 and tensor.size(-1) == 4, tensor.size()
============= Diagnostic Run torch.onnx.export version 2.0.0+cu117 =============
verbose: False, log level: Level.ERROR
======================= 0 NONE 0 NOTE 0 WARNING 0 ERROR ========================

[01/30 14:29:26 detectron2]: Inputs schema: TupleSchema(schemas=[ListSchema(schemas=[DictSchema(schemas=[IdentitySchema()], sizes=[1], keys=['image'])], sizes=[1])], sizes=[1])
[01/30 14:29:26 detectron2]: Outputs schema: ListSchema(schemas=[DictSchema(schemas=[InstancesSchema(schemas=[TensorWrapSchema(class_name='detectron2.structures.Boxes'), IdentitySchema(), IdentitySchema()], sizes=[1, 1, 1], keys=['pred_boxes', 'pred_classes', 'scores'])], sizes=[4], keys=['instances'])], sizes=[4])
[01/30 14:29:26 detectron2]: Success.

4. please simplify the steps as much as possible so they do not require additional resources to

## Expected behavior:
After running the conversion command to ONNX, to have a ONNX that is able to find the same boxes as the .pt does per the same image. The ONNX does not find any boxes.

## Environment:
Everything has been done following this:
https://colab.research.google.com/github/mashyko/object_detection/blob/master/Detectron2_Tutorial.ipynb

Contributor guide

Open the contributing guide

Research direction

Start with detectron2/tools/deploy/export_model.py and reproduce the reported command using the provided RetinaNet configuration, sample image, and model weights. Compare the boxes produced by the exported ONNX model with the .pt model on the same image; the issue is done when both produce matching detections.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
computer-vision, machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.