generate_tfrecord.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:unsupervised-2017-cvprw 作者: imatge-upc 项目源码 文件源码
def _parse_annotation_xml(filepath):
    tree = et.parse(filepath)
    data = tree.getroot()[1]    # <data>
    for sf in data:             #     <sourcefile> ... find first non-empty sourcefile node
        if len(list(sf)) != 0:
            break
    file = sf[0]                #         <file>
    objs = sf[1:]               #         <object> ...

    num_objs   = len(objs)
    num_frames = int(file.find("./*[@name='NUMFRAMES']/*[@value]").attrib['value'])
    parsed_bbx = np.zeros([num_frames, num_objs, 4])
    for i, obj in enumerate(objs):  # iterate <object> nodes
        loc = obj.find("./*[@name='Location']")
        for bbx in loc:
            span = re.findall(r'\d+', bbx.attrib['framespan'])
            beg, end = int(span[0]), int(span[1])
            h = int(bbx.attrib['height'])
            w = int(bbx.attrib['width'])
            x = int(bbx.attrib['x'])
            y = int(bbx.attrib['y'])
            parsed_bbx[beg-1:end, i] = [h, w, x, y]

    return parsed_bbx
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号