Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix case of missing label in Forest Damage dataset #499

Merged
merged 2 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
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
Binary file modified tests/data/forestdamage/Data_Set_Larch_Casebearer.zip
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<annotation><filename>B01_0004.xml</filename><size><width>32</width><height>32</height><depth>3</depth></size><object><damage>other</damage><bndbox><xmin>8</xmin><ymin>8</ymin><xmax>24</xmax><ymax>24</ymax></bndbox></object></annotation>
<annotation><filename>B01_0004.xml</filename><size><width>32</width><height>32</height><depth>3</depth></size><object><damage>other</damage><bndbox><xmin>8</xmin><ymin>8</ymin><xmax>24</xmax><ymax>24</ymax></bndbox></object><object><bndbox><xmin>8</xmin><ymin>8</ymin><xmax>24</xmax><ymax>24</ymax></bndbox></object></annotation>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<annotation><filename>B01_0005.xml</filename><size><width>32</width><height>32</height><depth>3</depth></size><object><damage>other</damage><bndbox><xmin>8</xmin><ymin>8</ymin><xmax>24</xmax><ymax>24</ymax></bndbox></object></annotation>
<annotation><filename>B01_0005.xml</filename><size><width>32</width><height>32</height><depth>3</depth></size><object><damage>other</damage><bndbox><xmin>8</xmin><ymin>8</ymin><xmax>24</xmax><ymax>24</ymax></bndbox></object><object><bndbox><xmin>8</xmin><ymin>8</ymin><xmax>24</xmax><ymax>24</ymax></bndbox></object></annotation>
17 changes: 10 additions & 7 deletions tests/data/forestdamage/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"Bebehojd_20190527/Annotations/B01_0004.xml",
"Bebehojd_20190527/Annotations/B01_0005.xml",
],
"labels": [True, False],
}


Expand All @@ -38,15 +39,17 @@ def create_annotation(path: str) -> None:
ET.SubElement(size, "height").text = str(SIZE)
ET.SubElement(size, "depth").text = str(3)

annotation = ET.SubElement(root, "object")
for label in PATHS["labels"]:
annotation = ET.SubElement(root, "object")

ET.SubElement(annotation, "damage").text = "other"
if label:
ET.SubElement(annotation, "damage").text = "other"

bbox = ET.SubElement(annotation, "bndbox")
ET.SubElement(bbox, "xmin").text = str(0 + int(SIZE / 4))
ET.SubElement(bbox, "ymin").text = str(0 + int(SIZE / 4))
ET.SubElement(bbox, "xmax").text = str(SIZE - int(SIZE / 4))
ET.SubElement(bbox, "ymax").text = str(SIZE - int(SIZE / 4))
bbox = ET.SubElement(annotation, "bndbox")
ET.SubElement(bbox, "xmin").text = str(0 + int(SIZE / 4))
ET.SubElement(bbox, "ymin").text = str(0 + int(SIZE / 4))
ET.SubElement(bbox, "xmax").text = str(SIZE - int(SIZE / 4))
ET.SubElement(bbox, "ymax").text = str(SIZE - int(SIZE / 4))

tree = ET.ElementTree(root)
tree.write(path)
Expand Down
2 changes: 1 addition & 1 deletion tests/datasets/test_forestdamage.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def dataset(self, monkeypatch: MonkeyPatch, tmp_path: Path) -> ForestDamage:

url = os.path.join(data_dir, "Data_Set_Larch_Casebearer.zip")

md5 = "a6adc19879c1021cc1ba8d424e19c9e0"
md5 = "52d82ac38899e6e6bb40aacda643ee15"

monkeypatch.setattr(ForestDamage, "url", url)
monkeypatch.setattr(ForestDamage, "md5", md5)
Expand Down
7 changes: 6 additions & 1 deletion torchgeo/datasets/forestdamage.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ def parse_pascal_voc(path: str) -> Dict[str, Any]:
int(bndbox.find("xmax").text), # type: ignore[union-attr, arg-type]
int(bndbox.find("ymax").text), # type: ignore[union-attr, arg-type]
]
label = obj.find("damage").text # type: ignore[union-attr]

label_var = obj.find("damage")
if label_var is not None:
label = label_var.text
else:
label = "other"
bboxes.append(bbox)
labels.append(label)
return dict(filename=filename, bboxes=bboxes, labels=labels)
Expand Down