Created
November 21, 2018 13:16
-
-
Save ianfhunter/1e5f7deae299954a73becb07af4462bb to your computer and use it in GitHub Desktop.
Verify a directory has valid images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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