I have trained CNNs using PyTorch, and I am trying to run a train loop on a simple CNN in Flux for binary (cat/dog) classification, but I cannot for the life of me figure out how to get the loss functions to work in Flux. I have looked around and copied what others did, but to no avail. It has to be something in the way I am using DataLoader, I just know it. But it could also be a collection of issues, so I am going to link the GitHub repo. The images are loading in properly, so I don’t think it’s that, but it could be how I am manipulating and treating them within the code.
MethodError: no method matching loss(::NamedTuple{(:images, :labels),
Tuple{Vector{Matrix{Gray{Float64}}},
Vector{Flux.OneHotArray{UInt32, 2, 0, 1, UInt32}}}})
Closest candidates are:
loss(::Any, ::Any) at In[19]:2
Since the error says that it is trying to call loss on a (named)tuple, I would just change the definition of loss function from loss(x, y) = Flux.Losses.logitcrossentropy(model(x), y)
to loss((x, y)) = Flux.Losses.logitcrossentropy(model(x), y)