From 66745474a5c94de6dfb01ade3c7caeeb159c18fc Mon Sep 17 00:00:00 2001 From: Vlad Kalmykov Date: Sat, 21 Sep 2024 16:00:57 +0300 Subject: [PATCH] add read_network_from buffers example --- crates/openvino/tests/setup.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/crates/openvino/tests/setup.rs b/crates/openvino/tests/setup.rs index bedf75c..a27aaa3 100644 --- a/crates/openvino/tests/setup.rs +++ b/crates/openvino/tests/setup.rs @@ -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() { @@ -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)); +}