You can use batch transforms outside of loading loop (it is probably much faster too).



 fnak:

img_pil = preprocess(img_pil)


I wonder if redefining img_pil inside with loop is causing this issue for the PIL library.