Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inputs has to be named after the first entry of the dict for models with multiple inputs #20036

Closed
henrysky opened this issue Jul 23, 2024 · 6 comments
Assignees
Labels

Comments

@henrysky
Copy link

Keras version: "3.4.1"

For model with multiple inputs, inputs has to be named after the first entry of the dictionary which I think is a bug.

Lets say I have a Keras model with two inputs named a_name and other_name. Error will be raise if I try to train such model with those named inputs

model.fit({"a_name": x_train_1, "other_name": x_train_2}, y_train)

but would be fine if their names are a_name and a_name_whatever or other_name and other_name_whatever

Here is a minimal example on Google Colab to demostrate the issue (https://colab.research.google.com/drive/1oJ5QGMYV7GlHimkquu1SJWd4vyn9-ok0?usp=sharing).

All cells work without raising error if I use Keras 3.3.3

@Grvzard
Copy link
Contributor

Grvzard commented Jul 24, 2024

model = keras.Model(inputs=[x, x2], outputs=output)

=> model = keras.Model(inputs={input1_name: x, input2_name: x2}, outputs=output)

@mehtamansi29
Copy link
Collaborator

Hi @henrysky -

Keras 3.4.1 doesn't directly support dictionary input with model.fit, if the model has named inputs. More details on this you can find here.

def test_case(input1_name, input2_name):
  x = keras.Input(shape=[28, 28, 1], name=input1_name)
  x2 = keras.Input(shape=[10, ], name=input2_name)
  cnn_layer_1 = keras.layers.Conv2D(filters=2,kernel_size=[2,2],)(x)
  maxpool_1 = keras.layers.MaxPooling2D(pool_size=(2, 2))(cnn_layer_1)
  flatten = keras.layers.Flatten()(cnn_layer_1)
  flatten_concat = keras.layers.concatenate([flatten, x2])
  output = keras.layers.Dense(10, activation="softmax")(flatten)

  model = keras.Model(inputs={input1_name: x, input2_name: x2}, outputs=output)
  model.compile(optimizer="adam", loss="categorical_crossentropy", metrics=["accuracy"])
  model.fit({input1_name: x_train, input2_name: y_train}, y_train)

Copy link

github-actions bot commented Aug 8, 2024

This issue is stale because it has been open for 14 days with no activity. It will be closed if no further activity occurs. Thank you.

@github-actions github-actions bot added the stale label Aug 8, 2024
@mehtamansi29
Copy link
Collaborator

Hi @henrysky -

Does the issue is still reproduce to you ?

@henrysky
Copy link
Author

henrysky commented Aug 8, 2024

The example by you has fixed the issue for me, thanks!

@henrysky henrysky closed this as completed Aug 8, 2024
Copy link

Are you satisfied with the resolution of your issue?
Yes
No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants