Skip to content

Commit

Permalink
Few mistakes in from_xml (#29)
Browse files Browse the repository at this point in the history
* handle images without object

* Update dataset.py

* Update dataset.py

correct few mistakes during iterations
  • Loading branch information
EtienneDavid authored and jsbroks committed Jan 22, 2020
1 parent eb493ff commit 92f1a11
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions imantics/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ def from_xml(cls, xml_folder, name="XML Dataset"):
for ext in extensions:
xml_list += list(xml_folder.glob(f"*.{ext}"))
categories = []
if "object" in xml["annotation"].keys():
if type(xml["annotation"]["object"]) is not list:
cat = xml["annotation"]["object"]["name"]["$"]
categories.append(cat)
else:
for ann in xml["annotation"]["object"]:
cat = ann["name"]["$"]
for idx, imgp in enumerate(xml_list):
xml = bf.data(fromstring(open(imgp.with_suffix(".xml"),"r").read()))
if "object" in xml["annotation"].keys():
if type(xml["annotation"]["object"]) is not list:
cat = xml["annotation"]["object"]["name"]["$"]
categories.append(cat)
else:
for ann in xml["annotation"]["object"]:
cat = ann["name"]["$"]
categories.append(cat)

categories = list(set(categories))

Expand All @@ -47,13 +49,13 @@ def from_xml(cls, xml_folder, name="XML Dataset"):
image.dataset = name



xml = bf.data(fromstring(open(imgp.with_suffix(".xml"),"r").read()))
if "object" in xml["annotation"].keys():

# Handle single object case
if type(xml["annotation"]["object"]) is not list:
xml["annotation"]["object"] = [xml["annotation"]["object"]]

for ann in xml["annotation"]["object"]:
i = ann["bndbox"]
cat = ann["name"]["$"]
Expand All @@ -63,10 +65,9 @@ def from_xml(cls, xml_folder, name="XML Dataset"):

fin_ann = Annotation(id=id_counter, image=image, bbox=bbox,category=xml_categories[cat])
id_counter += 1

image.add(fin_ann)

dataset.add(image)
dataset.add(image)
return dataset


Expand Down

0 comments on commit 92f1a11

Please sign in to comment.