From 54638bb5a2c3250f74a6329235edf7d0af3b2642 Mon Sep 17 00:00:00 2001 From: Cristo Zhang <39552438+WikChang@users.noreply.github.com> Date: Fri, 7 Jul 2023 21:26:12 +0800 Subject: [PATCH] Update search.py ## Bug Fix: IndexError in mim command We recently identified and fixed a bug that caused an `IndexError: list index out of range` exception when running the `mim download` command in Conda: ```shell mim download mmsegmentation --config pspnet_r50-d8_4xb2-40k_cityscapes-512x1024 --dest . ``` The issue occurred in `search.py` at line 339, where a check for `value[0]` being an instance of `dict` was being made without first confirming whether `value` was empty. This resulted in the following error: ```shell Traceback (most recent call): ... File "C:\Users\Enbla\anaconda3\envs\openmmlab\lib\site-packages\mim\commands\search.py", line 339, in _parse If isinstance(value[0], dict): IndexError: list index out of range ``` The fix involves adding an additional check to ensure `value` is not empty before checking if `value[0]` is a dictionary instance: ```python elif isinstance(value, (list, tuple)): If value and isinstance(value[0], dict): ``` Following this fix, re-running the `mim` command successfully installs the model: ```shell processing pspnet_r50-d8_4xb2-40k_cityscapes-512x1024... Download ---------------------------------------- 187.1/187.1 MiB 2.5 MB/s eta 0:00:00 Successfully downloaded pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth to C:\Windows\System32 Successfully dumped pspnet_r50-d8_4xb2-40k_cityscapes-512x1024.py to C:\Windows\System32. ``` We recommend users encountering this issue to update to the latest version where this bug has been addressed. --- mim/commands/search.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mim/commands/search.py b/mim/commands/search.py index e5a869e..f908602 100644 --- a/mim/commands/search.py +++ b/mim/commands/search.py @@ -336,7 +336,7 @@ def _parse(data: dict) -> dict: if isinstance(value, str): parsed_data[name] = cast2lowercase(value) elif isinstance(value, (list, tuple)): - if isinstance(value[0], dict): + if value and isinstance(value[0], dict): # inference time is a list of dict like List[dict] # each item of inference time represents the environment # where it is tested