1

I am not sure what I am doing wrong.

The data:

images_generator = ImageDataGenerator()
X_train_images = images_generator.flow_from_dataframe(
    dataframe=dataframe_train,
    directory=None,
    x_col='image_path',
    y_col='target',
    class_mode='raw'
)

dataframe_train.drop("image_path", axis=1, inplace=True)
X_train_tabular = dataframe_train.iloc[:, :-1].values
//scaling etc..
y_train = dataframe_train.iloc[:, -1].values

The model:

# Load the VGG16 model
vgg16 = keras.applications.VGG16(include_top=False, input_shape=(224, 224, 3))
for layer in vgg16.layers:
    layer.trainable = False

image_input = keras.Input(shape=(224, 224, 3), name='image')
tabular_input = keras.Input(shape=(NUM_TABULAR_COLS,), name='tabular')

vgg16_output = vgg16(image_input)
vgg16_output_flat = keras.layers.Flatten()(vgg16_output)

# Combine the flattened VGG16 output and tabular data
combined_inputs = tf.keras.layers.concatenate([vgg16_output_flat, tabular_input])

x = keras.layers.Dense(64, activation='relu')(combined_inputs)
output = keras.layers.Dense(2, activation='softmax')(x)

# Create a model using the inputs and outputs
model = keras.Model(inputs=[image_input, tabular_input], outputs=output)
model.compile(loss='categorical_crossentropy', optimizer='adam')

model.fit(
    [X_train_images, X_train_tabular],
    y_test,
    epochs=2
)

And when I try to fit it I get this exception:

ValueError: Failed to find data adapter that can handle input: (<class 'list'> containing values of types {"<class 'keras.preprocessing.image.DataFrameIterator'>", "<class 'numpy.ndarray'>"}), <class 'numpy.ndarray'>

Not sure how to tackle it since I tried converting to tensors,np array etc. Nothing worked. So now I wonder If I`m doing something essentially wrong.

2
  • Have you found a solution to this problem? I'm struggling with exactly the same one :( Commented May 26, 2023 at 18:00
  • 1
    @MarekM. I did not log in for a while.. Long story short you need to create a generator that will pass the combined input. Check out here - stackoverflow.com/questions/68793010/… Commented Mar 21, 2024 at 19:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.