View Source ExVision.Model.Definition.Ortex behaviour (Ex Vision v0.4.0)

A generic implementation of the ExVision.Model.Definition for Ortex based models.

Summary

Types

A type describing all options possible to use with the default implementation of the load/0 function.

A type describing ONNX provider that can be used with ExVision.

Callbacks

A callback used to apply postprocessing to the output of the ONNX model.

A callback used to apply preprocessing for your model.

Functions

Loads the ONNX model and attaches the Nx.Serving to callbacks defined in the module

Types

@type load_option_t() ::
  {:cache_path, Path.t()}
  | {:providers, [provider_t()]}
  | {:batch_size, pos_integer()}

A type describing all options possible to use with the default implementation of the load/0 function.

  • :cache_path - specifies a caching directory for this model.
  • :providers - a list of desired providers, sorted by preference. Onnx will attempt to use the first available provider. If none of the provided is available, onnx will fallback to :cpu. Default: [:cpu]
  • :batch_size - specifies a default batch size for this instance. Default: 1.
@type provider_t() :: :cpu | :coreml | :cpu

A type describing ONNX provider that can be used with ExVision.

For some providers, it may be necessary to use the local version of libonnxruntime and provide some configuration option. For details, please consult Ortex documentaiton

@type using_option_t() :: {:base_dir, Path.t()} | {:name, String.t()}

Callbacks

@callback postprocessing(map(), ExVision.Types.ImageMetadata.t()) ::
  ExVision.Model.output_t()

A callback used to apply postprocessing to the output of the ONNX model.

In this callback, you should transform the output to match your desired format.

@callback preprocessing(Nx.Tensor.t(), ExVision.Types.ImageMetadata.t()) :: Nx.Tensor.t()

A callback used to apply preprocessing for your model.

The requirements for that will differ depending on the model used.

Functions

Link to this function

load_ortex_model(module, model_path, options)

View Source
@spec load_ortex_model(module(), Path.t(), [load_option_t()]) ::
  {:ok, ExVision.Model.t()} | {:error, atom()}

Loads the ONNX model and attaches the Nx.Serving to callbacks defined in the module