Why using pre-resized images gives same training speed as resizing them 'on the fly'?

I had an experiment where I use same images but with 2 different sizes.
First case 800x600 jpegs that are resized to 600x600 with item_tfms = [Resize(600)]
Second case 600x600 jpegs with same transforms item_tfms = [Resize(600)]

I’ve expected training speed to be less in second case but surprisingly not! I’m really confused how this could happen? How can I get this CPU operation for free?

Additionally I’ve used very simple GPU transformations batch_tfms = [*aug_transforms(), Normalize.from_stats(*imagenet_stats)]

Any ideas?

What is the size of your dataset? Sometimes the difference won’t be noticaeble if you have small dataset due to overheads such as initializing new device, moving data to GPU, etc.

Dataset is relatively big: 20+k images

could you post the full code you used for this experiment?

It isn’t so easy here because of lots of dependancies and etc. May be one can share some general ideas: should one be faster? If yes - what I can miss in my code so that both experiments took same time?

Even if the size is the same, you’re still always going to call fastai’s internal CropPad transform (if you check the Resize source code you’ll notice it does this). If they’re already the same size then just don’t resize for your proper test, much like how we didn’t in the CAMVID example.

There are ways you can speed up the resize transform, such as potentially using libjpeg-turbo and pillow-simd

Can you please share CAMVID example that is mentioned above? And I’m also interested if there any good examples of using libjpeg-turbo and pillow-simd with fastai?

Hi, did you try to run profiler, say, line-profiler?
If some ops (say, resize), takes, say 1% of time, we will not see improvement… Compare profiles…

Hope, that’ll be useful

1 Like

Just install them. It’s an inplace replacement for pillow. Docs: https://fastai1.fast.ai/performance.html

Camvid: https://github.com/fastai/fastai/blob/master/dev_nbs/course/lesson3-camvid.ipynb