Skip to content

Commit

Permalink
feat: add rayon parallel indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
4o3F committed Oct 7, 2024
1 parent ed98f7e commit 35082a8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
12 changes: 11 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ tracing-subscriber = "0.3.18"
tracing = "0.1.40"
tracing-unwrap = "1.0.1"
regex = "*"
rayon = "*"
rayon = "*"
rayon-progress = "1.0.0"
14 changes: 8 additions & 6 deletions src/common/metric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use opencv::{
imgcodecs,
};
use rayon::prelude::*;
use rayon_progress::ProgressAdaptor;
use std::{
collections::HashMap,
sync::{Arc, Mutex},
};
use tracing_unwrap::ResultExt;

#[tracing::instrument]
pub fn calc_iou(target_img: &String, gt_img: &String) {
tracing::info!("Start loading images");
let target_img = imgcodecs::imread(&target_img, imgcodecs::IMREAD_COLOR)
Expand All @@ -31,10 +31,10 @@ pub fn calc_iou(target_img: &String, gt_img: &String) {
let rows = gt_img.rows();
let cols = gt_img.cols();

let span = tracing::span!(tracing::Level::INFO, "calc_iou");
let _enter = span.enter();

(0..rows).into_par_iter().for_each(|i| {
let row_iter = ProgressAdaptor::new(0..rows);
let row_progress = row_iter.items_processed();
let row_total = row_iter.len();
row_iter.for_each(|i| {
let mut row_intersection: HashMap<(u8, u8, u8), i64> = HashMap::new();
let mut row_union: HashMap<(u8, u8, u8), i64> = HashMap::new();
let mut row_confusion_matrix: HashMap<(u8, u8, u8), HashMap<(u8, u8, u8), i64>> =
Expand Down Expand Up @@ -78,7 +78,9 @@ pub fn calc_iou(target_img: &String, gt_img: &String) {
for (color, value) in row_confusion_matrix.into_iter() {
*confusion_matrix.entry(color).or_insert_with(HashMap::new) = value;
}
tracing::trace!("Y {} done", i);
if row_progress.get() != 0 && row_progress.get() % 1000 == 0 {
tracing::info!("Row {} / {} done", row_progress.get(), row_total);
}
});

let mut iou = HashMap::new();
Expand Down

0 comments on commit 35082a8

Please sign in to comment.