Skip to content

Instantly share code, notes, and snippets.

@ianfhunter
Created November 21, 2018 13:16
Show Gist options
  • Select an option

  • Save ianfhunter/1e5f7deae299954a73becb07af4462bb to your computer and use it in GitHub Desktop.

Select an option

Save ianfhunter/1e5f7deae299954a73becb07af4462bb to your computer and use it in GitHub Desktop.
Verify a directory has valid images
import glob
from PIL import Image
root_dir = "/Imagenet/"
for filename in glob.iglob(root_dir + '**/*.*', recursive=True):
try:
i = Image.open(filename)
except:
print(filename, "cant be opened")
continue
try:
i.verify()
except:
print("invalid image: ", filename)
i.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment