Struct Net

Source
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

Source

pub fn default() -> Result<Net>

Source

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.
Source

pub fn read_from_model_optimizer_1( buffer_model_config: &Vector<u8>, buffer_weights: &Vector<u8>, ) -> Result<Net>

Create a network from Intel’s Model Optimizer in-memory buffers with intermediate representation (IR).

§Parameters
  • bufferModelConfig: buffer with model’s configuration.
  • bufferWeights: buffer with model’s trained weights.
§Returns

Net object.

Source

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

Source§

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

Return the underlying raw pointer while consuming this wrapper. Read more
Source§

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

Return the underlying mutable raw pointer Read more
Source§

impl Clone for Net

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Net

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Net

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl NetTrait for Net

Source§

fn as_raw_mut_Net(&mut self) -> *mut c_void

Source§

fn dump(&mut self) -> Result<String>

Dump net to String Read more
Source§

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<()>

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>

Adds new layer to the net. Read more
Source§

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>

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>

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<()>

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<()>

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>

Registers network output with name Read more
Source§

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<()>

Specify shape of network input.
Source§

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>

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>

Runs forward pass to compute output of layer with name @p outputName. Read more
Source§

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<()>

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<()>

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<()>

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<()>

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>

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>

Returns a quantized Net from a floating-point Net. Read more
Source§

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<()>

Ask network to use specific computation backend where it supported. Read more
Source§

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<()>

Sets the new input value for the network Read more
Source§

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<()>

Sets the new value for the learned param of the layer. Read more
Source§

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<()>

Enables or disables layer fusion in the network. Read more
Source§

fn enable_winograd(&mut self, use_winograd: bool) -> Result<()>

Enables or disables the Winograd compute branch. The Winograd compute branch can speed up 3x3 Convolution at a small loss of accuracy. Read more
Source§

fn get_perf_profile(&mut self, timings: &mut Vector<f64>) -> Result<i64>

Returns overall time for inference and timings (in ticks) for layers. Read more
Source§

impl NetTraitConst for Net

Source§

fn as_raw_Net(&self) -> *const c_void

Source§

fn empty(&self) -> Result<bool>

Returns true if there are no layers in the network.
Source§

fn get_layer_id(&self, layer: &str) -> Result<i32>

Converts string name of the layer to the integer identifier. Read more
Source§

fn get_layer_names(&self) -> Result<Vector<String>>

Source§

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>>

👎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>>

👎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>>>

Returns pointers to input layers of specific layer.
Source§

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<()>

Returns output scale and zeropoint for a quantized Net. Read more
Source§

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>

Returns parameter blob of the layer. Read more
Source§

fn get_param_1(&self, layer_name: &str, num_param: i32) -> Result<Mat>

C++ default parameters Read more
Source§

fn get_param_def_1(&self, layer_name: &str) -> Result<Mat>

Source§

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>>

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<()>

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<()>

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<()>

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<()>

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>

Computes FLOP for whole loaded model with specified input shapes. Read more
Source§

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>

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>

Computes FLOP for whole loaded model with specified input shapes. Read more
Source§

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>

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<()>

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<()>

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<()>

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<()>

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<()>

Computes bytes number which are required to store all weights and intermediate blobs for each layer. Read more
Source§

fn get_memory_consumption_3( &self, net_input_shape: &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
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<Mat> ModifyInplace for Mat
where Mat: Boxed,

Source§

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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.