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

Need to explicitly specify x and y instead of using a generator when the model has two inputs. #20518

Open
danica-zhu opened this issue Nov 19, 2024 · 1 comment

Comments

@danica-zhu
Copy link

danica-zhu commented Nov 19, 2024

tf.version: '2.17.0'
tf.keras.version: '3.5.0'

for a image caption model, one input is vector representation of images, another is caption of encoder.

def batch_generator(batch_size, tokens_train, transfer_values_train, is_random_caption=False):
       # ...
        x_data = \
        {
            'transfer_values_input': transfer_values, #transfer_values
            'decoder_input': decoder_input_data # decoder_input_data
            
            
        }

        y_data = \
        {
            'decoder_output': decoder_output_data
        }
        
        yield (x_data, y_data)

then train on this is not work, it mistake the "decoder_input" or "decoder_output" as the "transfer_values_input" for the model, even with right parameters name in the model.

decoder_model.fit(x=flick_generator,
                  steps_per_epoch=flick_steps_per_epoch,
                  epochs=20,
                  callbacks=flick_callbacks)

only explicitly specify x and y will work.

from tqdm import tqdm 
for epoch in tqdm(range(2)): 
    for step in range(flick_steps_per_epoch):
        x_data, y_data = next(flick_generator)

        decoder_model.fit(
            x=x_data,
            y=y_data,
            batch_size=len(x_data[0]), 
            verbose=0, 
        )

    print(f"Epoch {epoch+1} completed.")
@dhantule
Copy link

Hi @danica-zhu,
Thanks for reporting this. It seems like your batch_generator is yielding a tuple of dictionaries, which is being incorrectly interpreted by model.fit. Could you please share the standalone code along with the error message you're receiving to reproduce the issue? Thanks!

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

No branches or pull requests

3 participants