**I'm trying to run this code below, where I'm getting an error 'file not found' **
I tried to check if I'm in right directory by using:
os.listdir('C:\\Users\\ruchi\\Desktop\\Car-Models-Classifier-master')
['.ipynb_checkpoints',
'bmw10_ims',
'cars_annos.mat',
'cars_test',
'cars_test_annos_withlabels.mat',
'cars_train',
'car_ims',
'car_models_classifier.ipynb',
'devkit',
'README.md']
This is the code which I'm trying to run for which I gave correct path still it shows file not found error.
**CODE:**
data_dir = '/Car-Models-Classifier-master'
train_dir = '/Car-Models-Classifier-master/cars_train'
valid_dir = data_dir + '/valid'
test_dir = '/Car-Models-Classifier-master/cars_test'
**# Training transform includes random rotation and flip to build a more robust model**
train_transforms = transforms.Compose([transforms.Resize((244,244)),
transforms.RandomRotation(30),
transforms.RandomHorizontalFlip(),
transforms.ToTensor(),
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])
**# The validation set will use the same transform as the test set**
test_transforms = transforms.Compose([transforms.Resize((244,244)),
transforms.CenterCrop(224),
transforms.ToTensor(),
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])
validation_transforms = transforms.Compose([transforms.Resize((244,244)),
transforms.CenterCrop(224),
transforms.ToTensor(),
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])
**# Load the datasets with ImageFolder**
train_data = datasets.ImageFolder(data_dir + '/Car-Models-Classifier-master/cars_train', transform=train_transforms)
test_data = datasets.ImageFolder(data_dir + '/Car-Models-Classifier-master/cars_test', transform=test_transforms)
#valid_data = datasets.ImageFolder(data_dir + '/valid', transform=validation_transforms)
**# Using the image datasets and the trainforms, define the dataloaders
# The trainloader will have shuffle=True so that the order of the images do not affect the model**
trainloader = torch.utils.data.DataLoader(train_data, batch_size=128, shuffle=True)
testloader = torch.utils.data.DataLoader(test_data, batch_size=32, shuffle=True)
validloader = torch.utils.data.DataLoader(valid_data, batch_size=32, shuffle=True)
This the error:
FileNotFoundError Traceback (most recent call last)
<ipython-input-16-fe5e781c7465> in <module>
20
21 # Load the datasets with ImageFolder
---> 22 train_data = datasets.ImageFolder(data_dir + '/Car-Models-Classifier-master/cars_train', transform=train_transforms)
23 test_data = datasets.ImageFolder(data_dir + '/Car-Models-Classifier-master/cars_test', transform=test_transforms)
24 #valid_data = datasets.ImageFolder(data_dir + '/valid', transform=validation_transforms)
Can someone help ? I'm not able to understand where I'm going wrong.
This
data_dir + '/Car-Models-Classifier-master/cars_train'
concatinates to
/Car-Models-Classifier-master/Car-Models-Classifier-master/cars_train
So the line must be
train_data = datasets.ImageFolder(data_dir + '/cars_train', transform=train_transforms)
Related
I'm developing a plants disease classification app using React and tensorflow.
To fill this job, I have developed an AI model with CNN and preprocessing layers.
the model works fine on google colab, but when I converted it to the JSON form to deploy it in my app it shows me this error on my browsers console:
Uncaught (in promise) Error: Unknown layer: RandomFlip. This may be due to one of the following reasons:
The layer is defined in Python, in which case it needs to be ported to TensorFlow.js or your JavaScript code.
The custom layer is defined in JavaScript, but is not registered properly with tf.serialization.registerClass().
this is my python code:
# -*- coding: utf-8 -*-
"""Copie de Untitled7.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1IFoiRxZ-FLnM-SIc6YfMtVooH2s-cMP4
"""
from google.colab import drive
drive.mount('/content/drive')
import zipfile
import os
zip_ref = zipfile.ZipFile('/content/drive/MyDrive/SoniaKarimDatasetPFA_Agriculture/archive.zip','r')
zip_ref.extractall('/content')
zip_ref.close()
len(os.listdir('/content'))
#importing necessary directories for analysis
import numpy as np
import tensorflow as tf
from tensorflow.keras import models, layers, callbacks
import matplotlib.pyplot as plt
!pip install split-folders
#Some additional parameters
#It is a good practice to declare these parameters
#outside of the functions also in a separate code block
directory = '/content/PlantVillage'
IMAGE_SIZE = 258
BATCH_SIZE = 32
CHANNELS = 3
EPOCHS = 3
import splitfolders
splitfolders.ratio(directory, output="output",
seed=1337, ratio=(.7,.3), group_prefix=None, move=False)
#Now, we gonna do the do! time to deal with
#our images!
#Let's call this tensorflow.keras function which will
#... you know!
dataset = tf.keras.preprocessing.image_dataset_from_directory(
"/content/output/val",
shuffle = True,
image_size = (IMAGE_SIZE,IMAGE_SIZE ),
batch_size = BATCH_SIZE
)
#dataset = dataset.take(int(len(dataset)*0.35))
class_names = dataset.class_names
class_names
len(dataset)
plt.figure(figsize=(10,10))
for image_batch, label_batch in dataset.take(1):
for i in range(12):
ax = plt.subplot(3,4,i+1)
plt.imshow(image_batch[i].numpy().astype('uint8'))
plt.title(class_names[label_batch[i]])
plt.axis('off')
#print(image_batch[0].shape)
#print(label_batch.numpy())
train_size = int(len(dataset)*0.8)
train_size
train_ds = dataset.take(train_size)
test_ds = dataset.skip(train_size)
validation_size = int(len(dataset)*0.1)
validation_ds = test_ds.take(validation_size)
test_ds = test_ds.skip(validation_size)
def get_dataset_partitions_tf(ds, train_split = 0.8,
val_split = 0.2,
test_split = 0.1,
shuffle = True,
shuffle_size = 10000):
ds_size = len(ds)
if shuffle:
ds = ds.shuffle(shuffle_size, seed = 12)
train_size = int(train_split * ds_size)
val_size = int (val_split * ds_size)
val_ds = ds.skip(train_size).take(val_size)
train_ds = ds.take(train_size)
test_ds = ds.skip(train_size).take(val_size)
return train_ds, val_ds, test_ds
train_ds, val_ds, test_ds = get_dataset_partitions_tf(dataset)
train_ds = train_ds.cache().shuffle(1000).prefetch(buffer_size = tf.data.AUTOTUNE)
val_ds = val_ds.cache().shuffle(1000).prefetch(buffer_size = tf.data.AUTOTUNE)
test_ds = test_ds.cache().shuffle(1000).prefetch(buffer_size = tf.data.AUTOTUNE)
data_augmentation = tf.keras.Sequential([
layers.experimental.preprocessing.RandomFlip('horizontal_and_vertical'),
layers.experimental.preprocessing.RandomRotation(0.2)
])
resize_and_rescale = tf.keras.Sequential([
layers.experimental.preprocessing.Resizing(IMAGE_SIZE, IMAGE_SIZE),
layers.experimental.preprocessing.Rescaling(1.0/255)
])
input_shape = (BATCH_SIZE, IMAGE_SIZE, IMAGE_SIZE, CHANNELS)
n_classes = 15
model = models.Sequential([
resize_and_rescale,
data_augmentation,
layers.Conv2D(32 , (3,3), input_shape = input_shape, activation='relu'),
layers.MaxPooling2D((2,2)),
layers.Conv2D(64 , (3,3), activation='relu'),
layers.MaxPooling2D((2,2)),
layers.Conv2D(64 , (3,3), activation='relu'),
layers.MaxPooling2D((2,2)),
layers.Conv2D(64 , (3,3), activation='relu'),
layers.MaxPooling2D((2,2)),
layers.Conv2D(64 , (3,3), activation='relu'),
layers.MaxPooling2D((2,2)),
layers.Conv2D(64 , (3,3), activation='relu'),
layers.MaxPooling2D((2,2)),
layers.Flatten(),
layers.Dense(64, activation = 'relu'),
layers.Dense(n_classes, activation = 'softmax')
])
model.build(input_shape = input_shape )
model.summary()
from tensorflow.keras.callbacks import EarlyStopping
early_stopping = EarlyStopping(
min_delta = 0.001,
patience = 10,
restore_best_weights = True,
)
model.compile(
optimizer = 'adam',
loss = tf.keras.losses.SparseCategoricalCrossentropy(from_logits = False),
metrics = ['accuracy']
)
from tensorflow.keras import callbacks
history = model.fit(
train_ds,
epochs = EPOCHS,
batch_size = BATCH_SIZE,
verbose = 1,
callbacks = [early_stopping],
validation_data = val_ds
)
score = model.evaluate(test_ds)
score
history.params
history.history.keys()
len(history.history['accuracy'])
acc = history.history['accuracy']
val_acc = history.history['val_accuracy']
loss = history.history['loss']
val_loss = history.history['val_loss']
plt.figure(figsize = (8,8))
plt.subplot(1,2,1)
plt.plot(range(EPOCHS), acc, label = 'Training Accuracy')
plt.plot(range(EPOCHS), val_acc, label = 'Validation Accuracy')
plt.legend(loc = 'lower right')
plt.title('Training and validation Accuracy')
plt.subplot(1,2,2)
plt.plot(range(EPOCHS), loss, label = 'Training_Loss')
plt.plot(range(EPOCHS), val_loss, label = 'Validation Loss')
plt.legend(loc = 'lower right')
plt.title('Training and validation Loss')
for images_batch, labels_batch in test_ds.take(1):
first_image = (image_batch[0].numpy().astype('uint8'))
first_label = labels_batch[0]
print('first image to predict')
plt.imshow(first_image)
print('actual label: ', class_names[first_label])
batch_prediction = model.predict(images_batch)
print(class_names[np.argmax(batch_prediction[0])])
def predict(model,img):
img_array = tf.keras.preprocessing.image.img_to_array(images[i].numpy())
img_array = tf.expand_dims(img_array, 0)
predictions = model.predict(img_array)
predicted_class = class_names[np.argmax(predictions[0])]
confidence = round(100* (np.max(predictions[0])),2)
return predicted_class, confidence
plt.figure(figsize = (15,15))
for images, labels in test_ds.take(1):
for i in range (9):
ax = plt.subplot(3,3,i+1)
plt.imshow(images[i].numpy().astype('uint8'))
predicted_class, confidence = predict( model, images[i].numpy())
actual_class = class_names[labels[i]]
plt.title(f"actual: {actual_class}, \n Predicted : {predicted_class} \n Confidence: {confidence} ")
plt.axis('off')
!pip install tensorflowjs
import tensorflowjs as tfjs
tfjs.converters.save_keras_model(model, "mode.h5")
#model.save("model1.h5")
#!pip install tensorflowjs
!tensorflowjs_converter --input_format keras '/content/mode.h5' '/content/sabetna-model'
I am working on 3D image data stored as .npy files with shape (128,128,128). When I try to use Keras ImageDataGenerator it throws the following error:
Found 0 validated image filenames belonging to 0 classes.
My code is as follows:
processed_data = r'C:/Users/dush/Desktop/Project/preprocessed'
from tensorflow.keras.preprocessing.image import ImageDataGenerator
img_size = 64
batch_size = 32
data_gen = ImageDataGenerator(horizontal_flip = True,
validation_split=0.2,
fill_mode = "nearest",
zoom_range = 0.3,
width_shift_range = 0.1,
height_shift_range = 0.1,
rotation_range = 30)
train_gen = data_gen.flow_from_dataframe(
dataframe = train,
directory = processed_data,
x_col = 'id',
y_col = 'category',
target_size=(img_size, img_size, img_size),
batch_size = batch_size,
class_mode="binary",
#validate_filenames=False,
subset='training', seed = 23) #image_generator.flow_from_dataframe
valid_gen = data_gen.flow_from_dataframe(
dataframe = train,
directory = processed_data,
x_col = 'id',
y_col = 'category',
target_size=(img_size, img_size, img_size),
#validate_filenames=False,
batch_size=batch_size,
class_mode="binary",
subset='validation', shuffle=False, seed=23)
If I set validate_filenames=False, then it identifies the filenames but get an error when fitting the model. What am I doing wrong?
I'm trying to learn about Computer Vision in Machine Learning with Tensorflow and Keras
I have a directory that contains 4185 images I got from https://www.kaggle.com/datasets/smaranjitghose/corn-or-maize-leaf-disease-dataset
(I intentionally removed 3 images)
I have this code containing listdir() to check if it's true:
import os
folders = os.listdir('/tmp/datasets/data')
print(f'folders: {folders}')
total_images = 0
for f in folders:
total_images += len(os.listdir(f'/tmp/datasets/data/{f}'))
print(f'Total Images found: {total_images}')
The following is the output:
folders: ['Blight', 'Common_Rust', 'Gray_Leaf_Spot', 'Healthy']
Total Images found: 4185
I would like to split it into 80% train set and 20% validation set with Keras' ImageDataGenerator
import tensorflow as tf
from tensorflow.keras.preprocessing.image import ImageDataGenerator
datagen = ImageDataGenerator(
rescale = 1./255,
fill_mode='nearest',
width_shift_range = 0.05,
height_shift_range = 0.05,
rotation_range = 45,
shear_range = 0.1,
zoom_range=0.2,
horizontal_flip = True,
vertical_flip = True,
validation_split = 0.2,
)
val_datagen = ImageDataGenerator(
rescale = 1./255,
validation_split = 0.2
)
train_images = datagen.flow_from_directory('/tmp/datasets/data',
target_size=(150,150),
batch_size=32,
seed=42,
subset='training',
class_mode='categorical'
)
val_images = val_datagen.flow_from_directory('/tmp/datasets/data',
target_size=(150,150),
batch_size=32,
seed=42,
subset='validation',
class_mode='categorical'
)
The following is the output logged by flow_from_directory():
Found 3350 images belonging to 4 classes.
Found 835 images belonging to 4 classes.
The split done is not the expected 3348 | 837 (0.2 * 4185 = 837), did I miss something? or did I misinterpreted the parameter validation_split?
The data is split for each folder (class) and not on the entire dataset. Check the source code here and here to understand more. Here is an example of what flow_from_directory is doing internally:
import os
folders = os.listdir('/content/data')
print(f'folders: {folders}')
total_images = 0
names = []
paths = []
white_list_formats = ('png', 'jpg', 'jpeg', 'bmp', 'ppm', 'tif', 'tiff')
for f in folders:
paths.append(os.listdir(f'/content/data/{f}'))
for d in os.listdir(f'/content/data/{f}'):
if d.lower().endswith(white_list_formats):
names.append(d)
print(f'Total number of valid images found: {len(names)}')
folders: ['Blight', 'Healthy', 'Common_Rust', 'Gray_Leaf_Spot']
Total number of valid images found: 4188
Split data by folders:
training_samples = 0
for p in paths:
split = (0.2, 1)
num_files = len(p)
start, stop = int(split[0] * num_files), int(split[1] * num_files)
valid_files = p[start: stop]
training_samples += len(valid_files)
print(training_samples)
validation_samples = 0
for p in paths:
split = (0, 0.2)
num_files = len(p)
start, stop = int(split[0] * num_files), int(split[1] * num_files)
valid_files = p[start: stop]
validation_samples += len(valid_files)
print(validation_samples)
3352
836
And this corresponds to what you see from flow_from_directory:
from tensorflow.keras.preprocessing.image import ImageDataGenerator
datagen = ImageDataGenerator(
rescale = 1./255,
fill_mode='nearest',
width_shift_range = 0.05,
height_shift_range = 0.05,
rotation_range = 45,
shear_range = 0.1,
zoom_range=0.2,
horizontal_flip = True,
vertical_flip = True,
validation_split = 0.2,
)
val_datagen = ImageDataGenerator(
rescale = 1./255,
validation_split = 0.2
)
train_images = datagen.flow_from_directory('/content/data',
target_size=(150,150),
batch_size=32,
seed=42,
subset='training',
shuffle=False,
class_mode='categorical'
)
val_images = val_datagen.flow_from_directory('/content/data',
target_size=(150,150),
batch_size=32,
seed=42,
subset='validation',
shuffle=False,
class_mode='categorical'
)
Found 3352 images belonging to 4 classes.
Found 836 images belonging to 4 classes.
Note that I did not remove the 3 images like you did, but the logic remains the same.
I am applying the following code to predict an image as cancerous using a merged model (GoogleNet and ResNet). I have used the concatenate function to merge the model.
However i am getting an error for the line validation_steps = len(test_set) used in model.fit even if there are images in both test set and the training set.
Please help me solve this issue.
from keras.models import load_model
merged_model = load_model('googleResNet.h5')
from tensorflow.keras.preprocessing.image import ImageDataGenerator
train_datagen = ImageDataGenerator(rescale = 1./255,
shear_range = 0.2,
zoom_range = 0.2,
horizontal_flip = True)
test_datagen = ImageDataGenerator(rescale = 1./255)
training_set = train_datagen.flow_from_directory('Images/Train',
target_size = (224, 224),
batch_size = 32,
class_mode = 'categorical')
test_set = test_datagen.flow_from_directory('Images/Test',
target_size = (224, 224),
batch_size = 32,
class_mode = 'categorical')
r = merged_model.fit(
[training_set,training_set2],
validation_data = [test_set,test_set2],
epochs=5,
steps_per_epoch = len(training_set),
validation_steps = len(test_set)
)
# loss
plt.plot(r.history['loss'], label='train loss')
plt.plot(r.history['val_loss'], label='val loss')
plt.legend()
plt.show()
plt.savefig('LossVal_loss')
# accuracies
plt.plot(r.history['accuracy'], label='train acc')
plt.plot(r.history['val_accuracy'], label='val acc')
plt.legend()
plt.show()
plt.savefig('AccVal_acc')
#Test the model
new_image = plt.imread('img_004.jpg') #read in the image (3,14,20)
#show the uploaded image
img = plt.imshow(new_image)
from tensorflow.keras.preprocessing import image
img = image.load_img('img_004.jpg',target_size=(224,224))
img = np.asarray(img)
plt.imshow(img)
img = np.expand_dims(img, axis=0)
predictions = model.predict(img)
list_index = [0,1]
x = predictions
for i in range (2):
for j in range(2):
if x[0][list_index][i] > x[0][list_index][j]:
temp = list_index[i]
list_index[i] = list_index[j]
list_index[j] = temp
#Show the sorted labels in order from highesh probability to lowest
print(list_index)
print('')
classification = ['mass','calcifications']
i = 0
for i in range(3):
print(classification[list_index[i]],';',round(predictions[0][list_index[i]]*100,2),'%')
Please find the full error:
Please find the error trace below:
ValueError Traceback (most recent call last)
<ipython-input-21-1294c8191a37> in <module>()
33 epochs=5,
34 steps_per_epoch = len(training_set),
---> 35 validation_steps = len(test_set)
36 )
37
3 frames
/usr/local/lib/python3.6/dist-
packages/tensorflow/python/keras/engine/data_adapter.py in
select_data_adapter(x,
y)
969 "Failed to find data adapter that can handle "
970 "input: {}, {}".format(
--> 971 _type_name(x), _type_name(y)))
972 elif len(adapter_cls) > 1:
973 raise RuntimeError(
ValueError: Failed to find data adapter that can handle input: (<class
'list'> containing
values of types {"<class
'tensorflow.python.keras.preprocessing.image.DirectoryIterator'>"}), <class
'NoneType'>
I am using python and tensorflow and have created a flow from dataframe method (viewed open source code from kaggle) to generate a training and validation datagen. My issue is when i run code for creating a test_X, test_Y sets using the same flow_from_dataframe method.
Originally, this code has worked as kaggle code shows, but for some reason it does not seem to work for me.
I've checked many kaggle kernels, some of which are:
https://www.kaggle.com/digitalchaos666/simple-vgg16/notebook and
https://www.kaggle.com/kmader/attention-on-pretrained-vgg16-for-bone-age
which both have the same code for the problem, but does not seem to run now. Even if you fork the kernel and just run the code as-is, without changing anything, it seems to fail at that point
train_datagen = ImageDataGenerator(samplewise_center=False,
samplewise_std_normalization=False,
horizontal_flip = True,
vertical_flip = False,
height_shift_range = 0.2,
width_shift_range = 0.2,
rotation_range = 5,
shear_range = 0.01,
fill_mode = 'nearest',
zoom_range=0.25,
preprocessing_function = preprocess_input)
train_gen = flow_from_dataframe(train_datagen, df_train,
path_col = 'path',
y_col = 'bone_age_zscore',
target_size = IMG_SIZE,
color_mode = 'rgb',
batch_size = 32)
valid_gen = flow_from_dataframe(train_datagen, df_valid,
path_col = 'path',
y_col = 'bone_age_zscore',
target_size = IMG_SIZE,
color_mode = 'rgb',
batch_size = 256)
# used a fixed dataset for evaluating the algorithm, issue lies here
test_X, test_Y = next(flow_from_dataframe(train_datagen,
df_valid,
path_col = 'path',
y_col = 'bone_age_zscore',
target_size = IMG_SIZE,
color_mode = 'rgb',
batch_size = 512))
The error message is as follows:
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-53-10b59388b3f6> in <module>
36 target_size = IMG_SIZE,
37 color_mode = 'rgb',
---> 38 batch_size = 512)) # one big batch
39
40 print('Complete')
/opt/conda/lib/python3.6/site-packages/keras_preprocessing/image/iterator.py in __next__(self, *args, **kwargs)
102
103 def __next__(self, *args, **kwargs):
--> 104 return self.next(*args, **kwargs)
105
106 def next(self):
/opt/conda/lib/python3.6/site-packages/keras_preprocessing/image/iterator.py in next(self)
114 # The transformation of images is not under thread lock
115 # so it can be done in parallel
--> 116 return self._get_batches_of_transformed_samples(index_array)
117
118 def _get_batches_of_transformed_samples(self, index_array):
/opt/conda/lib/python3.6/site-packages/keras_preprocessing/image/iterator.py in _get_batches_of_transformed_samples(self, index_array)
225 filepaths = self.filepaths
226 for i, j in enumerate(index_array):
--> 227 img = load_img(filepaths[j],
228 color_mode=self.color_mode,
229 target_size=self.target_size,
IndexError: list index out of range
I had solved my issue by creating separate dataframes for each generator.
The train_flow and valid_flow, both make use of the flow_from_dataframe method which takes in a seed value. This allows my training and validation set to be the same whenever I run my code, which was a preference which I needed.
On the other hand, my test_flows did not take in a seed value, so I had created a new method for those.
train_idg = ImageDataGenerator(zoom_range=0.2,
fill_mode='nearest',
rotation_range=25,
width_shift_range=0.25,
height_shift_range=0.25,
vertical_flip=False,
horizontal_flip=True,
shear_range = 0.2,
samplewise_center=False,
samplewise_std_normalization=False)
val_idg = ImageDataGenerator(width_shift_range=0.25,
height_shift_range=0.25,
horizontal_flip=True)
test_idg = ImageDataGenerator()
####
def flow_from_dataframe(imgDatGen, df, batch_size, seed, img_size):
gc.collect()
gen_img = imgDatGen.flow_from_dataframe(dataframe=df,
x_col='path', y_col='boneage_zscore',
batch_size=batch_size, seed=seed, shuffle=True, class_mode='other',
target_size=img_size, color_mode='rgb',
drop_duplicates=False)
gen_gender = imgDatGen.flow_from_dataframe(dataframe=df,
x_col='path', y_col='gender',
batch_size=batch_size, seed=seed, shuffle=True, class_mode='other',
target_size=img_size, color_mode='rgb',
drop_duplicates=False)
while True:
X1i = gen_img.next()
X2i = gen_gender.next()
gc.collect()
yield [X1i[0], X2i[1]], X1i[1]
####
train_flow = flow_from_dataframe(train_idg, train_df, BATCH_SIZE_TRAIN, SEED, IMG_SIZE)
valid_flow = flow_from_dataframe(val_idg, valid_df, BATCH_SIZE_VAL, SEED, IMG_SIZE)
####
def test_gen_2inputs(imgDatGen, df, batch_size, img_size):
gc.collect()
gen_img = imgDatGen.flow_from_dataframe(dataframe=df,
x_col='path', y_col='boneage_zscore',
batch_size=batch_size, shuffle=False, class_mode='other',
target_size=img_size, color_mode='rgb',
drop_duplicates=False)
gen_gender = imgDatGen.flow_from_dataframe(dataframe=df,
x_col='path', y_col='gender',
batch_size=batch_size, shuffle=False, class_mode='other',
target_size=img_size, color_mode='rgb',
drop_duplicates=False)
while True:
X1i = gen_img.next()
X2i = gen_gender.next()
gc.collect()
yield [X1i[0], X2i[1]], X1i[1]
test_flow = test_gen_2inputs(test_idg, test_df, 789, IMG_SIZE)
male_test_flow = test_gen_2inputs(test_idg, male_df, 789, IMG_SIZE)
female_test_flow = test_gen_2inputs(test_idg, female_df, 789, IMG_SIZE)
Thereafter, the code below runs successfully
train_X, train_Y = next(my_train_flow)
test_X, test_Y = next(test_flow)
male_test_X, male_test_Y = next(male_test_flow)
female_test_X, female_test_Y = next(female_test_flow)