Skip to content

Dnn Manipulations

add_net

Dnn.add_net(name)

Adds another DnnNet to Dnn.

Arguments

  • name: A string to specify the name of the added DnnNet like 'preprocess', 'main' etc.

Returns

Type : DnnNet,DnnNet added.


add_tensor

Dnn.add_tensor(name)

Adds a Tensor to Dnn.

Arguments

  • name: A string to specify the name of the Tensor to be added.

Returns

Type : Tensor,Tensor added.


decompose

Dnn.decompose(i_net_name, i_parts)

Decomposes the Dnn according to given DnnNetPartition. The main purpose of decompose operation is to make a part of net be calculated by different inference engine. To make the decomposed net be calculated by different inference engine, the decomposed net need to be squashed (see squash_net).

Arguments

  • i_net_name: The net name to be decomposed.
  • i_parts: The DnnNetPartition, partitioning position where dnn is decomposed.

Examples

import softneuro
import sys


# load a dnn.
dnn = softneuro.Dnn(sys.argv[1])

# make partitions.
parts = softneuro.DnnNetPartition()
parts.add_interval('input', 'conv2_1')  # make subnet-0
parts.add_interval('conv2_2', 'output') # make subnet-1

# decompose
dnn.decompose('main', parts)

# If the main-net is fully represented by sub-nets, 
# the main-net is no longer needed.
dnn.removeNet(dnn.findNet('main'))

find_main_net

Dnn.find_main_net()

Finds the main DnnNet from Dnn.

Returns

Type : DnnNet,DnnNet if found else NULL.


find_net

Dnn.find_net(name)

Finds a DnnNet with a specific name from Dnn.

Arguments

  • name: A string to specify the name of the DnnNet to find.

Returns

Type : DnnNet,DnnNet if found else NULL.


find_tensor

Dnn.find_tensor(name)

Finds a Tensor object with a specific name from Dnn.

Arguments

  • name: A string to specify the name of the Tensor to be found.

Returns

Type : Tensor,Tensor if found else NULL.


get_input

Dnn.get_input(input_index)

Gets input object DnnInput of the Dnn.

Arguments

  • input_index: The input index of the interest.

Returns

Type : DnnInput, DnnInput of the Dnn.


get_output

Dnn.get_output(output_index)

Gets output object DnnOutput of the Dnn.

Arguments

  • output_index: The output index of the interest.

Returns

Type : DnnOutput, DnnOutput of the Dnn.


get_model

Dnn.get_model()

Gets a model as a json string.

Returns

Type : str,json string of model.


is_buf_opt_enabled

Dnn.is_buf_opt_enabled(device)

Returns a boolean whether buffer optimization is enabled (true) or disabled (false).

Arguments

  • device: The Device of the interest.

Returns

Type : bool,true if optimization is enabled else false.


remove_net

Dnn.remove_net(net)

Removes a DnnNet from Dnn.

Arguments

  • net: A DnnNet object to be removed.

remove_tensor

Dnn.remove_tensor(tensor)

Removes a Tensor from Dnn.

Arguments

  • tensor: A Tensor object to be removed from Dnn.

set_model

Dnn.set_model(model)

Sets a model from json string.

Arguments

  • model: A json string to be set as model.

set_buf_opt_enabled

Dnn.set_buf_opt_enabled(device, is_enabled)

Enables or disables buffer optimization.

Arguments

  • device: Device for which buffer optimization will be enabled/disabled.
  • is_enabled: Boolean indicating whether it will be enabled (true) or disabled (false).

squash_net

Dnn.squash_net(net_name)

Squashes the net. The squashed net becomes a pseudo single layer of type complex. The squashed complex layer can be calculated by external inference engine.

Arguments

  • net_name: The net to be squashed.