// make pixel indexes 0-based
bbox_elem = [float(b - 1) for b in bbox_elem]
name = obj.find("name").text.lower().strip()
bbox_elem += [self.labels.index(name)]
bbox.append(bbox_elem)
bbox = np.stack(bbox).astype(np.float32)
After Change
anno = ET.parse(
os.path.join(self.data_dir, "Annotations", id_ + ".xml"))
bbox = []
label = []
for obj in anno.findall("object"):
// when in not using difficult mode, and the object is
// difficult, skipt it.
if not self.use_difficult and int(obj.find("difficult").text) == 1:
continue
bndbox_anno = obj.find("bndbox")
bbox_elem = [int(bndbox_anno.find("xmin").text),
int(bndbox_anno.find("ymin").text),
int(bndbox_anno.find("xmax").text),
int(bndbox_anno.find("ymax").text)]
// make pixel indexes 0-based
bbox_elem = [float(b - 1) for b in bbox_elem]
name = obj.find("name").text.lower().strip()
label.append(self.labels.index(name))
bbox.append(bbox_elem)
bbox = np.stack(bbox).astype(np.float32)
label = np.stack(label).astype(np.int32)
// Load a image
img_file = os.path.join(self.data_dir, "JPEGImages", id_ + ".jpg")
img = read_image_as_array(img_file) // RGB