
polmiro
Machine Learning in Elixir: Error in Chapter 9, identifying cats and dogs again
the code provided I am running into an error when training the first model that uses transfer learning with ONNX model mobilenetv2-7. I am a bit stuck here, not really sure what may be wrong.
warning: Axon.Optimizers.adam/1 is deprecated. Use Polaris.Optimizers.adam/1 instead
machine-learning-in-elixir-src/StopReinventingTheWheel.livemd#cell:s4yqqx5n4j6oyja2b2c57iqes4fvcbny:2
12:22:35.339 [warning] found unexpected key in the initial parameters map: "mobilenetv20_output_pred_fwd"
Epoch: 0, Batch: 700, accuracy: 0.7747430 loss: 0.4431267
Batch: 6, accuracy: 0.9151786 loss: 0.1636844
** (ArgumentError) argument at position 1 is not compatible with compiled function template.
{
<<<<< Expected <<<<<
#Nx.Tensor<
f32[32][channels: 3][height: 160][width: 160]
>
==========
#Nx.Tensor<
f32[26][channels: 3][height: 160][width: 160]
>
>>>>> Argument >>>>>
,
<<<<< Expected <<<<<
#Nx.Tensor<
s64[32][1]
>
==========
#Nx.Tensor<
s64[26][1]
>
>>>>> Argument >>>>>
}
(nx 0.6.2) lib/nx/defn.ex:323: anonymous fn/7 in Nx.Defn.compile_flatten/5
(elixir 1.15.2) lib/enum.ex:1819: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
(nx 0.6.2) lib/nx/lazy_container.ex:61: Nx.LazyContainer.Tuple.traverse/3
(nx 0.6.2) lib/nx/defn.ex:320: Nx.Defn.compile_flatten/5
(nx 0.6.2) lib/nx/defn.ex:312: anonymous fn/4 in Nx.Defn.compile/3
(stdlib 5.0.2) timer.erl:270: :timer.tc/2
(axon 0.6.0) lib/axon/loop.ex:1805: anonymous fn/4 in Axon.Loop.run_epoch/5
/data/machine-learning-in-elixir-src/StopReinventingTheWheel.livemd#cell:s4yqqx5n4j6oyja2b2c57iqes4fvcbny:10: (file)
Marked As Solved

joshprintsimple
The length of the val_paths has to be divisible by the batch number so that the tensors come out the right shape.
You can just add this line
val_paths = Enum.take(val_paths, 224)
after setting the val_paths. I also removed the Enum.take line at the end because the length of the train_paths is 24000 and that is also divisible by a batch size of 32.
so that cell would look like this now:
{test_paths, train_paths} =
Path.wildcard("train/*.jpg")
|> Enum.shuffle()
|> Enum.split(1000)
{test_paths, val_paths} = test_paths |> Enum.split(750)
val_paths = Enum.take(val_paths, 224)
batch_size = 32
target_height = 160
target_width = 160
train_pipeline =
CatsAndDogs.pipeline_with_augmentations(
train_paths,
batch_size,
target_height,
target_width
)
val_pipeline =
CatsAndDogs.pipeline(
val_paths,
batch_size,
target_height,
target_width
)
test_pipeline =
CatsAndDogs.pipeline(
test_paths,
batch_size,
target_height,
target_width
)
# Enum.take(train_pipeline, 1)
1
Popular Pragmatic Bookshelf topics

Hi everyone!
There is an error on the page 71 in the book “Programming machine learning from coding to depp learning” P. Perrotta. You c...
New

Title: Hands-On Rust (Chapter 11: prefab)
Just played a couple of amulet-less games. With a bit of debugging, I believe that your can_p...
New

Title: Web Development with Clojure, Third Edition, vB17.0 (p9)
The create table guestbook syntax suggested doesn’t seem to be accepted ...
New

I’m new to Rust and am using this book to learn more as well as to feed my interest in game dev. I’ve just finished the flappy dragon exa...
New

@noelrappin
Running the webpack dev server, I receive the following warning:
ERROR in tsconfig.json
TS18003: No inputs were found in c...
New

Hey there,
I’m enjoying this book and have learned a few things alredayd. However, in Chapter 4 I believe we are meant to see the “>...
New

Modern front-end development for Rails, second edition - Struggling to get the first chapter to work
After running /bin/setup, the first error was: The foreman' command exists in these Ruby versions: That was easy to fix: gem install fore...
New

When running the program in chapter 8, “Implementing Combat”, the printout Health before attack was never printed so I assumed something ...
New

Hello faithful readers! If you have tried to follow along in the book, you are asked to start up the dev environment via dx/build and ar...
New

Getting an error when installing the dependencies at the start of this chapter:
could not compile dependency :exla, "mix compile" failed...
New
Other popular topics

If it’s a mechanical keyboard, which switches do you have?
Would you recommend it? Why?
What will your next keyboard be?
Pics always w...
New

Any thoughts on Svelte?
Svelte is a radical new approach to building user interfaces. Whereas traditional frameworks like React and Vue...
New

No chair. I have a standing desk.
This post was split into a dedicated thread from our thread about chairs :slight_smile:
New

poll
poll
Be sure to check out @Dusty’s article posted here: An Introduction to Alternative Keyboard Layouts It’s one of the best write-...
New

Oh just spent so much time on this to discover now that RancherOS is in end of life but Rancher is refusing to mark the Github repo as su...
New

Continuing the discussion from Thinking about learning Crystal, let’s discuss - I was wondering which languages don’t GC - maybe we can c...
New

Hello everyone! This thread is to tell you about what authors from The Pragmatic Bookshelf are writing on Medium.
New

Hi folks,
I don’t know if I saw this here but, here’s a new programming language, called Roc
Reminds me a bit of Elm and thus Haskell. ...
New

We’ve talked about his book briefly here but it is quickly becoming obsolete - so he’s decided to create a series of 7 podcasts, the firs...
New

Develop, deploy, and debug BEAM applications using BEAMOps: a new paradigm that focuses on scalability, fault tolerance, and owning each ...
New
Categories:
Sub Categories:
Popular Portals
- /elixir
- /rust
- /ruby
- /wasm
- /erlang
- /phoenix
- /keyboards
- /rails
- /js
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /emacs
- /java
- /haskell
- /onivim
- /svelte
- /typescript
- /crystal
- /c-plus-plus
- /kotlin
- /tailwind
- /gleam
- /react
- /ocaml
- /elm
- /flutter
- /vscode
- /ash
- /opensuse
- /centos
- /php
- /deepseek
- /html
- /scala
- /zig
- /textmate
- /sublime-text
- /debian
- /nixos
- /lisp
- /agda
- /react-native
- /kubuntu
- /arch-linux
- /revery
- /ubuntu
- /django
- /spring
- /manjaro
- /diversity
- /lua
- /nodejs
- /julia
- /slackware
- /c
- /neovim