Skip to content

Commit

Permalink
add read_network_from buffers example
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlad Kalmykov committed Sep 21, 2024
1 parent 7ef481c commit 6674547
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion crates/openvino/tests/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
mod fixtures;

use fixtures::alexnet::Fixture;
use openvino::Core;
use openvino::{Core, Shape, Tensor};

use std::fs;

#[test]
fn read_network() {
Expand All @@ -18,3 +20,23 @@ fn read_network() {
assert_eq!(read_model.get_inputs_len(), Ok(1));
assert_eq!(read_model.get_outputs_len(), Ok(1));
}

#[test]
fn read_network_from_buffers() {
let mut core = Core::new().unwrap();
let graph = fs::read(&Fixture::graph()).unwrap();
let weights = {
let weights = fs::read(&Fixture::weights()).unwrap();
let shape = Shape::new(&[1, weights.len() as i64]).unwrap();
let mut tensor = Tensor::new(openvino::ElementType::U8, &shape).unwrap();
let buffer = tensor.get_raw_data_mut().unwrap();
buffer.copy_from_slice(&weights);
tensor
};

let read_model = core.read_model_from_buffer(&graph, Some(&weights)).unwrap();

// Check the number of inputs and outputs.
assert_eq!(read_model.get_inputs_len(), Ok(1));
assert_eq!(read_model.get_outputs_len(), Ok(1));
}

0 comments on commit 6674547

Please sign in to comment.