Image - an image processing library based upon Vix

FYR…
I recently encountered prediction problem. When trying to predict some urls, it doesn’t return anything. Upon consulting with @kip it has to do with top_k: 1. But the latest version image version 0.28.2 fixed the issue.

I’m just sharing my experience here. So if anyone came across the issue then should know what to do as well.

This code wasn’t working

    image_data = %HTTPoison.Response{body: body} = HTTPoison.get!(image_url)
    my_image = image_data.body
    classify(my_image)

@kip suggestion:

%HTTPoison.Response{body: image_data} = HTTPoison.get!(image_url)
{:ok, image} = Image.from_binary(image_data)
predictions = Image.Classification.classify(image)

Which basically fixed my problem.

iex> Image.Classification.classify(image)                                                                        
%{
  predictions: [
    %{label: "toyshop", score: 0.3621242344379425},
    %{label: "shopping basket", score: 0.1781061440706253},
    %{label: "hamper", score: 0.07665970921516418},
    %{label: "rubber eraser, rubber, pencil eraser", score: 0.06588040292263031},
    %{label: "carton", score: 0.04808710142970085}
  ]
}

# To get only the labels from the prediction
iex> Image.Classification.labels(image, min_score: 0.01)
["toyshop", "shopping basket", "hamper", "rubber eraser", "rubber",
 "pencil eraser", "carton"]
iex> Image.Classification.labels(image, min_score: 0.05)
["toyshop", "shopping basket", "hamper", "rubber eraser", "rubber",
 "pencil eraser"]
iex> Image.Classification.labels(image, min_score: 0.1) 
["toyshop", "shopping basket"]

Thanks to @kip for the help.

1 Like