pub struct Model { /* private fields */ }Implementations§
Source§impl Model
impl Model
Sourcepub fn load_async(
_path: impl AsRef<Path>,
_compute_units: ComputeUnits,
) -> Result<CompletionFuture<Self>>
pub fn load_async( _path: impl AsRef<Path>, _compute_units: ComputeUnits, ) -> Result<CompletionFuture<Self>>
Load a compiled model asynchronously (stub for non-Apple platforms).
Sourcepub fn load_from_bytes(
_data: &[u8],
_compute_units: ComputeUnits,
) -> Result<CompletionFuture<Self>>
pub fn load_from_bytes( _data: &[u8], _compute_units: ComputeUnits, ) -> Result<CompletionFuture<Self>>
Load a model from in-memory bytes (stub for non-Apple platforms).
Sourcepub fn predict_async(
&self,
_inputs: &[(&str, &dyn AsMultiArray)],
) -> Result<CompletionFuture<Prediction>>
pub fn predict_async( &self, _inputs: &[(&str, &dyn AsMultiArray)], ) -> Result<CompletionFuture<Prediction>>
Run a prediction asynchronously (stub for non-Apple platforms).
Source§impl Model
impl Model
Sourcepub fn load(
_path: impl AsRef<Path>,
_compute_units: ComputeUnits,
) -> Result<Self>
pub fn load( _path: impl AsRef<Path>, _compute_units: ComputeUnits, ) -> Result<Self>
Examples found in repository?
examples/load_and_predict.rs (line 13)
7fn main() {
8 let model_path = std::env::args()
9 .nth(1)
10 .unwrap_or_else(|| "tests/fixtures/test_linear.mlmodelc".to_string());
11
12 println!("Loading model: {model_path}");
13 let model = Model::load(&model_path, ComputeUnits::All).expect("Failed to load model");
14
15 // Create a simple input tensor
16 let input_data = vec![1.0f32, 2.0, 3.0, 4.0];
17 let tensor =
18 BorrowedTensor::from_f32(&input_data, &[1, 4]).expect("Failed to create tensor");
19
20 println!("Running prediction...");
21 let prediction = model.predict(&[("input", &tensor)]).expect("Prediction failed");
22
23 let (output, shape) = prediction.get_f32("output").expect("Failed to get output");
24 println!("Output shape: {shape:?}");
25 println!("Output data: {output:?}");
26}More examples
examples/inspect_model.rs (line 13)
7fn main() {
8 let model_path = std::env::args()
9 .nth(1)
10 .unwrap_or_else(|| "tests/fixtures/test_linear.mlmodelc".to_string());
11
12 println!("Loading model: {model_path}");
13 let model = Model::load(&model_path, ComputeUnits::All).expect("Failed to load model");
14
15 println!("\n--- Inputs ---");
16 for desc in model.inputs() {
17 println!(
18 " {}: {:?} shape={:?} optional={}",
19 desc.name(),
20 desc.feature_type(),
21 desc.shape(),
22 desc.is_optional(),
23 );
24 if let Some(dt) = desc.data_type() {
25 println!(" data_type: {dt}");
26 }
27 }
28
29 println!("\n--- Outputs ---");
30 for desc in model.outputs() {
31 println!(
32 " {}: {:?} shape={:?}",
33 desc.name(),
34 desc.feature_type(),
35 desc.shape(),
36 );
37 if let Some(dt) = desc.data_type() {
38 println!(" data_type: {dt}");
39 }
40 }
41
42 let meta = model.metadata();
43 println!("\n--- Metadata ---");
44 println!(" author: {:?}", meta.author);
45 println!(" description: {:?}", meta.description);
46 println!(" version: {:?}", meta.version);
47 println!(" license: {:?}", meta.license);
48}Sourcepub fn predict(
&self,
_inputs: &[(&str, &dyn AsMultiArray)],
) -> Result<Prediction>
pub fn predict( &self, _inputs: &[(&str, &dyn AsMultiArray)], ) -> Result<Prediction>
Examples found in repository?
examples/load_and_predict.rs (line 21)
7fn main() {
8 let model_path = std::env::args()
9 .nth(1)
10 .unwrap_or_else(|| "tests/fixtures/test_linear.mlmodelc".to_string());
11
12 println!("Loading model: {model_path}");
13 let model = Model::load(&model_path, ComputeUnits::All).expect("Failed to load model");
14
15 // Create a simple input tensor
16 let input_data = vec![1.0f32, 2.0, 3.0, 4.0];
17 let tensor =
18 BorrowedTensor::from_f32(&input_data, &[1, 4]).expect("Failed to create tensor");
19
20 println!("Running prediction...");
21 let prediction = model.predict(&[("input", &tensor)]).expect("Prediction failed");
22
23 let (output, shape) = prediction.get_f32("output").expect("Failed to get output");
24 println!("Output shape: {shape:?}");
25 println!("Output data: {output:?}");
26}pub fn new_state(&self) -> Result<State>
pub fn predict_stateful( &self, _inputs: &[(&str, &dyn AsMultiArray)], _state: &State, ) -> Result<Prediction>
pub fn predict_batch(&self, _batch: &BatchProvider) -> Result<BatchPrediction>
Sourcepub fn inputs(&self) -> Vec<FeatureDescription>
pub fn inputs(&self) -> Vec<FeatureDescription>
Examples found in repository?
examples/inspect_model.rs (line 16)
7fn main() {
8 let model_path = std::env::args()
9 .nth(1)
10 .unwrap_or_else(|| "tests/fixtures/test_linear.mlmodelc".to_string());
11
12 println!("Loading model: {model_path}");
13 let model = Model::load(&model_path, ComputeUnits::All).expect("Failed to load model");
14
15 println!("\n--- Inputs ---");
16 for desc in model.inputs() {
17 println!(
18 " {}: {:?} shape={:?} optional={}",
19 desc.name(),
20 desc.feature_type(),
21 desc.shape(),
22 desc.is_optional(),
23 );
24 if let Some(dt) = desc.data_type() {
25 println!(" data_type: {dt}");
26 }
27 }
28
29 println!("\n--- Outputs ---");
30 for desc in model.outputs() {
31 println!(
32 " {}: {:?} shape={:?}",
33 desc.name(),
34 desc.feature_type(),
35 desc.shape(),
36 );
37 if let Some(dt) = desc.data_type() {
38 println!(" data_type: {dt}");
39 }
40 }
41
42 let meta = model.metadata();
43 println!("\n--- Metadata ---");
44 println!(" author: {:?}", meta.author);
45 println!(" description: {:?}", meta.description);
46 println!(" version: {:?}", meta.version);
47 println!(" license: {:?}", meta.license);
48}Sourcepub fn outputs(&self) -> Vec<FeatureDescription>
pub fn outputs(&self) -> Vec<FeatureDescription>
Examples found in repository?
examples/inspect_model.rs (line 30)
7fn main() {
8 let model_path = std::env::args()
9 .nth(1)
10 .unwrap_or_else(|| "tests/fixtures/test_linear.mlmodelc".to_string());
11
12 println!("Loading model: {model_path}");
13 let model = Model::load(&model_path, ComputeUnits::All).expect("Failed to load model");
14
15 println!("\n--- Inputs ---");
16 for desc in model.inputs() {
17 println!(
18 " {}: {:?} shape={:?} optional={}",
19 desc.name(),
20 desc.feature_type(),
21 desc.shape(),
22 desc.is_optional(),
23 );
24 if let Some(dt) = desc.data_type() {
25 println!(" data_type: {dt}");
26 }
27 }
28
29 println!("\n--- Outputs ---");
30 for desc in model.outputs() {
31 println!(
32 " {}: {:?} shape={:?}",
33 desc.name(),
34 desc.feature_type(),
35 desc.shape(),
36 );
37 if let Some(dt) = desc.data_type() {
38 println!(" data_type: {dt}");
39 }
40 }
41
42 let meta = model.metadata();
43 println!("\n--- Metadata ---");
44 println!(" author: {:?}", meta.author);
45 println!(" description: {:?}", meta.description);
46 println!(" version: {:?}", meta.version);
47 println!(" license: {:?}", meta.license);
48}Sourcepub fn metadata(&self) -> ModelMetadata
pub fn metadata(&self) -> ModelMetadata
Examples found in repository?
examples/inspect_model.rs (line 42)
7fn main() {
8 let model_path = std::env::args()
9 .nth(1)
10 .unwrap_or_else(|| "tests/fixtures/test_linear.mlmodelc".to_string());
11
12 println!("Loading model: {model_path}");
13 let model = Model::load(&model_path, ComputeUnits::All).expect("Failed to load model");
14
15 println!("\n--- Inputs ---");
16 for desc in model.inputs() {
17 println!(
18 " {}: {:?} shape={:?} optional={}",
19 desc.name(),
20 desc.feature_type(),
21 desc.shape(),
22 desc.is_optional(),
23 );
24 if let Some(dt) = desc.data_type() {
25 println!(" data_type: {dt}");
26 }
27 }
28
29 println!("\n--- Outputs ---");
30 for desc in model.outputs() {
31 println!(
32 " {}: {:?} shape={:?}",
33 desc.name(),
34 desc.feature_type(),
35 desc.shape(),
36 );
37 if let Some(dt) = desc.data_type() {
38 println!(" data_type: {dt}");
39 }
40 }
41
42 let meta = model.metadata();
43 println!("\n--- Metadata ---");
44 println!(" author: {:?}", meta.author);
45 println!(" description: {:?}", meta.description);
46 println!(" version: {:?}", meta.version);
47 println!(" license: {:?}", meta.license);
48}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Model
impl RefUnwindSafe for Model
impl Send for Model
impl Sync for Model
impl Unpin for Model
impl UnsafeUnpin for Model
impl UnwindSafe for Model
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more