Class SNPE::NeuralNetworkBuilder

Nested Relationships

This class is a nested type of Class SNPE.

Class Documentation

class NeuralNetworkBuilder

Class exposes a way to configure and create NeuralNetwork instances.

Public Functions

inline  NeuralNetworkBuilder (final Application application)
inline NeuralNetworkBuilder setRuntimeOrder (final NeuralNetwork.Runtime... order)

Sets the runtime selection order for the neural network.

Parameters

order – array with the priority order for selecting an available runtime.

Returns

the builder itself.

inline NeuralNetworkBuilder setInputDimensions (final Map< String, int[]> inputDimensions)

Sets network’s input dimensions to enable resizing of dimensions of the network.

Parameters

inputDimensions – map of input names and their new dimensions.

Returns

the builder itself

inline NeuralNetworkBuilder setOutputLayers (final String... outputLayers)

Sets the output layers to return when NeuralNetwork#execute(Map) is called.

Parameters

outputLayers – name of the output layers to retrieve.

Returns

the builder itself.

inline NeuralNetworkBuilder setModel (final InputStream stream, final int size)

Reads the model from the provided InputStream. The caller is responsible to close the stream after calling this method. After build() has been called, it is required that this method be invoked to re-set the input stream before every successive call to build() on the same instance.

Parameters
  • stream – input stream from where to read the model from.

  • size – number of bytes to read from the stream.

Throws

IOException – if not able to read from the stream.

Returns

the builder itself.

inline NeuralNetworkBuilder setModel (final File file)

Sets the file from where to read the DLC model from.

Parameters

file – DLC model file.

Throws

IOException – if not able to read from the stream.

Returns

the builder itself.

inline NeuralNetworkBuilder setDebugEnabled (final boolean isEnabled)
inline NeuralNetworkBuilder setPerformanceProfile (final PerformanceProfile profile)

Selects a performance profile to use during the network execution.

Parameters

profile – target performance profile.

Returns

the builder itself.

inline NeuralNetworkBuilder setProfilingLevel (final ProfilingLevel profile)

Selects a profile level to use during the network execution.

Parameters

profile – target profile level.

Returns

the builder itself.

inline NeuralNetworkBuilder setExecutionPriorityHint (final ExecutionPriorityHint priority)

Passes an execution priority hint to the runtime

Parameters

priority – target execution priority.

Returns

the builder itself.

inline NeuralNetworkBuilder setCpuFallbackEnabled(boolean enabled)

Enables/Disables falling back to CPU if a layer is not supported in the selected runtime.

Parameters

enabled

inline NeuralNetworkBuilder setUnsignedPD(boolean enabled)

Sets Unsigned PD constraint while building network

Parameters

enabled

inline NeuralNetworkBuilder setRuntimeCheckOption (final NeuralNetwork.RuntimeCheckOption runtimeCheckOption)

Sets a runtimeCheck option that is used for runtime availability check

Parameters

runtimeCheckOption – runtime available check option

inline NeuralNetworkBuilder setUseUserSuppliedBuffers(boolean enabled)

Sets whether this network will perform inference with input from user-supplied buffers.

Parameters

enabled

inline NeuralNetworkBuilder setInitCacheEnabled(boolean isInitCacheEnabled, String cacheTag, Context context)

Enable/disable the functionality of init caching. Init caching creates a set of init caches during network building/initialization process and adds them to DLC container. If such DLC container is saved by the user, in subsequent network building/initialization processes these init caches will be loaded from the DLC so as to reduce initialization time.

Parameters
  • isInitCacheEnabled – enables/disables the functionality of init caching.

  • cacheTag – The init caches are saved into a location under this tag name.

  • context – The android context from which the network is created.

Returns

The current instance of NeuralNetworkBuilder.

inline NeuralNetworkBuilder setCpuFixedPointMode(boolean fxpMode)

Sets the fixed point execution of a quantized DLC on CPU runtime. If a floating point DLC is executed with this option set, the execution will be in floating point mode in CPU. If a quantized DLC is executed without this option set, the execution will be in floating point mode in CPU.

Parameters

cpuFxpMode – Boolean If set to true, enables the fixed point mode.

Returns

The current instance of NeuralNetworkBuilder.

inline NeuralNetworkBuilder setUnconsumedTensorsOutput(boolean unconsumedTensorsOutput)

Sets unconsumed tensors as output option.

Parameters

UnconsumedTensorAsOutput – Boolean If set to true, enables unconsumed tensors as output.

Returns

The current instance of NeuralNetworkBuilder.

inline NeuralNetworkBuilder setStorageDirectory(String storageDirectory)

Set the SNPE storage location for all SNPE instances in this process. This may only be called once, and if so must be called before creating any SNPE instances

Parameters

Absolute – path to a directory which SNPE may use for caching and other storage purposes.

Returns

The current instance of NeuralNetworkBuilder.

inline NeuralNetwork build()

Builds a NeuralNetwork instance based on this builder’s configuration.

Returns

New network instance.

inline boolean isRuntimeSupported (final NeuralNetwork.Runtime runtime)
class ModelNotSet : public RuntimeException