I am quite new to tensorflow, I would like to clearly know, what does the below command do?
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
import os
num_skipped = 0
for folder_name in ("Cat", "Dog"):
print("folder_name:",folder_name) #folder_name: Cat
folder_path = os.path.join("Dataset/PetImages", folder_name)
print("folder_path:",folder_path) #folder_path: Dataset/PetImages/Cat
for fname in os.listdir(folder_path):
print("fname:",fname) #fname: 5961.jpg
fpath = os.path.join(folder_path, fname)
print("fpath:", fpath) #fpath: Dataset/PetImages/Cat/10591.jpg
try:
fobj = open(fpath, "rb")
is_jfif = tf.compat.as_bytes("JFIF") in fobj.peek(10)
finally:
fobj.close()
if not is_jfif:
num_skipped += 1
# Delete corrupted image
os.remove(fpath)
print("Deleted %d images" % num_skipped)
Keras Website comment on the above code :
When working with lots of real-world image data, corrupted images are a common occurence. Let's filter out badly-encoded images that do not feature the string "JFIF" in their header.
I want to specifically know what does the below command do, how does it do ?
is_jfif = tf.compat.as_bytes("JFIF") in fobj.peek(10)
I checked the API but wasn't clearly able to understand it.
A better explanation will be of much help.
Thanks
