If you’re memory-constrained, you may want to load and transform one image at a time, which prevents you from needing to hold all the input images and all the outputs in memory simultaneously. Broadcasting is often handy, but it’ll probably be easier to split this into multiple functions or use explicit loops to avoid those memory constraints.
Your example doesn’t make a ton of sense to me:
- loading
x
then never referencing it again - indexing into
img[1:50]
- where wasimg
defined? - doing
h=imresize(a,(240,240)
, but never referencingh
afterwards
It helps to make sure your example can be run as written by the person trying to assist you (see this note).
That said, I’ll make some guesses from your comments:
function load_data(path, N)
img_paths = readdir(path, join=true)
l = Matrix{Float32}[]
for img_path in 1:min(N, length(img_paths))
a = load(img_path)
h = imresize(a, (240,240))
push!(l, convert(Matrix{Float32}, a)
end
return l
end