【问题标题】:how to dump the object detection labels into the pickle?如何将对象检测标签转储到泡菜中?
【发布时间】:2020-04-15 08:48:17
【问题描述】:

我有如下对象检测的标签。

item{
    id: 1
    name: 'red_light'
}
item{
    id: 2
    name: 'blue_light'
}
item{
    id: 3
    name: 'blue_left'
}
item{
    id: 4
    name:'red_left'
}
{
    id: 5
    name: 'yellow_light'
}

使用 ssd moblienet v2 coco 中的标签,我将检测交通信号灯。如何为标签创建泡菜?当我加载泡菜数据时,它应该是这样的

{1:'red_light', 2:'blue_light', 3:'blue_left', 4:'red_left', 5:'yellow_light'}

我会很感激你的建议。

【问题讨论】:

    标签: object pickle detection


    【解决方案1】:

    坚持原来的标签格式并尝试转换它是不明智的。相反,只需输入所需的输出,如下所示。

    import argparse
    import pickle
    
    # construct the argument parse and parse the arguments
    ap = argparse.ArgumentParser()
    ap.add_argument("-l", "--labels", required=True,
        help="path to output labels file")
    args = vars(ap.parse_args())
    
    LABEL_ENCODINGS = {"red_light": 1, 
        "blue_light": 2, 
        "blue_left": 3, 
        "red_left": 4, 
        "yellow_light": 5, 
    }
    
    # reverse the label encoding dictionary
    labels = {v: k for (k, v) in LABEL_ENCODINGS.items()}
    
    # save the class labels to disk
    f = open(args["labels"], "wb")
    f.write(pickle.dumps(labels))
    f.close()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-06
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多