美文网首页
python获取voc标注数据集中类别及数量

python获取voc标注数据集中类别及数量

作者: 卡拉肖克_潘 | 来源:发表于2020-06-16 10:41 被阅读0次
    # coding:utf-8
    import xml.etree.cElementTree as ET
    import os
    from collections import Counter
    def count(pathdir):
        category = []
        path = pathdir + '/XML/'
        for index,xml in enumerate(os.listdir(path)):
            print(str(index) + ' xml: '+ xml)
            root = ET.parse(os.path.join(path, xml))
            objects = root.findall('object')
            category += [ob.find('name').text for ob in objects]
        print(Counter(category))
        total_num = sum([value for key, value in Counter(category).items()])
        print('total_num:',total_num)
     
    if __name__ == '__main__':
        pathdir = 'D:\\WorkSpace\\pythonWorkspace\\annotations\\'
        count(pathdir,despath)
    

    相关文章

      网友评论

          本文标题:python获取voc标注数据集中类别及数量

          本文链接:https://www.haomeiwen.com/subject/cuelxktx.html