Loading Images is very slow, is there a work around?

Loading images seems to be very slow? Comparing my Julia code to Python

using BenchmarkTools, FileIO
path = "/home/dom/Pictures/sd1/jpegs/DSCF0201.jpg"
@btime load(path);
#  1.890 s (245 allocations: 206.01 MiB)


from PIL import Image
path = "/home/dom/Pictures/sd1/jpegs/DSCF0201.jpg"
# In a seperate notebook cell
# 907 µs ± 25.3 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)

Since there seems to be some issues in this area, I was wondering if there is a common work around?

I’m running Ubuntu and Julia 1.10.

I wonder if Python load just open a handler, Julia load seems to actually read the file (allocation 200MB?)

I think your right, since when converting to a numpy array or torch tensor the time difference is a lot less.

from torchvision.transforms.functional import to_tensor
import numpy as np

# 470 ms ± 14.6 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

# 582 ms ± 13.2 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)