参考程序pascal_voc.py中_load_pascal_annotation函数用来读取标注信息,gt_roidb用于保存或读取pkl文件。
单个文件的标注信息提取流程详见如下程序。
import os
import scipy
import numpy as np
import xml.etree.ElementTree as ET
_classes = ('__background__',
'car', 'bus', 'truck')
num_classes = len(_classes)
_class_to_ind = dict(list(zip(_classes, list(range(num_classes)))))
_data_path = 'data/cars' #Annocations的所在目录
def load_pascal_annotation(index):
"""
Load image and bounding boxes info from XML file in the PASCAL VOC
format.
"""
filename = os.path.join(_data_path, 'Annotations', index + '.xml')
tree = ET.parse(filename)
objs = tree.findall('object')
# Load object bounding boxes into a data frame.