View Source TFLiteElixir.ImageClassification (tflite_elixir v1.0.0)

Experimental image classification module.

Summary

Functions

Returns a specification to start this module under a supervisor.

Run the model against an image.

Give the classifier its labels, either as a list or as the path to a file holding one label per line.

Give the classifier its labels from a file the model itself carries.

Start a classifier for model, a path to a .tflite file or its contents.

Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

predict(pid, input_path, opts \\ [])

View Source
@spec predict(
  pid(),
  binary()
  | %StbImage{data: term(), shape: term(), type: term()}
  | %Nx.Tensor{
      data: term(),
      names: term(),
      shape: term(),
      type: term(),
      vectorized_axes: term()
    },
  Keyword.t()
) :: term()

Run the model against an image.

Options

  • :timeout - how long to wait for the answer, in milliseconds, or :infinity. Defaults to 30000. Raise it for a large model or a slow board; inference is local and bounded, so waiting is the right answer more often than giving up.
Link to this function

set_label(pid, label_file)

View Source
@spec set_label(pid(), String.t() | [String.t()]) :: :ok

Give the classifier its labels, either as a list or as the path to a file holding one label per line.

Results carry an index until this is set; afterwards they carry the label.

Link to this function

set_label_from_associated_file(pid, associated_filename)

View Source
@spec set_label_from_associated_file(pid(), String.t()) :: :ok | {:error, String.t()}

Give the classifier its labels from a file the model itself carries.

TFLiteElixir.FlatBufferModel.list_associated_files/1 says what a model has.

Link to this function

start(model, opts \\ [])

View Source
@spec start(any(), any()) :: :ignore | {:error, any()} | {:ok, pid()}

Start a classifier for model, a path to a .tflite file or its contents.

Options, all optional: :top_k (1) how many results predict/3 returns, :threshold (0.0) the score below which a result is dropped, :mean (128.0) and :std (128.0) the input normalisation, :jobs (System.schedulers_online/0) the interpreter's thread count, :use_tpu (false) and :tpu ("") to run on a named Edge TPU.