-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v0.4.0 introduced error for DataLoader which collates images #139
Comments
Here's a MWE: using Images
using StatsBase: sample, shuffle
using DataAugmentation
using Flux
using TestImages
import Base: length, getindex
import Flux.MLUtils: getobs, getobs!
const im_size = (224, 224)
imgs = ["chelsea", "coffee"]
struct ImageContainer{T<:Vector}
img::T
end
length(data::ImageContainer) = length(data.img)
tfm_train = DataAugmentation.compose(ScaleKeepAspect(im_size))
function getobs(data::ImageContainer, idx::Int)
path = data.img[idx]
# img = Images.load(path)
img = testimage(path)
img = apply(tfm_train, Image(img))
img = itemdata(img)
# img = permutedims(channelview(RGB.(itemdata(img))), (3, 2, 1))
return img
end
data = ImageContainer(imgs)
deval1 = Flux.DataLoader(data, batchsize=2, collate = true, partial = false) Incuding the line Although this may look at first glance as an Images' related issue, I think it is more tied to @lorenzoh, would you have a take on this one? |
(CatDogPanda) pkg> st
Project CatDogPanda v0.1.0
Status `C:\github\CatDogPanda\Project.toml`
[336ed68f] CSV v0.10.9
[052768ef] CUDA v3.12.1
[88a5189c] DataAugmentation v0.2.11
[587475ba] Flux v0.13.11
[916415d5] Images v0.25.2
[2913bbd2] StatsBase v0.33.21
[5e47fb64] TestImages v1.7.1 |
These axes represent images the same size, with offset indices:
I presume the previous version ignored offsets & made an Julia 1.9's Flux won't work at all on arrays with offset indices. So there's some chance MLUtils should always remove them? |
I think you're having the right diagnosis. path = imgs[1]
_img = testimage(path)
_img = apply(tfm_train, Image(_img))
size(_img.data)
img = channelview(float32.(_img.data))
julia> typeof(img)
Base.ReinterpretArray{Float32, 3, RGB{Float32}, OffsetArrays.OffsetMatrix{RGB{Float32}, Matrix{RGB{Float32}}}, true} Then, on this reinterpreted julia> Array(img)
ERROR: DimensionMismatch: axes must agree, got (Base.OneTo(3), Base.OneTo(224), Base.OneTo(224)) and (Base.OneTo(3), OffsetArrays.IdOffsetRange(values=2:225, indices=2:225), OffsetArrays.IdOffsetRange(values=59:282, indices=59:282)) Hover, The above is with Julia 1.8.4. In short, using tfm_train = DataAugmentation.compose(ScaleKeepAspect(im_size), CenterCrop(im_size))
function getobs(data::ImageContainer, idx::Int)
path = data.img[idx]
_img = testimage(path)
_img = apply(tfm_train, Image(_img))
img = collect(channelview(float32.(itemdata(_img))))
return img
end A caveat from the |
Update from v0.3.1 to v0.4.0 resulted in a failure on a data loader:
Strangely, the message about the axes sizes seems legitimate.
The error message appears to come from https://github.com/JuliaLang/Compat.jl/blob/295c146528063385a0d89bc2be12a7f534052d82/src/Compat.jl#L610, which itself is called by
_dim_stack
: https://github.com/JuliaLang/julia/blob/de73c26fbff61d07a38c9653525b530a56630831/base/abstractarray.jl#L2847The error can be reproduced with following script: https://github.com/jeremiedb/ImageNetTrain.jl/blob/main/experiments/loaders/test-loader-min.jl
Although it assumes imagenet data is available. I'll provide a more minimal reproducible example in case the above details don't already hint to the issue that came with v0.4.
It may tied to #119, though I wasn't clear whether or how the Loader for images would no longer be properly defined for MLUtils.
The text was updated successfully, but these errors were encountered: