Skip to content

Cannot read ONNX model #6

@benjamingb

Description

@benjamingb

I'm trying the example of loading a YOLOv8 model in ONNX format and I'm getting this error, am I doing something wrong?

fn main() {
    let classes_labels: Vec<&str> = vec!["person", "bicycle", "car", "motorbike", "aeroplane", "bus", "train", "truck", "boat", "traffic light", "fire hydrant", "stop sign", "parking meter", "bench", "bird", "cat", "dog", "horse", "sheep", "cow", "elephant", "bear", "zebra", "giraffe", "backpack", "umbrella", "handbag", "tie", "suitcase", "frisbee", "skis", "snowboard", "sports ball", "kite", "baseball bat", "baseball glove", "skateboard", "surfboard", "tennis racket", "bottle", "wine glass", "cup", "fork", "knife", "spoon", "bowl", "banana", "apple", "sandwich", "orange", "broccoli", "carrot", "hot dog", "pizza", "donut", "cake", "chair", "sofa", "pottedplant", "bed", "diningtable", "toilet", "tvmonitor", "laptop", "mouse", "remote", "keyboard", "cell phone", "microwave", "oven", "toaster", "sink", "refrigerator", "book", "clock", "vase", "scissors", "teddy bear", "hair drier", "toothbrush"];
    let mf = ModelFormat::ONNX;
    let net_width = 640;
    let net_height = 640;
    // let class_filters: Vec<usize> = vec![15, 16];
    let class_filters: Vec<usize> = vec![];
    let mut model = ModelUltralyticsV8::new_from_file("pretrained/yolov8n.onnx", None, (net_width, net_height), mf, DNN_BACKEND_CUDA, DNN_TARGET_CUDA, vec![]).unwrap();
    let mut frame = imread("images/dog.jpg", 1).unwrap();
    let (bboxes, class_ids, confidences) = model.forward(&frame, 0.25, 0.4).unwrap();
    for (i, bbox) in bboxes.iter().enumerate() {
        rectangle(&mut frame, *bbox, Scalar::from((0.0, 255.0, 0.0)), 2, LINE_4, 0).unwrap();
        println!("Class: {}", classes_labels[class_ids[i]]);
        println!("\tBounding box: {:?}", bbox);
        println!("\tConfidences: {}", confidences[i]);
    }
    imwrite("images/dog_yolov8_n.jpg", &frame, &Vector::new()).unwrap();
}
 Compiling myod v0.1.0 (/test_odopencv/myod)
warning: unused variable: `class_filters`
  --> src/main.rs:22:9
   |
22 |     let class_filters: Vec<usize> = vec![];
   |         ^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_class_filters`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: `myod` (bin "myod") generated 1 warning (run `cargo fix --bin "myod"` to apply 1 suggestion)
    Finished dev [unoptimized + debuginfo] target(s) in 1.16s
     Running `target/debug/myod`
[ERROR:0@0.030] global ./modules/dnn/src/onnx/onnx_importer.cpp (1018) handleNode DNN/ONNX: ERROR during processing node with 2 inputs and 1 outputs: [Add]:(onnx_node!/model.22/Add) from domain='ai.onnx'
thread 'main' panicked at src/main.rs:23:206:
called `Result::unwrap()` on an `Err` value: Error { code: "StsError, -2", message: "OpenCV(4.6.0) ./modules/dnn/src/onnx/onnx_importer.cpp:1040: error: (-2:Unspecified error) in function 'handleNode'\n> Node [Add@ai.onnx]:(onnx_node!/model.22/Add) parse error: OpenCV(4.6.0) ./modules/dnn/src/onnx/onnx_importer.cpp:1464: error: (-215:Assertion failed) blob_0.size == blob_1.size in function 'parseBias'\n> " }
stack backtrace:
   0: rust_begin_unwind
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/panicking.rs:647:5
   1: core::panicking::panic_fmt
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/panicking.rs:72:14
   2: core::result::unwrap_failed
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/result.rs:1649:5
   3: core::result::Result<T,E>::unwrap
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/result.rs:1073:23
   4: myod::main
             at ./src/main.rs:23:21
   5: core::ops::function::FnOnce::call_once
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Metadata

Metadata

Assignees

Labels

help wantedExtra attention is neededquestionFurther information is requested

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions