tracel-ai / burn

Burn is a new comprehensive dynamic Deep Learning Framework built using Rust with extreme flexibility, compute efficiency and portability as its primary goals.
https://burn.dev
Apache License 2.0
8.45k stars 415 forks source link

error when import onnx of yolo8 #1686

Open xuexl opened 4 months ago

xuexl commented 4 months ago

I have one onnx file of trained from yolo8. I want to use it in burn, as the backend. Then i import the onnx file , and an error is throwed. The error like this:

checking outputs DEBUG burn_import::onnx::from_onnx: output name: /model.22/Shape_4_output_0 DEBUG burn_import::onnx::proto_conversion: Converting ONNX node with type "Concat" DEBUG burn_import::onnx::from_onnx: renaming node "/model.22/Concat_3" ERROR burn_import::logger: PANIC => panicked at /home/lin/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/burn-import-0.13.0/src/onnx/dim_inference.rs:178:10: calledOption::unwrap()on aNone` value

--- stderr thread 'main' panicked at /home/lin/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/burn-import-0.13.0/src/onnx/dim_inference.rs:178:10: called Option::unwrap() on a None value`

This is a bug or not , i don't know. So, anyone can help me , please. thanks .

laggui commented 4 months ago

Not all ops are supported for ONNX import yet, but in this case it seems to have failed at the Concat node (as pointed out by the panic at this line).

Is your model publicly available?

xuexl commented 4 months ago

@laggui First, thanks your reply.
And the model is exported by yolo8 project of ultralytics. So, can you try it when you have some time. The yolo8 is so good , and many people use it. Now, i use yolo8 model by tch-rs. And, i want to try it in burn . By export, and then import onnx file, it is a bridge from pytorch to burn. It is a good way . And the other way is that writing the modle script again in burn from pytorch to burn , it is not good . Most CNN models are trained by pytorch, So if you give a simple way from pytorch to burn, i think it must be excellent.

antimora commented 4 months ago

It would be great if you could link the onnx file so we could try out.

7kanak commented 3 months ago

@antimora i am also facing a similar issue , not sure if i should create a new issue as this one is already open. this is the python code i use to generate onnx file

model_id = "distilbert-base-uncased-finetuned-sst-2-english"
feature = "sequence-classification"

model = AutoModelForSequenceClassification.from_pretrained(model_id)
tokenizer = AutoTokenizer.from_pretrained(model_id)

inputs = tokenizer("onnx is wonderful", return_tensors="pt")
torch.onnx.export(
    model, 
    tuple(inputs.values()),
    f="bert.onnx",  
    input_names=['input_ids', 'attention_mask'], 
    output_names=['logits'], 
    dynamic_axes={'input_ids': {0: 'batch_size', 1: 'sequence'}, 
                  'attention_mask': {0: 'batch_size', 1: 'sequence'}, 
                  'logits': {0: 'batch_size', 1: 'sequence'}}, 
    do_constant_folding=True, 
    opset_version=16, 
    verbose=True
)

getting this error,

  DEBUG burn_import::onnx::from_onnx: input /distilbert/embeddings/Constant_3_output_0 matched constant node constant6    
  ERROR burn_import::logger: PANIC => panicked at /home/kanak/.cargo/registry/src/index.crates.io-6f17d22bba15001f/burn-import-0.13.2/src/onnx/dim_inference.rs:281:40:
  called `Option::unwrap()` on a `None` value    

let me know if any other information i can provide(or if i should create a new issue), thanks

antimora commented 3 months ago

@antimora i am also facing a similar issue , not sure if i should create a new issue as this one is already open.

this is the python code i use to generate onnx file


model_id = "distilbert-base-uncased-finetuned-sst-2-english"

feature = "sequence-classification"

model = AutoModelForSequenceClassification.from_pretrained(model_id)

tokenizer = AutoTokenizer.from_pretrained(model_id)

inputs = tokenizer("onnx is wonderful", return_tensors="pt")

torch.onnx.export(

    model, 

    tuple(inputs.values()),

    f="bert.onnx",  

    input_names=['input_ids', 'attention_mask'], 

    output_names=['logits'], 

    dynamic_axes={'input_ids': {0: 'batch_size', 1: 'sequence'}, 

                  'attention_mask': {0: 'batch_size', 1: 'sequence'}, 

                  'logits': {0: 'batch_size', 1: 'sequence'}}, 

    do_constant_folding=True, 

    opset_version=16, 

    verbose=True

)

getting this error,


  DEBUG burn_import::onnx::from_onnx: input /distilbert/embeddings/Constant_3_output_0 matched constant node constant6    

  ERROR burn_import::logger: PANIC => panicked at /home/kanak/.cargo/registry/src/index.crates.io-6f17d22bba15001f/burn-import-0.13.2/src/onnx/dim_inference.rs:281:40:

  called `Option::unwrap()` on a `None` value    

let me know if any other information i can provide(or if i should create a new issue), thanks

It would be helpful if you file a new ticket.

7kanak commented 3 months ago

i have created a new issue https://github.com/tracel-ai/burn/issues/1811