

The subdirectories class_a and class_b, together with labelsĠ and 1 (0 corresponding to class_a and 1 corresponding to class_b). Will return a tf.data.Dataset that yields batches of images from Then calling image_dataset_from_directory(main_directory, labels='inferred') Output = model.predict(np.Main_directory /. # for your model you have to do the preparation just the same as in the case of learning process # here data is in the format which is accepted by, in this case, my model

# gray scale is the 1st channel in the Lab color spaceĬolor_me = rgb2lab((1.0 / 255) * color_me)Ĭolor_me = color_me.reshape(color_me.shape + (1,)) # here you prepare the input data, for example here we take the gray image One final step if you want to save it to a csv file, arrange it in a dataframe with the image names appended with the class predicted. Where by class numbers will be replaced by the class names. Predictions = for k in predicted_class_indices] Next step is I want the name of the classes: labels = (train_generator.class_indices) Predicted_class_indices=np.argmax(pred,axis=1) In my case it was 4 classes, so class numbers were 0,1,2 and 3.
#KERAS DATA GENERATOR CODE#
Running the above code will give output in probabilities so at first I need to convert them to class number. Pred=cnn.predict_generator(test_generator,verbose=1,steps=306/batch_size) Then ran the following code: test_generator = test_datagen.flow_from_directory(Īnd most importantly you've to write the following code: So in my case I made another folder inside test folder and named it all_classes. So first of all the test images should be placed inside a separate folder inside the test folder. I have googled a lot, searched on Kaggle Kernels also but haven't been able to get a solution. So how can I predict on my new images using Keras. Img_tensor = np.expand_dims(img_tensor, axis=0)īut I get this error: Permission denied: 'D:\\Datasets\\Trell\\imagesīut I haven't been able to predict_generator on my test images. I have also used this following code: img = image.load_img(pred_dir, target_size=(28, 28)) So in my test folder I have around 300 images, on which I want to predict and make a dataframe, like this: image_name class 4 specific classes, validation also stored in same way and works out pretty well. My train data is basically stored in 4 separate folders, i.e.

#KERAS DATA GENERATOR HOW TO#
predict_generator I get:ġ) Keras: How to use predict_generator with ImageDataGenerator? This didn't work out, because its trying on validation set only.Ģ) How to predict the new image by using model.predict? module image not foundģ) How to get predictions with predict_generator on streaming test data in Keras? This also didn't work out. Now I have some new images in a test folder (all images are inside the same folder only), on which I want to predict. This is my model training code: history = cnn.fit_generator( Validation_generator = test_datagen.flow_from_directory( Train_generator = train_datagen.flow_from_directory( Test_datagen = ImageDataGenerator(rescale=1. ImageGenerator Code: img_width, img_height = 28, 28 Pred_dir = Path('D:/Datasets/Trell/images/new_images/testing') Test_dir = Path('D:/Datasets/Trell/images/new_images/validation') These are my directories: train_dir = Path('D:/Datasets/Trell/images/new_images/training') I've used ImageDataGenerator and flow_from_directory for training and validation.
