# Machine Learning in Elixir: comments on chapter 11, version B 3.0

**URL:** <https://forum.devtalk.com/t/machine-learning-in-elixir-comments-on-chapter-11-version-b-3-0/146857>\
**Category:** PragProg Customers\
**Tags:** book-machine-learning-in-elixir, errata\
**Created:** [10 March 2024 10:57 UTC](https://forum.devtalk.com/t/machine-learning-in-elixir-comments-on-chapter-11-version-b-3-0/146857 "2024-03-10T10:57:08Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![jshprentz](https://forum.devtalk.com/user_avatar/forum.devtalk.com/jshprentz/32/5389_2.png) [@jshprentz](https://forum.devtalk.com/u/jshprentz)\
**Post date:** [18 April 2024 23:31 UTC](https://forum.devtalk.com/t/machine-learning-in-elixir-comments-on-chapter-11-version-b-3-0/146857/2 "2024-04-18T23:31:13Z")

</div>

@seanmor5

As Piet reported, the code on page 260 fails at

```elixir
    image
    |> Nx.from_binary(:u8)

```

Based on the example at [Examples — Bumblebee v0.5.3](https://hexdocs.pm/bumblebee/examples.html#image-classification), I replaced the `image` line with this pipeline:

```elixir
    image.file_ref
    |> Kino.Input.file_path()
    |> File.read!()

```

Now the Run button successfully ingests the image, runs the model, and reports the top predictions. The `serving = ...` code on page 259 contained the option `top_k: 1`, so only one prediction is shown. After changing `1` to `5` and uploading the book’s cat image, the five predictions match those shown on page 261, albeit with different probabilities.

Here is the complete modified code from page 260:

```elixir
image_input = Kino.Input.image("Image", size: {224, 224})
form = Kino.Control.form([image: image_input], submit: "Run")
frame = Kino.Frame.new()

form
|> Kino.Control.stream()
|> Stream.filter(& &1.data.image)
|> Kino.listen(fn %{data: %{image: image}} ->
  Kino.Frame.render(frame, Kino.Markdown.new("Running..."))

  image =
    image.file_ref
    |> Kino.Input.file_path()
    |> File.read!()
    |> Nx.from_binary(:u8)
    |> Nx.reshape({image.height, image.width, 3})

  output = Nx.Serving.run(serving, image)

  output.predictions
  |> Enum.map(&{&1.label, &1.score})
  |> Kino.Bumblebee.ScoredList.new()
  |> then(&Kino.Frame.render(frame, &1))
end)

Kino.Layout.grid([form, frame], boxed: true, gap: 16)

```

---

_[View the full topic](https://forum.devtalk.com/t/machine-learning-in-elixir-comments-on-chapter-11-version-b-3-0/146857)._
