yunfengwang commited on
Commit
0551e23
·
verified ·
1 Parent(s): 2e15212

Upload utils/coco_categories.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. utils/coco_categories.py +35 -0
utils/coco_categories.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """COCO category mapping utilities."""
2
+
3
+ COCO_CATS = {
4
+ 1: "person", 2: "bicycle", 3: "car", 4: "motorcycle", 5: "airplane",
5
+ 6: "bus", 7: "train", 8: "truck", 9: "boat", 10: "traffic light",
6
+ 11: "fire hydrant", 13: "stop sign", 14: "parking meter", 15: "bench",
7
+ 16: "bird", 17: "cat", 18: "dog", 19: "horse", 20: "sheep",
8
+ 21: "cow", 22: "elephant", 23: "bear", 24: "zebra", 25: "giraffe",
9
+ 27: "backpack", 28: "umbrella", 31: "handbag", 32: "tie", 33: "suitcase",
10
+ 34: "frisbee", 35: "skis", 36: "snowboard", 37: "sports ball", 38: "kite",
11
+ 39: "baseball bat", 40: "baseball glove", 41: "skateboard", 42: "surfboard",
12
+ 43: "tennis racket", 44: "bottle", 46: "wine glass", 47: "cup", 48: "fork",
13
+ 49: "knife", 50: "spoon", 51: "bowl", 52: "banana", 53: "apple",
14
+ 54: "sandwich", 55: "orange", 56: "broccoli", 57: "carrot", 58: "hot dog",
15
+ 59: "pizza", 60: "donut", 61: "cake", 62: "chair", 63: "couch",
16
+ 64: "potted plant", 65: "bed", 67: "dining table", 70: "toilet", 72: "tv",
17
+ 73: "laptop", 74: "mouse", 75: "remote", 76: "keyboard", 77: "cell phone",
18
+ 78: "microwave", 79: "oven", 80: "toaster", 81: "sink", 82: "refrigerator",
19
+ 84: "book", 85: "clock", 86: "vase", 87: "scissors", 88: "teddy bear",
20
+ 89: "hair drier", 90: "toothbrush",
21
+ }
22
+
23
+
24
+ _SORTED_IDS = sorted(COCO_CATS.keys())
25
+ HF_COCO_CATS = {i: COCO_CATS[_SORTED_IDS[i]] for i in range(len(_SORTED_IDS))}
26
+
27
+
28
+ def get_category_name(label_id, default_prefix="object"):
29
+ """Get COCO category name from label id (standard or HuggingFace index)."""
30
+ label_id = int(label_id)
31
+ if label_id in COCO_CATS:
32
+ return COCO_CATS[label_id]
33
+ if label_id in HF_COCO_CATS:
34
+ return HF_COCO_CATS[label_id]
35
+ return f"{default_prefix}_{label_id}"