MCPcopy Index your code
hub / github.com/tensorlayer/TensorLayer / convert_annotation

Function convert_annotation

tensorlayer/files/utils.py:1611–1658  ·  view source on GitHub ↗

Given VOC2012 XML Annotations, returns number of objects and info.

(file_name)

Source from the content-addressed store, hash-verified

1609 return x, y, w, h
1610
1611 def convert_annotation(file_name):
1612 """Given VOC2012 XML Annotations, returns number of objects and info."""
1613 in_file = open(file_name)
1614 out_file = ""
1615 tree = ET.parse(in_file)
1616 root = tree.getroot()
1617 size = root.find('size')
1618 w = int(size.find('width').text)
1619 h = int(size.find('height').text)
1620 n_objs = 0
1621
1622 for obj in root.iter('object'):
1623 if dataset != "2012test":
1624 difficult = obj.find('difficult').text
1625 cls = obj.find('name').text
1626 if cls not in classes or int(difficult) == 1:
1627 continue
1628 else:
1629 cls = obj.find('name').text
1630 if cls not in classes:
1631 continue
1632 cls_id = classes.index(cls)
1633 xmlbox = obj.find('bndbox')
1634 b = (
1635 float(xmlbox.find('xmin').text), float(xmlbox.find('xmax').text), float(xmlbox.find('ymin').text),
1636 float(xmlbox.find('ymax').text)
1637 )
1638 bb = convert((w, h), b)
1639
1640 out_file += str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n'
1641 n_objs += 1
1642 if cls in "person":
1643 for part in obj.iter('part'):
1644 cls = part.find('name').text
1645 if cls not in classes_in_person:
1646 continue
1647 cls_id = classes.index(cls)
1648 xmlbox = part.find('bndbox')
1649 b = (
1650 float(xmlbox.find('xmin').text), float(xmlbox.find('xmax').text),
1651 float(xmlbox.find('ymin').text), float(xmlbox.find('ymax').text)
1652 )
1653 bb = convert((w, h), b)
1654 # out_file.write(str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n')
1655 out_file += str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n'
1656 n_objs += 1
1657 in_file.close()
1658 return n_objs, out_file
1659
1660 logging.info("[VOC] Parsing xml annotations files")
1661 n_objs_list = []

Callers 1

load_voc_datasetFunction · 0.70

Calls 2

closeMethod · 0.80
convertFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…