dogs_vs_cats classification with alexNet and HDF5 DataSetGenerator

29 Views Asked by At

I am new to the machin learning coding.i am trying to run the code to classify if the image is for dog or cat using google colab notebook but i am getting error. i am asking if anyone has find the solution of this issue.

i want to classify dogs ans cats images using tensorflow and keras on colab notebook. here is the code

"# set the matplotlib backend so figures can be saved in the background
import matplotlib
matplotlib.use("Agg")

from keras.preprocessing.image import ImageDataGenerator
from keras.optimizers import Adam`your text`
import json
import os

# construct the training image generator for data augmentation
aug = ImageDataGenerator(rotation_range = 20, zoom_range = 0.15,width_shift_range = 0.2, 
                     height_shift_range = 0.2, shear_range = 0.15,horizontal_flip = True,       fill_mode = "nearest")

# load the RGB means for the training set
means = json.loads(open("dogs_vs_cats_mean.json").read())

# initialize the image preprocessors
sp = ImageResize(227, 227)
pp = PatchPreprocessor(227, 227)
mp = MeanPreprocessor(means["R"], means["G"], means["B"])
iap = ImageToArrayPreprocessor()

# initialize the training and validation dataset generators

trainGen = HDF5DatasetGenerator("/content/train.hdf5", 128, aug = aug,preprocessors = [pp, mp,  iap], classes = 2)
valGen = HDF5DatasetGenerator("/content/val.hdf5", 128,preprocessors = [sp, mp, iap], classes = 2)

# initialize the optimizer
print("[INFO] compiling model...")
opt = Adam(lr = 1e-3)
model = AlexNet.build(width = 227, height = 227, depth = 3, classes = 2, reg = 0.0002)
model.compile(loss = "binary_crossentropy", optimizer = opt, metrics = ["accuracy"],  run_eagerly=True)

#model.compile(optimizer="adam", loss="mean_squared_error", metrics=["acc"], run_eagerly=True)

# construct the set of callbacks
path = os.path.sep.join([OUTPUT_PATH, "{}.png".format(os.getpid())])
callbacks = [TrainingMonitor(path)]

# train the network
model.fit_generator(trainGen.generator(),steps_per_epoch = trainGen.numImages // 128,
                validation_data = valGen.generator(),validation_steps = valGen.numImages // 128,
                epochs =1,max_queue_size = 10,callbacks = callbacks, verbose = 1)"

but when i compile my code, i get this message error :

ValueError: Unexpected result of train_function (Empty logs). This could be due to issues in input pipeline that resulted in an empty dataset. Otherwise, please use Model.compile(..., run_eagerly=True), or tf.config.run_functions_eagerly(True) for more information of where went wrong, or file a issue/bug to tf.keras.

0

There are 0 best solutions below