alibi-detect
alibi-detect copied to clipboard
Alternatives to `opencv` (`cv2`)
opencv
is a fairly heavy dependency and requires building (see recent CI failures), but we only use it in one place for making image perturbations (https://github.com/SeldonIO/alibi-detect/blob/master/alibi_detect/utils/perturbation.py). We should either explore replacing it with another library that's lighter (potentially scikit-image) or make it an optional dependency.
Another suggestion is to not make it a required dependency and start recommending opencv-python-headless
as alternative for opencv-python
. Much better in docker images.
Pull Request #853
Just created a pull request to solve this issue.
- Replaced OpenCV's GaussianBlur and filter2D with their counterparts from SciPy.
- Substituted OpenCV's affineTransform and warp functions with the corresponding functionalities from scikit-image.
- OpenCV is now an optional library with cv2 import dynamically handled within perturbations.py (for future-proofing and people (system/environment) with OpenCV can leverage its functionality too).
PS: I implemented every alternative (known to me) using scipy, scikit-image, custom numpy convolution, etc., and compared the results using Mean Squared Error (MSE) and Structural Similarity Index (SSI). If anyone is interested in those comparisons, let me know I'll put the notebook somewhere online.