I am trying to make a multi-input Keras model that takes two inputs. One input is an image, and the second input is 1D text. I am storing the paths to the images in a dataframe, and then appending the images to a list like this:
from tqdm import tqdm
train_images = []
for image_path in tqdm(train_df['paths']):
byte_file = tf.io.read_file(image_path)
img = tf.image.decode_png(byte_file)
train_images.append(img)
The 1D text inputs are stored in lists. This process is repeated for the validation and test sets. I then make a dataset, like this:
train_protein = tf.expand_dims(padded_train_protein_encode,axis=2)
training_dataset = tf.data.Dataset.from_tensor_slices(((train_protein, train_images), train_Labels))
training_dataset = training_dataset.batch(20)
val_protein = tf.expand_dims(padded_val_protein_encode, axis=2)
validation_dataset = tf.data.Dataset.from_tensor_slices(((val_protein, val_images), validation_Labels))
validation_dataset = validation_dataset.batch(20)
test_protein = tf.expand_dims(padded_test_protein_encode, axis=2)
test_dataset = tf.data.Dataset.from_tensor_slices(((test_protein, test_images), test_Labels))
test_dataset = test_dataset.batch(20)
I am running this in Google Colab, and even using the high-ram option, the program crashes due to running out of ram. What is the best way to solve this problem?
I have researched tf.data.Dataset.from_generator as an option, but I can't work out how to make it work when there are two inputs. Can anyone help?