jeffheaton / t81_558_deep_learning

T81-558: Keras - Applications of Deep Neural Networks @Washington University in St. Louis
https://sites.wustl.edu/jeffheaton/t81-558/
Other
5.71k stars 3.04k forks source link

Error in running t81_558_class_10_4_captioning.ipynb #33

Closed blackwolf08 closed 4 years ago

blackwolf08 commented 4 years ago

Problem

When training the NN it throws this error

ValueError Traceback (most recent call last) in () 3 for i in tqdm(range(EPOCHS*2)): 4 generator = data_generator(train_descriptions, encoding_train, wordtoidx, max_length, number_pics_per_bath) ----> 5 caption_model.fit_generator(generator, epochs=1, steps_per_epoch=steps, verbose=1) 6 7 caption_model.optimizer.lr = 1e-4

2 frames /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training_generator.py in _get_next_batch(generator, mode) 370 raise ValueError('Output of generator should be ' 371 'a tuple (x, y, sample_weight) ' --> 372 'or (x, y). Found: ' + str(generator_output)) 373 374 if len(generator_output) < 1 or len(generator_output) > 3:

ValueError: Output of generator should be a tuple (x, y, sample_weight) or (x, y). Found: [[array([[0.1227757 , 0.33294907, 0.7527157 , ..., 0.21939711, 0.30216414, 0.40283215], [0.1227757 , 0.33294907, 0.7527157 , ..., 0.21939711, 0.30216414, 0.40283215], [0.1227757 , 0.33294907, 0.7527157 , ..., 0.21939711, 0.30216414, 0.40283215], ..., [0.37351927, 0.24596639, 0.96352935, ..., 1.1459347 , 0.26539996, 0.01983135], [0.37351927, 0.24596639, 0.96352935, ..., 1.1459347 , 0.26539996, 0.01983135], [0.37351927, 0.24596639, 0.96352935, ..., 1.1459347 , 0.26539996, 0.01983135]], dtype=float32), array([[ 0, 0, 0, ..., 0, 0, 1], [ 0, 0, 0, ..., 0, 1, 2], [ 0, 0, 0, ..., 1, 2, 3], ..., [ 0, 0, 0, ..., 66, 68, 3], [ 0, 0, 0, ..., 68, 3, 21], [ 0, 0, 0, ..., 3, 21, 61]], dtype=int32)], array([[0., 0., 1., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.], ..., [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.]], dtype=float32)]

Solution

Tensor flow required a tuple to be returned

jeffheaton commented 4 years ago

I think everything is fixed on this module up to the latest TF 2.0. I also ran it in CoLab with TF 2.0.