use crate::{Options, Xs, Y};
pub trait Vision: Sized {
type Input; fn new(options: Options) -> anyhow::Result<Self>;
fn preprocess(&self, xs: &[Self::Input]) -> anyhow::Result<Xs>;
fn inference(&mut self, xs: Xs) -> anyhow::Result<Xs>;
fn postprocess(&self, xs: Xs, xs0: &[Self::Input]) -> anyhow::Result<Vec<Y>>;
fn run(&mut self, xs: &[Self::Input]) -> anyhow::Result<Vec<Y>> {
let ys = self.preprocess(xs)?;
let ys = self.inference(ys)?;
let ys = self.postprocess(ys, xs)?;
Ok(ys)
}
fn forward(&mut self, xs: &[Self::Input], profile: bool) -> anyhow::Result<Vec<Y>> {
let t_pre = std::time::Instant::now();
let ys = self.preprocess(xs)?;
let t_pre = t_pre.elapsed();
let t_exe = std::time::Instant::now();
let ys = self.inference(ys)?;
let t_exe = t_exe.elapsed();
let t_post = std::time::Instant::now();
let ys = self.postprocess(ys, xs)?;
let t_post = t_post.elapsed();
if profile {
println!("> Preprocess: {t_pre:?} | Execution: {t_exe:?} | Postprocess: {t_post:?}");
}
Ok(ys)
}
}