I have a project with TensorFlow and I am struggling with the preparation in double input data. I hope I can recieve your assist from this problem. So I will present my code here:
#input data
import os, cv2
train_path = r"..\Dataset\Train"
val_path = r"..\Dataset\Val"
def read_image_data(root):
all file = os.listdir (root) #take all couple files
#print(len(all_file))
#load couple images
datal = []
data2 = []
for i in all file:
#take couple path
temp_path = os.listdir(root + '\\' + i)
datal.append(cv2.resize(cv2.imread(...))) # read and resize image
data2.append(cv2.resize(cv2.imread(...))) # read and resize image
return[data1, data2]
train_data = read_image_data(train_path)
val_data = read_image_data (val_path)
Then I create label: train_labels = np.ones (len(train_data[0]), dtype=int)
This is my shape of train_data and label_data:
- Shape of my data: train_data (2,27542, 320, 320, 3)
- Shape of my labels: train_labels(27542,)
After that, I use code ImageGenerator for double input from: https://github.com/keras-team/keras/issues/3386
from tensorflow.keras.preprocessing.image import ImageDataGenerator
#This code I take from above link:
generator = ImageDataGenerator (rescale = 1/.255)
def generate_data_generator_for_two_images (X1, X2, Y) :
print (np.shape(X1))
print (np.shape(X2))
print (np.shape(Y))
genX1 = generator.flow(X1, Y, seed=7)
genX2 = generator.flow(X2, seed=7)
While True:
XIi = genX1.next()
X2i = genX2.next()
yield [Xli[0], X2i J, X1i[1]
temp = next (generate_data_generator_for_two_images(train_data[e], train_data[1], train_labels))
It throws error: Error
I found a lot of information in many forum, but it seems make me more confuse. Besides, I didn't have many experiences in this multiple input case, I hope you can assist me in this problem.