-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathyolo_v4_tiny_onnx.rs
executable file
·51 lines (49 loc) · 1.4 KB
/
yolo_v4_tiny_onnx.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use od_opencv::{model_classic::ModelYOLOClassic, model_format::ModelFormat};
use opencv::{
core::{Scalar, Vector},
dnn::DNN_BACKEND_CUDA,
dnn::DNN_TARGET_CUDA,
imgcodecs::imread,
imgcodecs::imwrite,
imgproc::rectangle,
imgproc::LINE_4,
};
fn main() {
let classes_labels: Vec<&str> = vec!["car", "motorbike", "bus", "truck"];
let mf = ModelFormat::ONNX;
let net_width = 416;
let net_height = 416;
// let class_filters: Vec<usize> = vec![15, 16];
let class_filters: Vec<usize> = vec![];
let mut model = ModelYOLOClassic::new_from_file(
"pretrained/best_fp32.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.75, 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_yolov4_tiny.jpg", &frame, &Vector::new()).unwrap();
}