pub struct Prediction { /* private fields */ }Implementations§
Source§impl Prediction
impl Prediction
Sourcepub fn get_f32(&self, name: &str) -> Result<(Vec<f32>, Vec<usize>)>
pub fn get_f32(&self, name: &str) -> Result<(Vec<f32>, Vec<usize>)>
Get an output as (Vec
Examples found in repository?
examples/load_and_predict.rs (line 23)
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}Sourcepub fn get_f32_into(&self, name: &str, buf: &mut [f32]) -> Result<Vec<usize>>
pub fn get_f32_into(&self, name: &str, buf: &mut [f32]) -> Result<Vec<usize>>
Copy an output into a caller-provided f32 buffer (zero-alloc hot path).
Returns the shape. The buffer must be large enough to hold all elements.
Sourcepub fn get_i32(&self, name: &str) -> Result<(Vec<i32>, Vec<usize>)>
pub fn get_i32(&self, name: &str) -> Result<(Vec<i32>, Vec<usize>)>
Get an output as (Vec
Trait Implementations§
impl Send for Prediction
Available on Apple only.
impl Sync for Prediction
Available on Apple only.
Auto Trait Implementations§
impl Freeze for Prediction
impl !RefUnwindSafe for Prediction
impl Unpin for Prediction
impl UnsafeUnpin for Prediction
impl !UnwindSafe for Prediction
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