SSCMEx.Engine (sscmex v0.3.6)

Copy Markdown

SSCMA-Micro EngineCVI wrapper.

The engine is automatically garbage collected when no longer referenced.

Summary

Functions

Get input tensor as map with binary data.

Get input tensor index by name.

Get input quantization parameters.

Get input tensor shape as list of integers.

Returns the number of input tensors.

Get output tensor as map with binary data.

Get output tensor index by name.

Get output quantization parameters.

Get output tensor shape as list of integers.

Returns the number of output tensors.

Loads a model from file path.

Creates and initializes a new CVI engine.

Run inference (blocking, uses dirty CPU scheduler).

Set input tensor data from binary.

Types

resource()

@type resource() :: reference()

t()

@type t() :: %SSCMEx.Engine{resource: resource()}

Functions

get_input(engine, index)

@spec get_input(t(), non_neg_integer()) :: {:ok, map()} | {:error, term()}

Get input tensor as map with binary data.

Returns a map with keys:

  • :shape - tensor shape as list of integers
  • :type - tensor type atom (:u8, :s8, :f32, etc.)
  • :size - tensor size in bytes
  • :quant_param - quantization parameters map with :scale and :zero_point
  • :data - tensor data as binary
  • :name - tensor name string
  • :is_physical - boolean atom (:true or :false)

get_input_num(engine, name)

@spec get_input_num(t(), String.t()) :: {:ok, integer()} | {:error, term()}

Get input tensor index by name.

Returns the index of the input tensor with the given name.

get_input_quant_param(engine, index)

@spec get_input_quant_param(t(), non_neg_integer()) :: {:ok, map()} | {:error, term()}

Get input quantization parameters.

Returns a map with :scale (float) and :zero_point (integer).

get_input_shape(engine, index)

@spec get_input_shape(t(), non_neg_integer()) :: {:ok, [integer()]} | {:error, term()}

Get input tensor shape as list of integers.

get_input_size(engine)

@spec get_input_size(t()) :: {:ok, non_neg_integer()} | {:error, term()}

Returns the number of input tensors.

get_output(engine, index)

@spec get_output(t(), non_neg_integer()) :: {:ok, map()} | {:error, term()}

Get output tensor as map with binary data.

See get_input/2 for return format.

get_output_num(engine, name)

@spec get_output_num(t(), String.t()) :: {:ok, integer()} | {:error, term()}

Get output tensor index by name.

Returns the index of the output tensor with the given name.

get_output_quant_param(engine, index)

@spec get_output_quant_param(t(), non_neg_integer()) ::
  {:ok, map()} | {:error, term()}

Get output quantization parameters.

Returns a map with :scale (float) and :zero_point (integer).

get_output_shape(engine, index)

@spec get_output_shape(t(), non_neg_integer()) ::
  {:ok, [integer()]} | {:error, term()}

Get output tensor shape as list of integers.

get_output_size(engine)

@spec get_output_size(t()) :: {:ok, non_neg_integer()} | {:error, term()}

Returns the number of output tensors.

load(engine, path)

@spec load(t(), String.t()) :: :ok | {:error, term()}

Loads a model from file path.

Examples

:ok = SSCMEx.Engine.load(engine, "/path/to/model.cvimodel")

new()

@spec new() :: {:ok, t()} | {:error, term()}

Creates and initializes a new CVI engine.

Examples

{:ok, engine} = SSCMEx.Engine.new()

run(engine)

@spec run(t()) :: :ok | {:error, term()}

Run inference (blocking, uses dirty CPU scheduler).

After calling this function, output tensors will contain the inference results.

set_input(engine, index, data)

@spec set_input(t(), non_neg_integer(), binary()) :: :ok | {:error, term()}

Set input tensor data from binary.

The binary size must match the expected tensor size exactly.