LdDl / object-detection-opencv-rust

Just set of functions to utilize YOLO v3, v4, v7 and v8 version with OpenCV's DNN module
MIT License
12 stars 1 forks source link

Cannot read ONNX model #6

Closed benjamingb closed 3 weeks ago

benjamingb commented 2 months ago

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.
LdDl commented 2 months ago

I have two guesses: 1) OpenCV version (you have 4.6.0 based on error message). https://github.com/ultralytics/ultralytics/issues/1836 I think that version 4.7.0 should do the trick. 2) OpSet for ONNX. It should be 12. https://github.com/ultralytics/ultralytics/issues/1097

benjamingb commented 2 months ago

Hi

I updated to version opencv 4.8.0 but now I get another error

Can't process detection,  error: OpenCVError(Error { code: "StsAssert, -215", message: "OpenCV(4.8.0) /home/benjamin/dist/opencv-4.8.0/modules/dnn/src/layers/reshape_layer.cpp:109: error: (-215:Assertion failed) total(srcShape, srcRange.start, srcRange.end) == maskTotal in function 'computeShapeByReshapeMask'\n" })
[ERROR:0@10.825] global net_impl.cpp:1166 getLayerShapesRecursively OPENCV/DNN: [Reshape]:(onnx_node!/model.22/dfl/Reshape): getMemoryShapes() throws exception. inputs=1 outputs=1/1 blobs=0
[ERROR:0@10.825] global net_impl.cpp:1172 getLayerShapesRecursively     input[0] = [ 1 64 3549 ]
[ERROR:0@10.825] global net_impl.cpp:1176 getLayerShapesRecursively     output[0] = [ ]
[ERROR:0@10.825] global net_impl.cpp:1182 getLayerShapesRecursively Exception message: OpenCV(4.8.0) /home/benjamin/dist/opencv-4.8.0/modules/dnn/src/layers/reshape_layer.cpp:109: error: (-215:Assertion failed) total(srcShape, srcRange.start, srcRange.end) == maskTotal in function 'computeShapeByReshapeMask'

Does it only work with the darknet?

LdDl commented 2 months ago

May you provide link to a model and image you trying to run through the detection function? I think that something could be wrong with the shape of the model (I guess the model is custom?): input[0] = [ 1 64 3549 ]. https://github.com/ultralytics/ultralytics/issues/1050

benjamingb commented 2 months ago

The problem was that I had the dimensions of the network wrong, I had it at 416, I changed it to 640 and it worked.

let net_width = 640;
let net_height = 640;

Thank you for your help and for the great work in developing the lib.

Are you planning to update the opencv-rust version to 0.9.x in your library soon?

LdDl commented 2 months ago

Glad to hear that it works! Yes, I'm planning to update Cargo.toml to include 0.9 version of OpenCV bindings, but it will happen in a couple of weeks after my vacation and checks that my other projects depending on this package won't be broken

benjamingb commented 2 months ago

Question I converted a Yolov8m model to Onnx, the model works fine, but when I put a video to detect the objects, the video goes very slow, if I use darknet the video goes at normal speed, only when I load the .onnx model the video gets super slow, the video has 29 FPS, do you know why that happens ?

LdDl commented 2 months ago
  1. If using GPU check CUDA actually works for both ONNX and Darknet weights
  2. Check if batch is the same for both configurations (most of time this is the issue)
  3. Check the input size / classes num for both configurations

I believe it should be investigated in details in both Rust and Python OpenCV's bindings then if any of three clauses above does not take place.

LdDl commented 2 months ago

Using cargo run (in case of cargo build it should be faster), RTX 3060 (CUDA is enabled) TLDR:

Seems like, that M-model just takes more resources on computing. But should it affect FPS so much in your case?

Full logs:

Three runs on Traditional Darknet v7:

dimitrii@dimitrii-pc:~/rust_work/object-detection-opencv-rust$ time cargo run --package od_opencv --example yolo_v7 
warning: Patch `cc v1.0.79 (https://github.com/rust-lang/cc-rs.git?tag=1.0.79#e5bbdfa1)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/examples/yolo_v7`
Class: motorbike
        Bounding box: Rect_ { x: 56, y: 72, width: 53, height: 54 }
        Confidences: 0.36123458
Class: truck
        Bounding box: Rect_ { x: 468, y: 74, width: 225, height: 95 }
        Confidences: 0.9325973
Class: bicycle
        Bounding box: Rect_ { x: 126, y: 128, width: 440, height: 289 }
        Confidences: 0.9681798
Class: dog
        Bounding box: Rect_ { x: 130, y: 220, width: 180, height: 321 }
        Confidences: 0.9735598

real    0m0,527s
user    0m0,295s
sys     0m0,236s
dimitrii@dimitrii-pc:~/rust_work/object-detection-opencv-rust$ time cargo run --package od_opencv --example yolo_v7 
warning: Patch `cc v1.0.79 (https://github.com/rust-lang/cc-rs.git?tag=1.0.79#e5bbdfa1)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/examples/yolo_v7`
Class: motorbike
        Bounding box: Rect_ { x: 56, y: 72, width: 53, height: 54 }
        Confidences: 0.36123458
Class: truck
        Bounding box: Rect_ { x: 468, y: 74, width: 225, height: 95 }
        Confidences: 0.9325973
Class: bicycle
        Bounding box: Rect_ { x: 126, y: 128, width: 440, height: 289 }
        Confidences: 0.9681798
Class: dog
        Bounding box: Rect_ { x: 130, y: 220, width: 180, height: 321 }
        Confidences: 0.9735598

real    0m0,537s
user    0m0,297s
sys     0m0,243s
dimitrii@dimitrii-pc:~/rust_work/object-detection-opencv-rust$ time cargo run --package od_opencv --example yolo_v7 
warning: Patch `cc v1.0.79 (https://github.com/rust-lang/cc-rs.git?tag=1.0.79#e5bbdfa1)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/examples/yolo_v7`
Class: motorbike
        Bounding box: Rect_ { x: 56, y: 72, width: 53, height: 54 }
        Confidences: 0.36123458
Class: truck
        Bounding box: Rect_ { x: 468, y: 74, width: 225, height: 95 }
        Confidences: 0.9325973
Class: bicycle
        Bounding box: Rect_ { x: 126, y: 128, width: 440, height: 289 }
        Confidences: 0.9681798
Class: dog
        Bounding box: Rect_ { x: 130, y: 220, width: 180, height: 321 }
        Confidences: 0.9735598

real    0m0,521s
user    0m0,289s
sys     0m0,236s

Three runs on Ultralytics v8m:

dimitrii@dimitrii-pc:~/rust_work/object-detection-opencv-rust$ time cargo run --package od_opencv --example yolo_v8_m
warning: Patch `cc v1.0.79 (https://github.com/rust-lang/cc-rs.git?tag=1.0.79#e5bbdfa1)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.
warning: unused variable: `class_filters`
  --> examples/yolo_v8_m.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: `od_opencv` (example "yolo_v8_m") generated 1 warning (run `cargo fix --example "yolo_v8_m"` to apply 1 suggestion)
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/examples/yolo_v8_m`
Class: truck
        Bounding box: Rect_ { x: 465, y: 75, width: 226, height: 97 }
        Confidences: 0.86243707
Class: bicycle
        Bounding box: Rect_ { x: 125, y: 135, width: 442, height: 285 }
        Confidences: 0.9651602
Class: dog
        Bounding box: Rect_ { x: 132, y: 223, width: 179, height: 319 }
        Confidences: 0.94658756

real    0m0,662s
user    0m0,432s
sys     0m0,230s
dimitrii@dimitrii-pc:~/rust_work/object-detection-opencv-rust$ time cargo run --package od_opencv --example yolo_v8_m
warning: Patch `cc v1.0.79 (https://github.com/rust-lang/cc-rs.git?tag=1.0.79#e5bbdfa1)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.
warning: unused variable: `class_filters`
  --> examples/yolo_v8_m.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: `od_opencv` (example "yolo_v8_m") generated 1 warning (run `cargo fix --example "yolo_v8_m"` to apply 1 suggestion)
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/examples/yolo_v8_m`
Class: truck
        Bounding box: Rect_ { x: 465, y: 75, width: 226, height: 97 }
        Confidences: 0.86243707
Class: bicycle
        Bounding box: Rect_ { x: 125, y: 135, width: 442, height: 285 }
        Confidences: 0.9651602
Class: dog
        Bounding box: Rect_ { x: 132, y: 223, width: 179, height: 319 }
        Confidences: 0.94658756

real    0m0,667s
user    0m0,439s
sys     0m0,228s
dimitrii@dimitrii-pc:~/rust_work/object-detection-opencv-rust$ time cargo run --package od_opencv --example yolo_v8_m
warning: Patch `cc v1.0.79 (https://github.com/rust-lang/cc-rs.git?tag=1.0.79#e5bbdfa1)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.
warning: unused variable: `class_filters`
  --> examples/yolo_v8_m.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: `od_opencv` (example "yolo_v8_m") generated 1 warning (run `cargo fix --example "yolo_v8_m"` to apply 1 suggestion)
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/examples/yolo_v8_m`
Class: truck
        Bounding box: Rect_ { x: 465, y: 75, width: 226, height: 97 }
        Confidences: 0.86243707
Class: bicycle
        Bounding box: Rect_ { x: 125, y: 135, width: 442, height: 285 }
        Confidences: 0.9651602
Class: dog
        Bounding box: Rect_ { x: 132, y: 223, width: 179, height: 319 }
        Confidences: 0.94658756

real    0m0,659s
user    0m0,433s
sys     0m0,226s

Three runs on Ultralytics v8s:

dimitrii@dimitrii-pc:~/rust_work/object-detection-opencv-rust$ time cargo run --package od_opencv --example yolo_v8_s
warning: Patch `cc v1.0.79 (https://github.com/rust-lang/cc-rs.git?tag=1.0.79#e5bbdfa1)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.
warning: unused variable: `class_filters`
  --> examples/yolo_v8_s.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: `od_opencv` (example "yolo_v8_s") generated 1 warning (run `cargo fix --example "yolo_v8_s"` to apply 1 suggestion)
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/examples/yolo_v8_s`
Class: truck
        Bounding box: Rect_ { x: 468, y: 75, width: 226, height: 97 }
        Confidences: 0.86541396
Class: bicycle
        Bounding box: Rect_ { x: 126, y: 134, width: 445, height: 286 }
        Confidences: 0.90190446
Class: dog
        Bounding box: Rect_ { x: 132, y: 223, width: 179, height: 317 }
        Confidences: 0.9244803

real    0m0,574s
user    0m0,379s
sys     0m0,195s
dimitrii@dimitrii-pc:~/rust_work/object-detection-opencv-rust$ time cargo run --package od_opencv --example yolo_v8_s
warning: Patch `cc v1.0.79 (https://github.com/rust-lang/cc-rs.git?tag=1.0.79#e5bbdfa1)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.
warning: unused variable: `class_filters`
  --> examples/yolo_v8_s.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: `od_opencv` (example "yolo_v8_s") generated 1 warning (run `cargo fix --example "yolo_v8_s"` to apply 1 suggestion)
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/examples/yolo_v8_s`
Class: truck
        Bounding box: Rect_ { x: 468, y: 75, width: 226, height: 97 }
        Confidences: 0.86541396
Class: bicycle
        Bounding box: Rect_ { x: 126, y: 134, width: 445, height: 286 }
        Confidences: 0.90190446
Class: dog
        Bounding box: Rect_ { x: 132, y: 223, width: 179, height: 317 }
        Confidences: 0.9244803

real    0m0,564s
user    0m0,384s
sys     0m0,181s
dimitrii@dimitrii-pc:~/rust_work/object-detection-opencv-rust$ time cargo run --package od_opencv --example yolo_v8_s
warning: Patch `cc v1.0.79 (https://github.com/rust-lang/cc-rs.git?tag=1.0.79#e5bbdfa1)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.
warning: unused variable: `class_filters`
  --> examples/yolo_v8_s.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: `od_opencv` (example "yolo_v8_s") generated 1 warning (run `cargo fix --example "yolo_v8_s"` to apply 1 suggestion)
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/examples/yolo_v8_s`
Class: truck
        Bounding box: Rect_ { x: 468, y: 75, width: 226, height: 97 }
        Confidences: 0.86541396
Class: bicycle
        Bounding box: Rect_ { x: 126, y: 134, width: 445, height: 286 }
        Confidences: 0.90190446
Class: dog
        Bounding box: Rect_ { x: 132, y: 223, width: 179, height: 317 }
        Confidences: 0.9244803

real    0m0,557s
user    0m0,371s
sys     0m0,187s

Three runs on Traditional Darknet v4:

dimitrii@dimitrii-pc:~/rust_work/object-detection-opencv-rust$ time cargo run --package od_opencv --example yolo_v4
warning: Patch `cc v1.0.79 (https://github.com/rust-lang/cc-rs.git?tag=1.0.79#e5bbdfa1)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.
warning: unused variable: `class_filters`
  --> examples/yolo_v4.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: `od_opencv` (example "yolo_v4") generated 1 warning (run `cargo fix --example "yolo_v4"` to apply 1 suggestion)
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/examples/yolo_v4`
Class: truck
        Bounding box: Rect_ { x: 463, y: 74, width: 229, height: 96 }
        Confidences: 0.9920712
Class: bicycle
        Bounding box: Rect_ { x: 128, y: 132, width: 438, height: 290 }
        Confidences: 0.9883387
Class: dog
        Bounding box: Rect_ { x: 132, y: 231, width: 177, height: 305 }
        Confidences: 0.99280965

real    0m0,678s
user    0m0,350s
sys     0m0,331s
dimitrii@dimitrii-pc:~/rust_work/object-detection-opencv-rust$ time cargo run --package od_opencv --example yolo_v4
warning: Patch `cc v1.0.79 (https://github.com/rust-lang/cc-rs.git?tag=1.0.79#e5bbdfa1)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.
warning: unused variable: `class_filters`
  --> examples/yolo_v4.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: `od_opencv` (example "yolo_v4") generated 1 warning (run `cargo fix --example "yolo_v4"` to apply 1 suggestion)
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/examples/yolo_v4`
Class: truck
        Bounding box: Rect_ { x: 463, y: 74, width: 229, height: 96 }
        Confidences: 0.9920712
Class: bicycle
        Bounding box: Rect_ { x: 128, y: 132, width: 438, height: 290 }
        Confidences: 0.9883387
Class: dog
        Bounding box: Rect_ { x: 132, y: 231, width: 177, height: 305 }
        Confidences: 0.99280965

real    0m0,663s
user    0m0,325s
sys     0m0,340s
dimitrii@dimitrii-pc:~/rust_work/object-detection-opencv-rust$ time cargo run --package od_opencv --example yolo_v4
warning: Patch `cc v1.0.79 (https://github.com/rust-lang/cc-rs.git?tag=1.0.79#e5bbdfa1)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.
warning: unused variable: `class_filters`
  --> examples/yolo_v4.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: `od_opencv` (example "yolo_v4") generated 1 warning (run `cargo fix --example "yolo_v4"` to apply 1 suggestion)
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/examples/yolo_v4`
Class: truck
        Bounding box: Rect_ { x: 463, y: 74, width: 229, height: 96 }
        Confidences: 0.9920712
Class: bicycle
        Bounding box: Rect_ { x: 128, y: 132, width: 438, height: 290 }
        Confidences: 0.9883387
Class: dog
        Bounding box: Rect_ { x: 132, y: 231, width: 177, height: 305 }
        Confidences: 0.99280965

real    0m0,660s
user    0m0,359s
sys     0m0,304s
LdDl commented 2 months ago

Glad to hear that it works! Yes, I'm planning to update Cargo.toml to include 0.9 version of OpenCV bindings, but it will happen in a couple of weeks after my vacation and checks that my other projects depending on this package won't be broken

Just bumped to 0.91.3 version

benjamingb commented 2 months ago

Usando (en caso de que sea más rápido), RTX 3060 (CUDA está habilitado) :cargo run``cargo build``TLDR

  • v7 darknet. Promedio:
real    0m0,5s
user    0m0,3s
sys     0m0,2s
  • v4 darknet. Promedio:
real    0m0,6s
user    0m0,4s
sys     0m0,3s
  • V8M Onnx. Promedio:
real    0m0,7s
user    0m0,4s
sys     0m0,2s
  • V8S Onnx. Promedio:
real    0m0,5s
user    0m0,4s
sys     0m0,2s

Parece que el modelo M solo requiere más recursos en computación. Pero, ¿debería afectar tanto a los FPS en tu caso?

Registros completos:

Tres ejecuciones en Traditional Darknet v7:

dimitrii@dimitrii-pc:~/rust_work/object-detection-opencv-rust$ time cargo run --package od_opencv --example yolo_v7 
warning: Patch `cc v1.0.79 (https://github.com/rust-lang/cc-rs.git?tag=1.0.79#e5bbdfa1)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/examples/yolo_v7`
Class: motorbike
        Bounding box: Rect_ { x: 56, y: 72, width: 53, height: 54 }
        Confidences: 0.36123458
Class: truck
        Bounding box: Rect_ { x: 468, y: 74, width: 225, height: 95 }
        Confidences: 0.9325973
Class: bicycle
        Bounding box: Rect_ { x: 126, y: 128, width: 440, height: 289 }
        Confidences: 0.9681798
Class: dog
        Bounding box: Rect_ { x: 130, y: 220, width: 180, height: 321 }
        Confidences: 0.9735598

real    0m0,527s
user    0m0,295s
sys     0m0,236s
dimitrii@dimitrii-pc:~/rust_work/object-detection-opencv-rust$ time cargo run --package od_opencv --example yolo_v7 
warning: Patch `cc v1.0.79 (https://github.com/rust-lang/cc-rs.git?tag=1.0.79#e5bbdfa1)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/examples/yolo_v7`
Class: motorbike
        Bounding box: Rect_ { x: 56, y: 72, width: 53, height: 54 }
        Confidences: 0.36123458
Class: truck
        Bounding box: Rect_ { x: 468, y: 74, width: 225, height: 95 }
        Confidences: 0.9325973
Class: bicycle
        Bounding box: Rect_ { x: 126, y: 128, width: 440, height: 289 }
        Confidences: 0.9681798
Class: dog
        Bounding box: Rect_ { x: 130, y: 220, width: 180, height: 321 }
        Confidences: 0.9735598

real    0m0,537s
user    0m0,297s
sys     0m0,243s
dimitrii@dimitrii-pc:~/rust_work/object-detection-opencv-rust$ time cargo run --package od_opencv --example yolo_v7 
warning: Patch `cc v1.0.79 (https://github.com/rust-lang/cc-rs.git?tag=1.0.79#e5bbdfa1)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/examples/yolo_v7`
Class: motorbike
        Bounding box: Rect_ { x: 56, y: 72, width: 53, height: 54 }
        Confidences: 0.36123458
Class: truck
        Bounding box: Rect_ { x: 468, y: 74, width: 225, height: 95 }
        Confidences: 0.9325973
Class: bicycle
        Bounding box: Rect_ { x: 126, y: 128, width: 440, height: 289 }
        Confidences: 0.9681798
Class: dog
        Bounding box: Rect_ { x: 130, y: 220, width: 180, height: 321 }
        Confidences: 0.9735598

real    0m0,521s
user    0m0,289s
sys     0m0,236s

Three runs on Ultralytics v8m:

dimitrii@dimitrii-pc:~/rust_work/object-detection-opencv-rust$ time cargo run --package od_opencv --example yolo_v8_m
warning: Patch `cc v1.0.79 (https://github.com/rust-lang/cc-rs.git?tag=1.0.79#e5bbdfa1)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.
warning: unused variable: `class_filters`
  --> examples/yolo_v8_m.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: `od_opencv` (example "yolo_v8_m") generated 1 warning (run `cargo fix --example "yolo_v8_m"` to apply 1 suggestion)
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/examples/yolo_v8_m`
Class: truck
        Bounding box: Rect_ { x: 465, y: 75, width: 226, height: 97 }
        Confidences: 0.86243707
Class: bicycle
        Bounding box: Rect_ { x: 125, y: 135, width: 442, height: 285 }
        Confidences: 0.9651602
Class: dog
        Bounding box: Rect_ { x: 132, y: 223, width: 179, height: 319 }
        Confidences: 0.94658756

real    0m0,662s
user    0m0,432s
sys     0m0,230s
dimitrii@dimitrii-pc:~/rust_work/object-detection-opencv-rust$ time cargo run --package od_opencv --example yolo_v8_m
warning: Patch `cc v1.0.79 (https://github.com/rust-lang/cc-rs.git?tag=1.0.79#e5bbdfa1)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.
warning: unused variable: `class_filters`
  --> examples/yolo_v8_m.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: `od_opencv` (example "yolo_v8_m") generated 1 warning (run `cargo fix --example "yolo_v8_m"` to apply 1 suggestion)
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/examples/yolo_v8_m`
Class: truck
        Bounding box: Rect_ { x: 465, y: 75, width: 226, height: 97 }
        Confidences: 0.86243707
Class: bicycle
        Bounding box: Rect_ { x: 125, y: 135, width: 442, height: 285 }
        Confidences: 0.9651602
Class: dog
        Bounding box: Rect_ { x: 132, y: 223, width: 179, height: 319 }
        Confidences: 0.94658756

real    0m0,667s
user    0m0,439s
sys     0m0,228s
dimitrii@dimitrii-pc:~/rust_work/object-detection-opencv-rust$ time cargo run --package od_opencv --example yolo_v8_m
warning: Patch `cc v1.0.79 (https://github.com/rust-lang/cc-rs.git?tag=1.0.79#e5bbdfa1)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.
warning: unused variable: `class_filters`
  --> examples/yolo_v8_m.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: `od_opencv` (example "yolo_v8_m") generated 1 warning (run `cargo fix --example "yolo_v8_m"` to apply 1 suggestion)
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/examples/yolo_v8_m`
Class: truck
        Bounding box: Rect_ { x: 465, y: 75, width: 226, height: 97 }
        Confidences: 0.86243707
Class: bicycle
        Bounding box: Rect_ { x: 125, y: 135, width: 442, height: 285 }
        Confidences: 0.9651602
Class: dog
        Bounding box: Rect_ { x: 132, y: 223, width: 179, height: 319 }
        Confidences: 0.94658756

real    0m0,659s
user    0m0,433s
sys     0m0,226s

Tres ejecuciones en Ultralytics v8:

dimitrii@dimitrii-pc:~/rust_work/object-detection-opencv-rust$ time cargo run --package od_opencv --example yolo_v8_s
warning: Patch `cc v1.0.79 (https://github.com/rust-lang/cc-rs.git?tag=1.0.79#e5bbdfa1)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.
warning: unused variable: `class_filters`
  --> examples/yolo_v8_s.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: `od_opencv` (example "yolo_v8_s") generated 1 warning (run `cargo fix --example "yolo_v8_s"` to apply 1 suggestion)
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/examples/yolo_v8_s`
Class: truck
        Bounding box: Rect_ { x: 468, y: 75, width: 226, height: 97 }
        Confidences: 0.86541396
Class: bicycle
        Bounding box: Rect_ { x: 126, y: 134, width: 445, height: 286 }
        Confidences: 0.90190446
Class: dog
        Bounding box: Rect_ { x: 132, y: 223, width: 179, height: 317 }
        Confidences: 0.9244803

real    0m0,574s
user    0m0,379s
sys     0m0,195s
dimitrii@dimitrii-pc:~/rust_work/object-detection-opencv-rust$ time cargo run --package od_opencv --example yolo_v8_s
warning: Patch `cc v1.0.79 (https://github.com/rust-lang/cc-rs.git?tag=1.0.79#e5bbdfa1)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.
warning: unused variable: `class_filters`
  --> examples/yolo_v8_s.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: `od_opencv` (example "yolo_v8_s") generated 1 warning (run `cargo fix --example "yolo_v8_s"` to apply 1 suggestion)
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/examples/yolo_v8_s`
Class: truck
        Bounding box: Rect_ { x: 468, y: 75, width: 226, height: 97 }
        Confidences: 0.86541396
Class: bicycle
        Bounding box: Rect_ { x: 126, y: 134, width: 445, height: 286 }
        Confidences: 0.90190446
Class: dog
        Bounding box: Rect_ { x: 132, y: 223, width: 179, height: 317 }
        Confidences: 0.9244803

real    0m0,564s
user    0m0,384s
sys     0m0,181s
dimitrii@dimitrii-pc:~/rust_work/object-detection-opencv-rust$ time cargo run --package od_opencv --example yolo_v8_s
warning: Patch `cc v1.0.79 (https://github.com/rust-lang/cc-rs.git?tag=1.0.79#e5bbdfa1)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.
warning: unused variable: `class_filters`
  --> examples/yolo_v8_s.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: `od_opencv` (example "yolo_v8_s") generated 1 warning (run `cargo fix --example "yolo_v8_s"` to apply 1 suggestion)
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/examples/yolo_v8_s`
Class: truck
        Bounding box: Rect_ { x: 468, y: 75, width: 226, height: 97 }
        Confidences: 0.86541396
Class: bicycle
        Bounding box: Rect_ { x: 126, y: 134, width: 445, height: 286 }
        Confidences: 0.90190446
Class: dog
        Bounding box: Rect_ { x: 132, y: 223, width: 179, height: 317 }
        Confidences: 0.9244803

real    0m0,557s
user    0m0,371s
sys     0m0,187s

Tres ejecuciones en Traditional Darknet v4:

dimitrii@dimitrii-pc:~/rust_work/object-detection-opencv-rust$ time cargo run --package od_opencv --example yolo_v4
warning: Patch `cc v1.0.79 (https://github.com/rust-lang/cc-rs.git?tag=1.0.79#e5bbdfa1)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.
warning: unused variable: `class_filters`
  --> examples/yolo_v4.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: `od_opencv` (example "yolo_v4") generated 1 warning (run `cargo fix --example "yolo_v4"` to apply 1 suggestion)
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/examples/yolo_v4`
Class: truck
        Bounding box: Rect_ { x: 463, y: 74, width: 229, height: 96 }
        Confidences: 0.9920712
Class: bicycle
        Bounding box: Rect_ { x: 128, y: 132, width: 438, height: 290 }
        Confidences: 0.9883387
Class: dog
        Bounding box: Rect_ { x: 132, y: 231, width: 177, height: 305 }
        Confidences: 0.99280965

real    0m0,678s
user    0m0,350s
sys     0m0,331s
dimitrii@dimitrii-pc:~/rust_work/object-detection-opencv-rust$ time cargo run --package od_opencv --example yolo_v4
warning: Patch `cc v1.0.79 (https://github.com/rust-lang/cc-rs.git?tag=1.0.79#e5bbdfa1)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.
warning: unused variable: `class_filters`
  --> examples/yolo_v4.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: `od_opencv` (example "yolo_v4") generated 1 warning (run `cargo fix --example "yolo_v4"` to apply 1 suggestion)
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/examples/yolo_v4`
Class: truck
        Bounding box: Rect_ { x: 463, y: 74, width: 229, height: 96 }
        Confidences: 0.9920712
Class: bicycle
        Bounding box: Rect_ { x: 128, y: 132, width: 438, height: 290 }
        Confidences: 0.9883387
Class: dog
        Bounding box: Rect_ { x: 132, y: 231, width: 177, height: 305 }
        Confidences: 0.99280965

real    0m0,663s
user    0m0,325s
sys     0m0,340s
dimitrii@dimitrii-pc:~/rust_work/object-detection-opencv-rust$ time cargo run --package od_opencv --example yolo_v4
warning: Patch `cc v1.0.79 (https://github.com/rust-lang/cc-rs.git?tag=1.0.79#e5bbdfa1)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.
warning: unused variable: `class_filters`
  --> examples/yolo_v4.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: `od_opencv` (example "yolo_v4") generated 1 warning (run `cargo fix --example "yolo_v4"` to apply 1 suggestion)
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/examples/yolo_v4`
Class: truck
        Bounding box: Rect_ { x: 463, y: 74, width: 229, height: 96 }
        Confidences: 0.9920712
Class: bicycle
        Bounding box: Rect_ { x: 128, y: 132, width: 438, height: 290 }
        Confidences: 0.9883387
Class: dog
        Bounding box: Rect_ { x: 132, y: 231, width: 177, height: 305 }
        Confidences: 0.99280965

real    0m0,660s
user    0m0,359s
sys     0m0,304s

I will have to test, I compile Opencv with CUDA but neither c++ nor rust detects it, only python detects it.

LdDl commented 3 weeks ago

I think I'll close issue due inactivity and actually working ONNX reader :D