SeldonIO / alibi-detect

Algorithms for outlier, adversarial and drift detection
https://docs.seldon.io/projects/alibi-detect/en/stable/
Other
2.21k stars 220 forks source link

Alternatives to `opencv` (`cv2`) #532

Open jklaise opened 2 years ago

jklaise commented 2 years ago

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.

kkwekkeboom commented 1 year ago

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.

Dilip-Jain commented 11 months ago

Pull Request #853
Just created a pull request to solve this issue.

  1. Replaced OpenCV's GaussianBlur and filter2D with their counterparts from SciPy.
  2. Substituted OpenCV's affineTransform and warp functions with the corresponding functionalities from scikit-image.
  3. 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.