Created
September 15, 2023 11:53
-
-
Save gbildson/df3c24db0f4e03b366319ef82bc58bd9 to your computer and use it in GitHub Desktop.
Scan a directory of images to ensure that they are not corrupt for training purposes. Can swap load_image to your local version.
This file contains 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 os | |
import argparse | |
import tensorflow as tf | |
parser = argparse.ArgumentParser() | |
parser.add_argument("-d", "--directory", dest='directory', required=True, help="the base directory for training data") | |
args = parser.parse_args() | |
directory = args.directory | |
# iterate over files in | |
# that directory | |
for filename in os.listdir(directory): | |
f = os.path.join(directory, filename) | |
# checking if it is a file | |
if os.path.isfile(f): | |
try: | |
img = tf.keras.utils.load_img(f, target_size=(224, 224)) | |
except OSError as err: | |
print("file:", filename) | |
print("OS error:", err) | |
except Exception as err: | |
print("file:", f) | |
print("Unexpected: ",err, "type:", type(err)) | |
#img = image.load_img(img_path, target_size=(height, width)) | |
print('done') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment