Detectron 2中的类标签输出是指什么?

4
detectron2的文档中,它指出类标签位于output_dict['Instances'].pred_classes。这很好理解,并且我可以轻松访问它,但在文档(或输出字典)中似乎没有指定哪个整数标签对应哪个类别。 我假设某处有一个包含类别和整数标签的字典,例如 {0:'人',1:'自行车',2:'汽车',...},但我无法找到它。有人知道在哪里可以找到吗?
以下是输出字典的规格: https://detectron2.readthedocs.io/tutorials/models.html
3个回答

4
数据集元数据类具有一个属性thing_classes,其中包含该数据集的类名称列表。仅通过从pred_classes传递类ID,即可获取类名称,代码如下所示:此处
pred_classes = output_dict['instances'].pred_classes.cpu().tolist()
class_names = MetadataCatalog.get("mydataset").thing_classes
pred_class_names = list(map(lambda x: class_names[x], pred_classes))

2
你可以在这里找到它:

https://gist.github.com/AruniRC/7b3dadd004da04c80198557db5da4bda

请注意,模型输出的值是此字典中的键+1。
{0: u'__background__',
 1: u'person',
 2: u'bicycle',
 3: u'car',
 4: u'motorcycle',
 5: u'airplane',
 6: u'bus',
 7: u'train',
 8: u'truck',
 9: u'boat',
 10: u'traffic light',
 11: u'fire hydrant',
 12: u'stop sign',
 13: u'parking meter',
 14: u'bench',
 15: u'bird',
 16: u'cat',
 17: u'dog',
 18: u'horse',
 19: u'sheep',
 20: u'cow',
 21: u'elephant',
 22: u'bear',
 23: u'zebra',
 24: u'giraffe',
 25: u'backpack',
 26: u'umbrella',
 27: u'handbag',
 28: u'tie',
 29: u'suitcase',
 30: u'frisbee',
 31: u'skis',
 32: u'snowboard',
 33: u'sports ball',
 34: u'kite',
 35: u'baseball bat',
 36: u'baseball glove',
 37: u'skateboard',
 38: u'surfboard',
 39: u'tennis racket',
 40: u'bottle',
 41: u'wine glass',
 42: u'cup',
 43: u'fork',
 44: u'knife',
 45: u'spoon',
 46: u'bowl',
 47: u'banana',
 48: u'apple',
 49: u'sandwich',
 50: u'orange',
 51: u'broccoli',
 52: u'carrot',
 53: u'hot dog',
 54: u'pizza',
 55: u'donut',
 56: u'cake',
 57: u'chair',
 58: u'couch',
 59: u'potted plant',
 60: u'bed',
 61: u'dining table',
 62: u'toilet',
 63: u'tv',
 64: u'laptop',
 65: u'mouse',
 66: u'remote',
 67: u'keyboard',
 68: u'cell phone',
 69: u'microwave',
 70: u'oven',
 71: u'toaster',
 72: u'sink',
 73: u'refrigerator',
 74: u'book',
 75: u'clock',
 76: u'vase',
 77: u'scissors',
 78: u'teddy bear',
 79: u'hair drier',
 80: u'toothbrush'}

0

如果您要使用Detectron2,请使用链接将类别复制并存储为字典(在此情况下为className)

如果您想获取默认Detectron2模型的类别,请使用以下代码

instances = outputs["instances"]
detected_class_indexes = instances.pred_classes.tolist()
print(detected_class_indexes)
pred_class_names = list(map(lambda x: className[x+1], detected_class_indexes))
print(pred_class_names)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接