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

Continue on error in dataset_tool.py #39

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
18 changes: 15 additions & 3 deletions dataset_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@ def iterate_images():
for idx, fname in enumerate(input_images):
arch_fname = os.path.relpath(fname, source_dir)
arch_fname = arch_fname.replace('\\', '/')
img = np.array(PIL.Image.open(fname))
yield dict(img=img, label=labels.get(arch_fname))
try:
img = np.array(PIL.Image.open(fname))
except Exception as e:
sys.stderr.write(f'Failed to read {fname}: {e}\n')
continue
yield dict(img=img, label=labels.get(arch_fname), fname=fname)
if idx >= max_idx-1:
break
return max_idx, iterate_images()
Expand Down Expand Up @@ -409,7 +413,15 @@ def convert_dataset(
archive_fname = f'{idx_str[:5]}/img{idx_str}.png'

# Apply crop and resize.
img = transform_image(image['img'])
try:
img = transform_image(image['img'])
except Exception as e:
if "fname" in image:
error_msg = f'Failed to process image {image["fname"]}: {e}'
else:
error_msg = f'Failed to process image at index {idx}: {e}'
sys.stderr.write(error_msg + '\n')
continue

# Transform may drop images.
if img is None:
Expand Down