use super::scale_aware_detector::{
ScaleAwareDetectorInferenceMode, ScaleAwareDetectorModel, ScaleAwareDetectorModelBuilder,
ScaleAwareDetectorModelOutput, ScaleAwareDetectorPostprocessConfig,
ScaleAwareDetectorPreprocessConfig,
};
use crate::core::OCRError;
use crate::core::inference::OrtInfer;
pub type PPDocLayoutPreprocessConfig = ScaleAwareDetectorPreprocessConfig;
pub type PPDocLayoutPostprocessConfig = ScaleAwareDetectorPostprocessConfig;
pub type PPDocLayoutModelOutput = ScaleAwareDetectorModelOutput;
pub type PPDocLayoutModel = ScaleAwareDetectorModel;
#[derive(Debug, Default)]
pub struct PPDocLayoutModelBuilder {
inner: ScaleAwareDetectorModelBuilder,
}
impl PPDocLayoutModelBuilder {
pub fn new() -> Self {
Self {
inner: ScaleAwareDetectorModelBuilder::pp_doclayout(),
}
}
pub fn preprocess_config(mut self, config: PPDocLayoutPreprocessConfig) -> Self {
self.inner = self.inner.preprocess_config(config);
self
}
pub fn image_shape(mut self, height: u32, width: u32) -> Self {
self.inner = self.inner.image_shape(height, width);
self
}
pub fn build(self, inference: OrtInfer) -> Result<PPDocLayoutModel, OCRError> {
let input_names = inference.input_names_from_model();
let mode = if input_names.iter().any(|n| n == "im_shape") {
ScaleAwareDetectorInferenceMode::ScaleFactorAndImageShape
} else {
ScaleAwareDetectorInferenceMode::ScaleFactorOnly
};
self.inner.inference_mode(mode).build(inference)
}
}