We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Adding Non Unique Names To ClassMap Must Be Illegal
Currently, `add_name` doesn't check if the added `name` is a duplicate or not. This should be illegal, as classes must be unique

https://github.com/airctic/icevision/blob/82f3c7322d5adbc41d6a1b7b9e4327eb32ad23c4/icevision/core/class_map.py#L47-L51

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `icevision/core/class_map.py`
Content:
```
1 __all__ = ["ClassMap", "BACKGROUND"]
2 
3 from icevision.imports import *
4 
5 BACKGROUND = "background"
6 
7 
8 class ClassMap:
9     """Utility class for mapping between class name and id."""
10 
11     def __init__(
12         self,
13         classes: Optional[Sequence[str]] = None,
14         background: Optional[str] = BACKGROUND,
15     ):
16         self._lock = True
17 
18         self._id2class = copy(list(classes)) if classes else []
19         # insert background if required
20         self._background = background
21         if self._background is not None:
22             try:
23                 self._id2class.remove(self._background)
24             except ValueError:
25                 pass
26             # background is always index zero
27             self._id2class.insert(0, self._background)
28 
29         self._class2id = {name: i for i, name in enumerate(self._id2class)}
30 
31     @property
32     def num_classes(self):
33         return len(self)
34 
35     def get_by_id(self, id: int) -> str:
36         return self._id2class[id]
37 
38     def get_by_name(self, name: str) -> int:
39         try:
40             return self._class2id[name]
41         except KeyError as e:
42             if not self._lock:
43                 return self.add_name(name)
44             else:
45                 raise e
46 
47     def add_name(self, name) -> int:
48         self._id2class.append(name)
49         id = len(self._class2id)
50         self._class2id[name] = id
51         return id
52 
53     def lock(self):
54         self._lock = True
55         return self
56 
57     def unlock(self):
58         self._lock = False
59         return self
60 
61     def __eq__(self, other) -> bool:
62         if isinstance(other, ClassMap):
63             return self.__dict__ == other.__dict__
64         return False
65 
66     def __len__(self):
67         return len(self._id2class)
68 
69     def __repr__(self):
70         return f"<ClassMap: {self._class2id.__repr__()}>"
71
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/icevision/core/class_map.py b/icevision/core/class_map.py
--- a/icevision/core/class_map.py
+++ b/icevision/core/class_map.py
@@ -44,7 +44,13 @@
             else:
                 raise e
 
-    def add_name(self, name) -> int:
+    def add_name(self, name: str) -> int:
+        # Raise error if trying to add duplicate value
+        if name in self._id2class:
+            raise ValueError(
+                f"'{name}' already exists in the ClassMap. You can only add new labels that are unique"
+            )
+
         self._id2class.append(name)
         id = len(self._class2id)
         self._class2id[name] = id

{"golden_diff": "diff --git a/icevision/core/class_map.py b/icevision/core/class_map.py\n--- a/icevision/core/class_map.py\n+++ b/icevision/core/class_map.py\n@@ -44,7 +44,13 @@\n             else:\n                 raise e\n \n-    def add_name(self, name) -> int:\n+    def add_name(self, name: str) -> int:\n+        # Raise error if trying to add duplicate value\n+        if name in self._id2class:\n+            raise ValueError(\n+                f\"'{name}' already exists in the ClassMap. You can only add new labels that are unique\"\n+            )\n+\n         self._id2class.append(name)\n         id = len(self._class2id)\n         self._class2id[name] = id\n", "issue": "Adding Non Unique Names To ClassMap Must Be Illegal\nCurrently, `add_name` doesn't check if the added `name` is a duplicate or not. This should be illegal, as classes must be unique\r\n\r\nhttps://github.com/airctic/icevision/blob/82f3c7322d5adbc41d6a1b7b9e4327eb32ad23c4/icevision/core/class_map.py#L47-L51\n", "before_files": [{"content": "__all__ = [\"ClassMap\", \"BACKGROUND\"]\n\nfrom icevision.imports import *\n\nBACKGROUND = \"background\"\n\n\nclass ClassMap:\n    \"\"\"Utility class for mapping between class name and id.\"\"\"\n\n    def __init__(\n        self,\n        classes: Optional[Sequence[str]] = None,\n        background: Optional[str] = BACKGROUND,\n    ):\n        self._lock = True\n\n        self._id2class = copy(list(classes)) if classes else []\n        # insert background if required\n        self._background = background\n        if self._background is not None:\n            try:\n                self._id2class.remove(self._background)\n            except ValueError:\n                pass\n            # background is always index zero\n            self._id2class.insert(0, self._background)\n\n        self._class2id = {name: i for i, name in enumerate(self._id2class)}\n\n    @property\n    def num_classes(self):\n        return len(self)\n\n    def get_by_id(self, id: int) -> str:\n        return self._id2class[id]\n\n    def get_by_name(self, name: str) -> int:\n        try:\n            return self._class2id[name]\n        except KeyError as e:\n            if not self._lock:\n                return self.add_name(name)\n            else:\n                raise e\n\n    def add_name(self, name) -> int:\n        self._id2class.append(name)\n        id = len(self._class2id)\n        self._class2id[name] = id\n        return id\n\n    def lock(self):\n        self._lock = True\n        return self\n\n    def unlock(self):\n        self._lock = False\n        return self\n\n    def __eq__(self, other) -> bool:\n        if isinstance(other, ClassMap):\n            return self.__dict__ == other.__dict__\n        return False\n\n    def __len__(self):\n        return len(self._id2class)\n\n    def __repr__(self):\n        return f\"<ClassMap: {self._class2id.__repr__()}>\"\n", "path": "icevision/core/class_map.py"}], "after_files": [{"content": "__all__ = [\"ClassMap\", \"BACKGROUND\"]\n\nfrom icevision.imports import *\n\nBACKGROUND = \"background\"\n\n\nclass ClassMap:\n    \"\"\"Utility class for mapping between class name and id.\"\"\"\n\n    def __init__(\n        self,\n        classes: Optional[Sequence[str]] = None,\n        background: Optional[str] = BACKGROUND,\n    ):\n        self._lock = True\n\n        self._id2class = copy(list(classes)) if classes else []\n        # insert background if required\n        self._background = background\n        if self._background is not None:\n            try:\n                self._id2class.remove(self._background)\n            except ValueError:\n                pass\n            # background is always index zero\n            self._id2class.insert(0, self._background)\n\n        self._class2id = {name: i for i, name in enumerate(self._id2class)}\n\n    @property\n    def num_classes(self):\n        return len(self)\n\n    def get_by_id(self, id: int) -> str:\n        return self._id2class[id]\n\n    def get_by_name(self, name: str) -> int:\n        try:\n            return self._class2id[name]\n        except KeyError as e:\n            if not self._lock:\n                return self.add_name(name)\n            else:\n                raise e\n\n    def add_name(self, name: str) -> int:\n        # Raise error if trying to add duplicate value\n        if name in self._id2class:\n            raise ValueError(\n                f\"'{name}' already exists in the ClassMap. You can only add new labels that are unique\"\n            )\n\n        self._id2class.append(name)\n        id = len(self._class2id)\n        self._class2id[name] = id\n        return id\n\n    def lock(self):\n        self._lock = True\n        return self\n\n    def unlock(self):\n        self._lock = False\n        return self\n\n    def __eq__(self, other) -> bool:\n        if isinstance(other, ClassMap):\n            return self.__dict__ == other.__dict__\n        return False\n\n    def __len__(self):\n        return len(self._id2class)\n\n    def __repr__(self):\n        return f\"<ClassMap: {self._class2id.__repr__()}>\"\n", "path": "icevision/core/class_map.py"}]}