Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Classification

livebooks/vix/classification.livemd

Classification

Mix.install(
  [
    {:image, "~> 0.54"},
    {:bumblebee, "~> 0.5"},
    {:exla, "~> 0.9"},
    {:kino, "~> 0.14"}
  ],
  config: [nx: [default_backend: EXLA.Backend]]
)

Prepare image

puppies_img = Image.open!("/home/livebook/vix/puppies.png")

Classify image

Image.Classification.labels(puppies_img)
puppies_img
|> Image.Classification.classify()
|> Map.get(:predictions)
|> Kino.DataTable.new()
{_, classifier} = Image.Classification.classifier()
serving = Keyword.get(classifier, :serving)
serving
|> Nx.Serving.run(Image.to_nx!(puppies_img))
|> Map.get(:predictions)
|> Kino.DataTable.new()
{_, classifier} = Image.Classification.classifier(
  model: {:hf, "google/vit-base-patch16-224"},
  featurizer:  {:hf, "google/vit-base-patch16-224"}
)

serving = Keyword.get(classifier, :serving)

serving
|> Nx.Serving.run(Image.to_nx!(puppies_img))
|> Map.get(:predictions)
|> Kino.DataTable.new()