keras-preprocessing
keras-preprocessing copied to clipboard
[pre-pull-request] opencv version (PIL alternative) for image.py
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?
I agree with you, I am already loading my images with cv2.. Why not putting this into keras ; )
- 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.
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.