Skip to content

Commit

Permalink
🐛 fix used model in pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
chriamue committed Dec 31, 2023
1 parent f5eb557 commit 8a2b75e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub fn App() -> Html {
Arc::new(Pipeline::new(
(*video_queue).clone(),
(*processed_queue).clone(),
detector.get_model().clone(),
))
});

Expand Down
4 changes: 4 additions & 0 deletions src/wasm/hogdetector_js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ impl HogDetectorJS {
let y = y.into_iter().map(|y| y as usize).collect::<Vec<_>>();
hog.fit_class(&x, &y, 1).unwrap();
}

pub fn get_model(&self) -> &Arc<Mutex<Box<dyn HogDetectorTrait<f32, usize>>>> {
&self.hog
}
}

#[wasm_bindgen]
Expand Down
24 changes: 8 additions & 16 deletions src/wasm/pipeline.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
use crate::{
detection_filter::TrackerFilter, detector::visualize_detections, hogdetector::HogDetectorTrait,
prelude::DetectionFilter, HogDetector,
prelude::DetectionFilter,
};

use super::image_queue::ImageQueue;
use object_detector_rust::{classifier::RandomForestClassifier, detector::PersistentDetector};
use std::{
io::Cursor,
sync::{Arc, Mutex, TryLockError},
};
use std::sync::{Arc, Mutex, TryLockError};
use web_sys::ImageData;

#[derive(Clone)]
Expand All @@ -27,19 +23,16 @@ impl PartialEq for Pipeline {
}

impl Pipeline {
pub fn new(video_queue: Arc<ImageQueue>, processed_queue: Arc<ImageQueue>) -> Self {
let hog = {
let mut model: HogDetector<f32, usize, RandomForestClassifier<_, _>, _> =
HogDetector::default();
let file = Cursor::new(include_bytes!("../../res/eyes_random_forest_model.json"));
model.load(file).unwrap();
model
};
pub fn new(
video_queue: Arc<ImageQueue>,
processed_queue: Arc<ImageQueue>,
hog: Arc<Mutex<Box<dyn HogDetectorTrait<f32, usize>>>>,
) -> Self {
Pipeline {
id: rand::random(),
video_queue,
processed_queue,
hog: Arc::new(Mutex::new(Box::new(hog))),
hog,
detection_filter: Arc::new(Mutex::new(TrackerFilter::new(0.2))),
}
}
Expand Down Expand Up @@ -70,7 +63,6 @@ impl Pipeline {
match self.hog.try_lock() {
Ok(mut processor_guard) => {
if let Some(mut image_data) = self.video_queue.pop() {

let processor = processor_guard.as_mut();
let mut image = Pipeline::to_dynamic_image(image_data);
let detections = processor.detect(&mut image);
Expand Down

0 comments on commit 8a2b75e

Please sign in to comment.