View Source Image.Classification (image v0.18.1)
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
@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
image
is anyVix.Vips.Image.t/0
.backend
is any validNx
backend. The default isNx.default_backend/0
.
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}]}
@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
image
is anyVix.Vips.Image.t/0
.options
is a keyword list of options.
options
Options
:backend
is any validNx
backend. The default isNx.default_backend/0
.:min_score
is the minimum score, a float between0
and1
, 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"]