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

**URL:** https://discourse.julialang.org/t/loading-images-is-very-slow-is-there-a-work-around/30529
**Category:** Performance
**Tags:** question, images
**Created:** [October 31, 2019, 9:08am UTC](https://discourse.julialang.org/t/loading-images-is-very-slow-is-there-a-work-around/30529 "2019-10-31T09:08:49Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![onetonfoot](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/onetonfoot/32/2697_2.png) [@onetonfoot](https://discourse.julialang.org/u/onetonfoot)
#### Post date: [October 31, 2019, 9:08am UTC](https://discourse.julialang.org/t/loading-images-is-very-slow-is-there-a-work-around/30529/1 "2019-10-31T09:08:49Z")

</div>

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

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

```

Vs

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

```

Since there seems to be some [issues](https://github.com/JuliaImages/Images.jl/issues/743) in this area, I was wondering if there is a common work around?

I’m running Ubuntu and Julia 1.10.

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [October 31, 2019, 9:58am UTC](https://discourse.julialang.org/t/loading-images-is-very-slow-is-there-a-work-around/30529/2 "2019-10-31T09:58:41Z")

</div>

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

---

<div class="post-metadata">

### Author: ![onetonfoot](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/onetonfoot/32/2697_2.png) [@onetonfoot](https://discourse.julialang.org/u/onetonfoot)
#### Post date: [October 31, 2019, 10:06am UTC](https://discourse.julialang.org/t/loading-images-is-very-slow-is-there-a-work-around/30529/3 "2019-10-31T10:06:04Z")

</div>

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

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

np.array(Image.open(path))
# 470 ms ± 14.6 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

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

```
