pub struct Net { /* private fields */ }
Expand description
This class allows to create and manipulate comprehensive artificial neural networks.
Neural network is presented as directed acyclic graph (DAG), where vertices are Layer instances, and edges specify relationships between layers inputs and outputs.
Each network layer has unique integer id and unique string name inside its network. LayerId can store either layer name or layer id.
This class supports reference counting of its instances, i. e. copies point to the same instance.
Implementations§
Source§impl Net
impl Net
pub fn default() -> Result<Net>
Sourcepub fn read_from_model_optimizer(xml: &str, bin: &str) -> Result<Net>
pub fn read_from_model_optimizer(xml: &str, bin: &str) -> Result<Net>
Create a network from Intel’s Model Optimizer intermediate representation (IR).
§Parameters
- xml: XML configuration file with network’s topology.
- bin: Binary file with trained weights. Networks imported from Intel’s Model Optimizer are launched in Intel’s Inference Engine backend.
Sourcepub fn read_from_model_optimizer_1(
buffer_model_config: &Vector<u8>,
buffer_weights: &Vector<u8>,
) -> Result<Net>
pub fn read_from_model_optimizer_1( buffer_model_config: &Vector<u8>, buffer_weights: &Vector<u8>, ) -> Result<Net>
Sourcepub fn read_from_model_optimizer_2(
buffer_model_config_ptr: &[u8],
buffer_weights_ptr: &[u8],
) -> Result<Net>
pub fn read_from_model_optimizer_2( buffer_model_config_ptr: &[u8], buffer_weights_ptr: &[u8], ) -> Result<Net>
Create a network from Intel’s Model Optimizer in-memory buffers with intermediate representation (IR).
§Parameters
- bufferModelConfigPtr: buffer pointer of model’s configuration.
- bufferModelConfigSize: buffer size of model’s configuration.
- bufferWeightsPtr: buffer pointer of model’s trained weights.
- bufferWeightsSize: buffer size of model’s trained weights.
§Returns
Net object.
Trait Implementations§
Source§impl Boxed for Net
impl Boxed for Net
Source§unsafe fn from_raw(ptr: <Net as OpenCVFromExtern>::ExternReceive) -> Self
unsafe fn from_raw(ptr: <Net as OpenCVFromExtern>::ExternReceive) -> Self
Wrap the specified raw pointer Read more
Source§fn into_raw(self) -> <Net as OpenCVTypeExternContainer>::ExternSendMut
fn into_raw(self) -> <Net as OpenCVTypeExternContainer>::ExternSendMut
Return the underlying raw pointer while consuming this wrapper. Read more
Source§fn as_raw(&self) -> <Net as OpenCVTypeExternContainer>::ExternSend
fn as_raw(&self) -> <Net as OpenCVTypeExternContainer>::ExternSend
Return the underlying raw pointer. Read more
Source§fn as_raw_mut(&mut self) -> <Net as OpenCVTypeExternContainer>::ExternSendMut
fn as_raw_mut(&mut self) -> <Net as OpenCVTypeExternContainer>::ExternSendMut
Return the underlying mutable raw pointer Read more
Source§impl NetTrait for Net
impl NetTrait for Net
fn as_raw_mut_Net(&mut self) -> *mut c_void
Source§fn dump_to_file(&mut self, path: &str) -> Result<()>
fn dump_to_file(&mut self, path: &str) -> Result<()>
Dump net structure, hyperparameters, backend, target and fusion to dot file Read more
Source§fn dump_to_pbtxt(&mut self, path: &str) -> Result<()>
fn dump_to_pbtxt(&mut self, path: &str) -> Result<()>
Dump net structure, hyperparameters, backend, target and fusion to pbtxt file Read more
Source§fn add_layer_type(
&mut self,
name: &str,
typ: &str,
dtype: &i32,
params: &mut impl LayerParamsTrait,
) -> Result<i32>
fn add_layer_type( &mut self, name: &str, typ: &str, dtype: &i32, params: &mut impl LayerParamsTrait, ) -> Result<i32>
Adds new layer to the net. Read more
Source§fn add_layer(
&mut self,
name: &str,
typ: &str,
params: &mut impl LayerParamsTrait,
) -> Result<i32>
fn add_layer( &mut self, name: &str, typ: &str, params: &mut impl LayerParamsTrait, ) -> Result<i32>
Adds new layer to the net. Read more
Source§fn add_layer_to_prev_type(
&mut self,
name: &str,
typ: &str,
dtype: &i32,
params: &mut impl LayerParamsTrait,
) -> Result<i32>
fn add_layer_to_prev_type( &mut self, name: &str, typ: &str, dtype: &i32, params: &mut impl LayerParamsTrait, ) -> Result<i32>
Adds new layer and connects its first input to the first output of previously added layer. Read more
Source§fn add_layer_to_prev(
&mut self,
name: &str,
typ: &str,
params: &mut impl LayerParamsTrait,
) -> Result<i32>
fn add_layer_to_prev( &mut self, name: &str, typ: &str, params: &mut impl LayerParamsTrait, ) -> Result<i32>
Adds new layer and connects its first input to the first output of previously added layer. Read more
Source§fn connect_first_second(&mut self, out_pin: &str, inp_pin: &str) -> Result<()>
fn connect_first_second(&mut self, out_pin: &str, inp_pin: &str) -> Result<()>
Connects output of the first layer to input of the second layer. Read more
Source§fn connect(
&mut self,
out_layer_id: i32,
out_num: i32,
inp_layer_id: i32,
inp_num: i32,
) -> Result<()>
fn connect( &mut self, out_layer_id: i32, out_num: i32, inp_layer_id: i32, inp_num: i32, ) -> Result<()>
Connects #@p outNum output of the first layer to #@p inNum input of the second layer. Read more
Source§fn register_output(
&mut self,
output_name: &str,
layer_id: i32,
output_port: i32,
) -> Result<i32>
fn register_output( &mut self, output_name: &str, layer_id: i32, output_port: i32, ) -> Result<i32>
Registers network output with name Read more
Source§fn set_inputs_names(&mut self, input_blob_names: &Vector<String>) -> Result<()>
fn set_inputs_names(&mut self, input_blob_names: &Vector<String>) -> Result<()>
Sets outputs names of the network input pseudo layer. Read more
Source§fn set_input_shape(&mut self, input_name: &str, shape: &MatShape) -> Result<()>
fn set_input_shape(&mut self, input_name: &str, shape: &MatShape) -> Result<()>
Specify shape of network input.
Source§fn forward_single(&mut self, output_name: &str) -> Result<Mat>
fn forward_single(&mut self, output_name: &str) -> Result<Mat>
Runs forward pass to compute output of layer with name @p outputName. Read more
Source§fn forward_single_def(&mut self) -> Result<Mat>
fn forward_single_def(&mut self) -> Result<Mat>
Runs forward pass to compute output of layer with name @p outputName. Read more
Source§fn forward_async(&mut self, output_name: &str) -> Result<AsyncArray>
fn forward_async(&mut self, output_name: &str) -> Result<AsyncArray>
Runs forward pass to compute output of layer with name @p outputName. Read more
Source§fn forward_async_def(&mut self) -> Result<AsyncArray>
fn forward_async_def(&mut self) -> Result<AsyncArray>
Runs forward pass to compute output of layer with name @p outputName. Read more
Source§fn forward_layer(
&mut self,
output_blobs: &mut impl ToOutputArray,
output_name: &str,
) -> Result<()>
fn forward_layer( &mut self, output_blobs: &mut impl ToOutputArray, output_name: &str, ) -> Result<()>
Runs forward pass to compute output of layer with name @p outputName. Read more
Source§fn forward_layer_def(
&mut self,
output_blobs: &mut impl ToOutputArray,
) -> Result<()>
fn forward_layer_def( &mut self, output_blobs: &mut impl ToOutputArray, ) -> Result<()>
Runs forward pass to compute output of layer with name @p outputName. Read more
Source§fn forward(
&mut self,
output_blobs: &mut impl ToOutputArray,
out_blob_names: &Vector<String>,
) -> Result<()>
fn forward( &mut self, output_blobs: &mut impl ToOutputArray, out_blob_names: &Vector<String>, ) -> Result<()>
Runs forward pass to compute outputs of layers listed in @p outBlobNames. Read more
Source§fn forward_and_retrieve(
&mut self,
output_blobs: &mut Vector<Vector<Mat>>,
out_blob_names: &Vector<String>,
) -> Result<()>
fn forward_and_retrieve( &mut self, output_blobs: &mut Vector<Vector<Mat>>, out_blob_names: &Vector<String>, ) -> Result<()>
Runs forward pass to compute outputs of layers listed in @p outBlobNames. Read more
Source§fn quantize(
&mut self,
calib_data: &impl ToInputArray,
inputs_dtype: i32,
outputs_dtype: i32,
per_channel: bool,
) -> Result<Net>
fn quantize( &mut self, calib_data: &impl ToInputArray, inputs_dtype: i32, outputs_dtype: i32, per_channel: bool, ) -> Result<Net>
Returns a quantized Net from a floating-point Net. Read more
Source§fn quantize_def(
&mut self,
calib_data: &impl ToInputArray,
inputs_dtype: i32,
outputs_dtype: i32,
) -> Result<Net>
fn quantize_def( &mut self, calib_data: &impl ToInputArray, inputs_dtype: i32, outputs_dtype: i32, ) -> Result<Net>
Returns a quantized Net from a floating-point Net. Read more
Source§fn set_halide_scheduler(&mut self, scheduler: &str) -> Result<()>
fn set_halide_scheduler(&mut self, scheduler: &str) -> Result<()>
Compile Halide layers. Read more
Source§fn set_preferable_backend(&mut self, backend_id: i32) -> Result<()>
fn set_preferable_backend(&mut self, backend_id: i32) -> Result<()>
Ask network to use specific computation backend where it supported. Read more
Source§fn set_preferable_target(&mut self, target_id: i32) -> Result<()>
fn set_preferable_target(&mut self, target_id: i32) -> Result<()>
Ask network to make computations on specific target device. Read more
Source§fn set_input(
&mut self,
blob: &impl ToInputArray,
name: &str,
scalefactor: f64,
mean: Scalar,
) -> Result<()>
fn set_input( &mut self, blob: &impl ToInputArray, name: &str, scalefactor: f64, mean: Scalar, ) -> Result<()>
Sets the new input value for the network Read more
Source§fn set_input_def(&mut self, blob: &impl ToInputArray) -> Result<()>
fn set_input_def(&mut self, blob: &impl ToInputArray) -> Result<()>
Sets the new input value for the network Read more
Source§fn set_param(
&mut self,
layer: i32,
num_param: i32,
blob: &impl MatTraitConst,
) -> Result<()>
fn set_param( &mut self, layer: i32, num_param: i32, blob: &impl MatTraitConst, ) -> Result<()>
Sets the new value for the learned param of the layer. Read more
fn set_param_1( &mut self, layer_name: &str, num_param: i32, blob: &impl MatTraitConst, ) -> Result<()>
Source§fn enable_fusion(&mut self, fusion: bool) -> Result<()>
fn enable_fusion(&mut self, fusion: bool) -> Result<()>
Enables or disables layer fusion in the network. Read more
Source§impl NetTraitConst for Net
impl NetTraitConst for Net
fn as_raw_Net(&self) -> *const c_void
Source§fn get_layer_id(&self, layer: &str) -> Result<i32>
fn get_layer_id(&self, layer: &str) -> Result<i32>
Converts string name of the layer to the integer identifier. Read more
fn get_layer_names(&self) -> Result<Vector<String>>
Source§fn get_layer(&self, layer_id: i32) -> Result<Ptr<Layer>>
fn get_layer(&self, layer_id: i32) -> Result<Ptr<Layer>>
Returns pointer to layer with specified id or name which the network use.
Source§fn get_layer_1(&self, layer_name: &str) -> Result<Ptr<Layer>>
fn get_layer_1(&self, layer_name: &str) -> Result<Ptr<Layer>>
👎Deprecated: Use int getLayerId(const String &layer)
Returns pointer to layer with specified id or name which the network use. Read more
Source§fn get_layer_2(&self, layer_id: &impl DictValueTraitConst) -> Result<Ptr<Layer>>
fn get_layer_2(&self, layer_id: &impl DictValueTraitConst) -> Result<Ptr<Layer>>
👎Deprecated: to be removed
Returns pointer to layer with specified id or name which the network use. Read more
Source§fn get_layer_inputs(&self, layer_id: i32) -> Result<Vector<Ptr<Layer>>>
fn get_layer_inputs(&self, layer_id: i32) -> Result<Vector<Ptr<Layer>>>
Returns pointers to input layers of specific layer.
Source§fn get_input_details(
&self,
scales: &mut Vector<f32>,
zeropoints: &mut Vector<i32>,
) -> Result<()>
fn get_input_details( &self, scales: &mut Vector<f32>, zeropoints: &mut Vector<i32>, ) -> Result<()>
Returns input scale and zeropoint for a quantized Net. Read more
Source§fn get_output_details(
&self,
scales: &mut Vector<f32>,
zeropoints: &mut Vector<i32>,
) -> Result<()>
fn get_output_details( &self, scales: &mut Vector<f32>, zeropoints: &mut Vector<i32>, ) -> Result<()>
Returns output scale and zeropoint for a quantized Net. Read more
Source§fn get_param(&self, layer: i32, num_param: i32) -> Result<Mat>
fn get_param(&self, layer: i32, num_param: i32) -> Result<Mat>
Returns parameter blob of the layer. Read more
Source§fn get_param_def(&self, layer: i32) -> Result<Mat>
fn get_param_def(&self, layer: i32) -> Result<Mat>
Returns parameter blob of the layer. Read more
Source§fn get_param_1(&self, layer_name: &str, num_param: i32) -> Result<Mat>
fn get_param_1(&self, layer_name: &str, num_param: i32) -> Result<Mat>
C++ default parameters Read more
Source§fn get_unconnected_out_layers(&self) -> Result<Vector<i32>>
fn get_unconnected_out_layers(&self) -> Result<Vector<i32>>
Returns indexes of layers with unconnected outputs. Read more
Source§fn get_unconnected_out_layers_names(&self) -> Result<Vector<String>>
fn get_unconnected_out_layers_names(&self) -> Result<Vector<String>>
Returns names of layers with unconnected outputs. Read more
Source§fn get_layers_shapes(
&self,
net_input_shapes: &Vector<MatShape>,
layers_ids: &mut Vector<i32>,
in_layers_shapes: &mut Vector<Vector<MatShape>>,
out_layers_shapes: &mut Vector<Vector<MatShape>>,
) -> Result<()>
fn get_layers_shapes( &self, net_input_shapes: &Vector<MatShape>, layers_ids: &mut Vector<i32>, in_layers_shapes: &mut Vector<Vector<MatShape>>, out_layers_shapes: &mut Vector<Vector<MatShape>>, ) -> Result<()>
Returns input and output shapes for all layers in loaded model;
preliminary inferencing isn’t necessary. Read more
Source§fn get_layers_shapes_1(
&self,
net_input_shape: &MatShape,
layers_ids: &mut Vector<i32>,
in_layers_shapes: &mut Vector<Vector<MatShape>>,
out_layers_shapes: &mut Vector<Vector<MatShape>>,
) -> Result<()>
fn get_layers_shapes_1( &self, net_input_shape: &MatShape, layers_ids: &mut Vector<i32>, in_layers_shapes: &mut Vector<Vector<MatShape>>, out_layers_shapes: &mut Vector<Vector<MatShape>>, ) -> Result<()>
Returns input and output shapes for all layers in loaded model;
preliminary inferencing isn’t necessary. Read more
Source§fn get_layer_shapes(
&self,
net_input_shape: &MatShape,
layer_id: i32,
in_layer_shapes: &mut Vector<MatShape>,
out_layer_shapes: &mut Vector<MatShape>,
) -> Result<()>
fn get_layer_shapes( &self, net_input_shape: &MatShape, layer_id: i32, in_layer_shapes: &mut Vector<MatShape>, out_layer_shapes: &mut Vector<MatShape>, ) -> Result<()>
Returns input and output shapes for layer with specified
id in loaded model; preliminary inferencing isn’t necessary. Read more
Source§fn get_layer_shapes_1(
&self,
net_input_shapes: &Vector<MatShape>,
layer_id: i32,
in_layer_shapes: &mut Vector<MatShape>,
out_layer_shapes: &mut Vector<MatShape>,
) -> Result<()>
fn get_layer_shapes_1( &self, net_input_shapes: &Vector<MatShape>, layer_id: i32, in_layer_shapes: &mut Vector<MatShape>, out_layer_shapes: &mut Vector<MatShape>, ) -> Result<()>
Returns input and output shapes for layer with specified
id in loaded model; preliminary inferencing isn’t necessary. Read more
Source§fn get_flops(&self, net_input_shapes: &Vector<MatShape>) -> Result<i64>
fn get_flops(&self, net_input_shapes: &Vector<MatShape>) -> Result<i64>
Computes FLOP for whole loaded model with specified input shapes. Read more
Source§fn get_flops_1(&self, net_input_shape: &MatShape) -> Result<i64>
fn get_flops_1(&self, net_input_shape: &MatShape) -> Result<i64>
Computes FLOP for whole loaded model with specified input shapes. Read more
Source§fn get_flops_2(
&self,
layer_id: i32,
net_input_shapes: &Vector<MatShape>,
) -> Result<i64>
fn get_flops_2( &self, layer_id: i32, net_input_shapes: &Vector<MatShape>, ) -> Result<i64>
Computes FLOP for whole loaded model with specified input shapes. Read more
Source§fn get_flops_3(&self, layer_id: i32, net_input_shape: &MatShape) -> Result<i64>
fn get_flops_3(&self, layer_id: i32, net_input_shape: &MatShape) -> Result<i64>
Computes FLOP for whole loaded model with specified input shapes. Read more
Source§fn get_layer_types(&self, layers_types: &mut Vector<String>) -> Result<()>
fn get_layer_types(&self, layers_types: &mut Vector<String>) -> Result<()>
Returns list of types for layer used in model. Read more
Source§fn get_layers_count(&self, layer_type: &str) -> Result<i32>
fn get_layers_count(&self, layer_type: &str) -> Result<i32>
Returns count of layers of specified type. Read more
Source§fn get_memory_consumption(
&self,
net_input_shapes: &Vector<MatShape>,
weights: &mut size_t,
blobs: &mut size_t,
) -> Result<()>
fn get_memory_consumption( &self, net_input_shapes: &Vector<MatShape>, weights: &mut size_t, blobs: &mut size_t, ) -> Result<()>
Computes bytes number which are required to store
all weights and intermediate blobs for model. Read more
Source§fn get_memory_consumption_1(
&self,
net_input_shape: &MatShape,
weights: &mut size_t,
blobs: &mut size_t,
) -> Result<()>
fn get_memory_consumption_1( &self, net_input_shape: &MatShape, weights: &mut size_t, blobs: &mut size_t, ) -> Result<()>
Computes bytes number which are required to store
all weights and intermediate blobs for model. Read more
Source§fn get_memory_consumption_for_layer(
&self,
layer_id: i32,
net_input_shapes: &Vector<MatShape>,
weights: &mut size_t,
blobs: &mut size_t,
) -> Result<()>
fn get_memory_consumption_for_layer( &self, layer_id: i32, net_input_shapes: &Vector<MatShape>, weights: &mut size_t, blobs: &mut size_t, ) -> Result<()>
Computes bytes number which are required to store
all weights and intermediate blobs for model. Read more
Source§fn get_memory_consumption_2(
&self,
layer_id: i32,
net_input_shape: &MatShape,
weights: &mut size_t,
blobs: &mut size_t,
) -> Result<()>
fn get_memory_consumption_2( &self, layer_id: i32, net_input_shape: &MatShape, weights: &mut size_t, blobs: &mut size_t, ) -> Result<()>
Computes bytes number which are required to store
all weights and intermediate blobs for model. Read more
Source§fn get_memory_consumption_for_layers(
&self,
net_input_shapes: &Vector<MatShape>,
layer_ids: &mut Vector<i32>,
weights: &mut Vector<size_t>,
blobs: &mut Vector<size_t>,
) -> Result<()>
fn get_memory_consumption_for_layers( &self, net_input_shapes: &Vector<MatShape>, layer_ids: &mut Vector<i32>, weights: &mut Vector<size_t>, blobs: &mut Vector<size_t>, ) -> Result<()>
Computes bytes number which are required to store
all weights and intermediate blobs for each layer. Read more
impl Send for Net
Auto Trait Implementations§
impl Freeze for Net
impl RefUnwindSafe for Net
impl !Sync for Net
impl Unpin for Net
impl UnwindSafe for Net
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Mat> ModifyInplace for Matwhere
Mat: Boxed,
impl<Mat> ModifyInplace for Matwhere
Mat: Boxed,
Source§unsafe fn modify_inplace<Res>(
&mut self,
f: impl FnOnce(&Mat, &mut Mat) -> Res,
) -> Res
unsafe fn modify_inplace<Res>( &mut self, f: impl FnOnce(&Mat, &mut Mat) -> Res, ) -> Res
Helper function to call OpenCV functions that allow in-place modification of a
Mat
or another similar object. By passing
a mutable reference to the Mat
to this function your closure will get called with the read reference and a write references
to the same Mat
. This is unsafe in a general case as it leads to having non-exclusive mutable access to the internal data,
but it can be useful for some performance sensitive operations. One example of an OpenCV function that allows such in-place
modification is imgproc::threshold
. Read more