From a688a0d359171d17706a28bb236f802374df956f Mon Sep 17 00:00:00 2001 From: light1003 Date: Mon, 29 Jul 2019 11:10:31 +0800 Subject: [PATCH 1/2] Update example.py xmin,ymin,xmax,ymax should not be type of int ,it may cause int/int to 0,and xmin==xmax,ymin==ymax will cause kmean "Box has no area" error. --- example.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/example.py b/example.py index 0f8a4d1..cee7e1b 100644 --- a/example.py +++ b/example.py @@ -17,10 +17,13 @@ def load_dataset(path): 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 + 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 {}".format(xml_file)) + continue dataset.append([xmax - xmin, ymax - ymin]) @@ -33,4 +36,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))) \ No newline at end of file +print("Ratios:\n {}".format(sorted(ratios))) From 530c18eeca2b91fb1ef1f75f3b6ef52e220ac47e Mon Sep 17 00:00:00 2001 From: Vinicio Valbuena Date: Wed, 21 Apr 2021 23:30:25 +0200 Subject: [PATCH 2/2] add num obj --- example.py | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/example.py b/example.py index cee7e1b..3bf4c73 100644 --- a/example.py +++ b/example.py @@ -9,25 +9,27 @@ CLUSTERS = 5 def load_dataset(path): - 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")) - - for obj in tree.iter("object"): - 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 {}".format(xml_file)) - continue - - dataset.append([xmax - xmin, ymax - ymin]) - - return np.array(dataset) + 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")) + + 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]) + + return np.array(dataset) data = load_dataset(ANNOTATIONS_PATH)