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

Fixed three issues: 1. PIL failed to parse truncated files; 2. Illega… #1533

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
23 changes: 15 additions & 8 deletions examples/bbox_detection/labelme2voc.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

import imgviz

from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True

import labelme

try:
Expand Down Expand Up @@ -77,17 +80,17 @@ def main():

maker = lxml.builder.ElementMaker()
xml = maker.annotation(
maker.folder(),
maker.folder("VOC"),
maker.filename(base + ".jpg"),
maker.database(), # e.g., The VOC2007 Database
maker.annotation(), # e.g., Pascal VOC2007
maker.image(), # e.g., flickr
maker.database("Unknown"), # e.g., The VOC2007 Database
maker.annotation("Unknown"), # e.g., Pascal VOC2007
maker.image("Unknown"), # e.g., flickr
maker.size(
maker.height(str(img.shape[0])),
maker.width(str(img.shape[1])),
maker.depth(str(img.shape[2])),
),
maker.segmented(),
maker.segmented("0"),
)

bboxes = []
Expand All @@ -102,6 +105,10 @@ def main():
continue

class_name = shape["label"]
if class_name not in class_names:
print(f"ignore class {class_name}")
continue

class_id = class_names.index(class_name)

(xmin, ymin), (xmax, ymax) = shape["points"]
Expand All @@ -115,9 +122,9 @@ def main():
xml.append(
maker.object(
maker.name(shape["label"]),
maker.pose(),
maker.truncated(),
maker.difficult(),
maker.pose("Unspecified"),
maker.truncated("0"),
maker.difficult("0"),
maker.bndbox(
maker.xmin(str(xmin)),
maker.ymin(str(ymin)),
Expand Down