diff --git a/roboflow/__init__.py b/roboflow/__init__.py index c2d52491..32d72a5e 100644 --- a/roboflow/__init__.py +++ b/roboflow/__init__.py @@ -15,7 +15,7 @@ from roboflow.models import CLIPModel, GazeModel # noqa: F401 from roboflow.util.general import write_line -__version__ = "1.2.0" +__version__ = "1.2.1" def check_key(api_key, model, notebook, num_retries=0): diff --git a/roboflow/util/image_utils.py b/roboflow/util/image_utils.py index 71a32824..63b3f81b 100644 --- a/roboflow/util/image_utils.py +++ b/roboflow/util/image_utils.py @@ -102,8 +102,11 @@ def load_labelmap(f): if f.lower().endswith(".yaml") or f.lower().endswith(".yml"): with open(f) as file: data = yaml.safe_load(file) - if "names" in data: - return {i: name for i, name in enumerate(data["names"])} + names = data.get("names", []) + if isinstance(names, dict): + return {int(k): v for k, v in names.items()} + else: + return {i: name for i, name in enumerate(names)} else: with open(f) as file: lines = [line for line in file.readlines() if line.strip()] diff --git a/tests/annotations/dict_names.yaml b/tests/annotations/dict_names.yaml new file mode 100644 index 00000000..e481edbc --- /dev/null +++ b/tests/annotations/dict_names.yaml @@ -0,0 +1,5 @@ +names: + 0: cat + 1: dog + 2: fish +nc: 3 diff --git a/tests/util/test_image_utils.py b/tests/util/test_image_utils.py index 5a17fe37..a229a455 100644 --- a/tests/util/test_image_utils.py +++ b/tests/util/test_image_utils.py @@ -2,7 +2,7 @@ import responses -from roboflow.util.image_utils import check_image_path, check_image_url +from roboflow.util.image_utils import check_image_path, check_image_url, load_labelmap class TestCheckImagePath(unittest.TestCase): @@ -33,3 +33,9 @@ def test_url_not_found(self): url = "https://example.com/notfound.png" responses.add(responses.HEAD, url, status=404) self.assertFalse(check_image_url(url)) + + +class TestLoadLabelmap(unittest.TestCase): + def test_yaml_dict_names(self): + labelmap = load_labelmap("tests/annotations/dict_names.yaml") + self.assertEqual(labelmap, {0: "cat", 1: "dog", 2: "fish"})