Skip to content

Commit f880bcc

Browse files
authored
Require pillow>=10.0.0, catch drise failure due to low mask_res or num_masks (#2181)
* pillow>=10, catch failure due to low mask_res or num_masks * add Pillow requirement that accommodates Python 3.7, flake8 fix * add quotes to requirements * try pinning pip * pip install without upgrade due to pin * remove pycocotools pin * install pycocotools using conda, remove pip pin * remove comment * pin pycocotools to automl required version
1 parent 29bfb51 commit f880bcc

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

.github/workflows/CI-responsibleai-text-vision-pytest.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ jobs:
8888
- if: ${{ (matrix.packageDirectory == 'responsibleai_vision') && ((matrix.pythonVersion == '3.7') || (matrix.pythonVersion == '3.8')) }}
8989
name: Install automl dependencies
9090
shell: bash -l {0}
91+
# pycocotools is a downstream dependency of automl requirements, but fails to install with pip
9192
run: |
93+
conda install pycocotools==2.0.4 -c conda-forge
9294
pip install -r ${{ matrix.packageDirectory }}/requirements-automl.txt
9395
9496
- name: Install package

responsibleai_vision/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
numpy>=1.17.2
22
pandas>=0.25.1,<2.0.0 # TODO: remove ceiling on version.
3+
Pillow>=10.0.0; python_version>"3.7" # due to breaking changes in v10.0.0 (https://pillow.readthedocs.io/en/latest/releasenotes/10.0.0.html)
4+
Pillow<10.0.0; python_version<="3.7" # Pillow v10.0.0 is only available starting with Python 3.8
35
scikit-learn>=0.22.1
46
scipy>=1.4.1
57
semver~=2.13.0

responsibleai_vision/responsibleai_vision/managers/explainer_manager.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -266,14 +266,23 @@ def compute_single_explanation(self,
266266
# get_drise_saliency_map only recognizes GPU and CPU
267267
if device == Device.AUTO.value:
268268
device = None
269-
fl, _, _, = get_drise_saliency_map(img,
270-
self._model,
271-
len(self._classes),
272-
savename=str(index),
273-
nummasks=self._num_masks,
274-
maskres=mask_res_tuple,
275-
devicechoice=device,
276-
max_figures=5000)
269+
try:
270+
fl, _, _, = get_drise_saliency_map(
271+
img,
272+
self._model,
273+
len(self._classes),
274+
savename=str(index),
275+
nummasks=self._num_masks,
276+
maskres=mask_res_tuple,
277+
devicechoice=device,
278+
max_figures=5000)
279+
except ValueError as ve:
280+
if str(ve) == 'No detections found':
281+
raise UserConfigValidationException(
282+
"No detections found in image. "
283+
"Please increase num_masks or mask_res.")
284+
else:
285+
raise ve
277286
if object_index is None:
278287
return fl
279288
b64_string = fl[object_index]
@@ -577,11 +586,13 @@ def _is_object_detection_task(self):
577586
return self._task_type == ModelTask.OBJECT_DETECTION
578587

579588
def _get_fail_str(self):
580-
fail = Image.new('RGB', (100, 100))
589+
fail = Image.new('RGB', (250, 250))
581590
draw = ImageDraw.Draw(fail)
582591
font = ImageFont.load_default()
583592
text = "saliency map could not be created"
584-
textwidth, textheight = draw.textsize(text, font)
593+
left, top, right, bottom = draw.textbbox((0, 0), text, font)
594+
textwidth = right - left
595+
textheight = bottom - top
585596
x = (fail.width - textwidth) // 2
586597
y = (fail.height - textheight) // 2
587598
draw.text((x, y), text, fill="white", font=font)

0 commit comments

Comments
 (0)