Skip to content
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