View Source Image.Classification (image v0.18.0)

Implements image classification functions using Axon machine learning models managed by Bumblebee.

Image classification refers to the task of extracting information from an image. In this module, the information extracted is one or more labels desribing the image. Typically something like "sports car" or "Blenheim spaniel". The labels returns depend on the machine learning model used.

configuration

Configuration

The machine learning model to be used is configured as follows:

config :image,
  classification_model: model
  classification_featurizer: featurizer

where model and featurizer are models that are represented in a manner acceptable to Bumblebee. The default for both model and featurizer is {:hf, "microsoft/resnet-50"}.

Link to this section Summary

Functions

Classify an image using a machine learning model.

Classify an image using a machine learning model and return the labels that meet a minimum score.

Link to this section Functions

Link to this function

classify(image, backend \\ Nx.default_backend())

View Source (since 0.18.0)
@spec classify(image :: Vix.Vips.Image.t(), backend :: Nx.Backend.t()) ::
  %{predictions: [%{label: String.t(), score: float()}]}
  | {:error, Image.error_message()}

Classify an image using a machine learning model.

arguments

Arguments

returns

Returns

  • A map containing the estimations of the image classification.

examples

Examples

iex> puppy = Image.open!("./test/support/images/puppy.webp") iex> Image.Classification.classify(puppy) %{predictions: [%{label: "Blenheim spaniel", score: 0.9701485633850098}]}

Link to this function

labels(image, options \\ [])

View Source (since 0.18.0)
@spec labels(image :: Vix.Vips.Image.t(), options :: Keyword.t()) ::
  [String.t()] | {:error, Image.error_message()}

Classify an image using a machine learning model and return the labels that meet a minimum score.

arguments

Arguments

options

Options

  • :backend is any valid Nx backend. The default is Nx.default_backend/0.

  • :min_score is the minimum score, a float between 0 and 1, which a label must match in order to be returned.

returns

Returns

  • A list of labels. The list may be empty if there are no predictions that exceed the :min_score.

  • {:error, reason}

examples

Examples

iex> {:ok, image} = Image.open ("./test/support/images/lamborghini-forsennato-concept.jpg")
iex> Image.Classification.labels(image)
["sports car", "sport car"]