Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,27 @@
CLUSTERS = 5

def load_dataset(path):
dataset = []
for xml_file in glob.glob("{}/*xml".format(path)):
tree = ET.parse(xml_file)
dataset = []
for xml_file in glob.glob("{}/*xml".format(path)):
tree = ET.parse(xml_file)

height = int(tree.findtext("./size/height"))
width = int(tree.findtext("./size/width"))
height = int(tree.findtext("./size/height"))
width = int(tree.findtext("./size/width"))

for obj in tree.iter("object"):
xmin = int(obj.findtext("bndbox/xmin")) / width
ymin = int(obj.findtext("bndbox/ymin")) / height
xmax = int(obj.findtext("bndbox/xmax")) / width
ymax = int(obj.findtext("bndbox/ymax")) / height
i = 0
for obj in tree.iter("object"):
i += 1
xmin = int(obj.findtext("bndbox/xmin"))*1.0 / width
ymin = int(obj.findtext("bndbox/ymin"))*1.0 / height
xmax = int(obj.findtext("bndbox/xmax"))*1.0 / width
ymax = int(obj.findtext("bndbox/ymax"))*1.0 / height
if xmin==xmax or ymin==ymax:
print("you need to check obj[{}] {}".format(i, xml_file))
continue

dataset.append([xmax - xmin, ymax - ymin])
dataset.append([xmax - xmin, ymax - ymin])

return np.array(dataset)
return np.array(dataset)


data = load_dataset(ANNOTATIONS_PATH)
Expand All @@ -33,4 +38,4 @@ def load_dataset(path):
print("Boxes:\n {}".format(out))

ratios = np.around(out[:, 0] / out[:, 1], decimals=2).tolist()
print("Ratios:\n {}".format(sorted(ratios)))
print("Ratios:\n {}".format(sorted(ratios)))