keras-preprocessing icon indicating copy to clipboard operation
keras-preprocessing copied to clipboard

[pre-pull-request] opencv version (PIL alternative) for image.py

Open DSLituiev opened this issue 6 years ago • 3 comments

I found that I need to rewrite load_img in image.py with opencv for my corner case of 16-bit images. Also benchmarks show that python-opencv is faster than PIL. Will there be interest in incorporating opencv/cv2-based reading function as an alternative to PIL into this package?

DSLituiev avatar Oct 11 '18 03:10 DSLituiev

I agree with you, I am already loading my images with cv2.. Why not putting this into keras ; )

easilar avatar Oct 11 '18 12:10 easilar

  • This would be a major breaking change for tons of applications.
  • This would be a pain for Windows users since they need Visual C++.
  • This is also a pretty big library just for loading images. I don't think we need a library as powerful as OpenCV just to load images.

As always, Keras values UX over performance, if you need to do something custom, just create a new class that inherits ImageDataGenerator.

NOTE: I do use OpenCV in my research.

Conclusion : I don't think we should switch PIL for cv2.

Dref360 avatar Oct 11 '18 13:10 Dref360

I see. Well, as I see now, PIL is loaded as an optional module. My proposition is to do same (optional dependency/loading) opencv, with a flag, like load_img(...,driver='pil' | 'opencv'), or a global switch preprocessing.image.DRIVER='pil' | 'opencv'.

Also I'm guessing many users have opencv already if they do any heavier processing/augmentation.

DSLituiev avatar Oct 11 '18 15:10 DSLituiev