You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Results of Buffered transformations are overwritten by the next call, which corrupts batches in collating loaders #148
The result of apply with a Buffered or BufferedThreadsafe transformation is the buffer itself, which the next call overwrites (documented on the Buffering page). A data loader that stacks the observations of a batch only after loading all of them, like DataLoader(...; collate = true) from MLUtils.jl, then receives the same array for every sample. The batch contains the last sample repeated, without any error or warning.
using DataAugmentation, Images, MLUtils
images = [fill(Gray{Float32}(i), 16, 16) for i in1:64] # sample i has the value i
labels =collect(1:64)
tfm =CenterCrop((8, 8)) |>PinOrigin() |>ImageToTensor()
btfm =BufferedThreadsafe(tfm; n = Threads.maxthreadid()) # n avoids #143
data =mapobs(((img, y),) -> (itemdata(apply(btfm, Image(img))), y), (images, labels))
wrong =0for (x, y) inDataLoader(data; batchsize =16, collate =true)
wrong +=count(j -> x[1, 1, 1, j] != y[j], 1:length(y))
end
wrong # 60 of the 64 samples
parallel = true gives the same result, and wrapping the buffered result in copy gives 0 wrong samples. Julia 1.13.4, DataAugmentation master (e389a2f), MLUtils 0.4.16.
Add an option to Buffered, for example Buffered(tfm; copy = true), that reuses the buffers of the intermediate steps and returns a copy of the final result.
On the value of buffering with a loader: in one quick benchmark (256×256 images, RandomResizeCrop((224, 224)), brightness, ImageToTensor, Normalize; a sequential loop over the samples), BufferedThreadsafe plus copy took 1.07 ms per sample against 1.02 ms without buffering, while allocating 599 KiB instead of 1510 KiB. So the saving is in allocations, not in time, at least for this pipeline.
Activity
Return owned copies from buffered transforms and drop the `threadid()…