Hvass-Labs / TensorFlow-Tutorials

TensorFlow Tutorials with YouTube Videos
MIT License
9.27k stars 4.19k forks source link

Tutorial 20 ValueError in Keras #114

Closed pairwiserr closed 5 years ago

pairwiserr commented 5 years ago
tf.__version__
'2.0.0'
tf.keras.__version__
'2.2.4-tf'

On line 48 model.fit(x_train_pad, y_train, validation_split=0.05, epochs=3, batch_size=64 I get

ValueError: Tried to convert 'y' to a tensor and failed. Error: None values not supported.

I opened an issue https://github.com/keras-team/keras/issues/13407

pairwiserr commented 5 years ago

Solution is to convert all your lists to numpy array e.g.

import numpy as np
x = np.array(x_train_pad)
y = np.array(y_train)

model.fit(x, y, validation_split=0.06, epochs=3, batch_size=64)

Also when you're loading tensorflow keras packages on line 2, change

from tensorflow.python.keras.models import Sequential
from tensorflow.python.keras.layers import Dense, GRU, Embedding
from tensorflow.python.keras.optimizers import Adam
from tensorflow.python.keras.preprocessing.text import Tokenizer
from tensorflow.python.keras.preprocessing.sequence import pad_sequences

to

from tensorflow.compat.v1.keras.models import Sequential
from tensorflow.compat.v1.keras.layers import Dense, GRU, Embedding
from tensorflow.compat.v1.keras.optimizers import Adam
from tensorflow.compat.v1.keras.preprocessing.text import Tokenizer
from tensorflow.compat.v1.keras.preprocessing.sequence import pad_sequences

I think tf 2.0 broke some of the utility functions when calculating gradients.

Hvass-Labs commented 5 years ago

Your post is too short. I have to guess most of the context. Are you running the tutorial exactly like it is in the repo? Are you using another dataset? If you're running it exactly like it is in the repo, then it's perhaps a tensorflow 2.0 problem. At some point I will go through all the tutorials and see if I can update them to TF 2.0. Using compat.v1 is only a temporary fix.

pairwiserr commented 5 years ago

Sorry, I should've prefaced that I am running the notebook exactly as is, line by line, using the same dataset with your download.py and imdb.py.