You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am currently developing and testing a RNN that relies upon a large amount of data for training, and so have attempted to separate my training and testing files. I have one file where I create, train, and save a tensorflow.keras model to a file 'model.keras' I then load this model in another file and predict some values, but get the following error: Failed to convert elements of {'class_name': 'tensor', 'config': {'dtype': 'float64', 'value': [0.0, 0.0, 0.0, 0.0]}} to Tensor. Consider casting elements to a supported type. See https://www.tensorflow.org/api_docs/python/tf/dtypes for supported TF dtypes
By the way, I have tried running model.predict with this exact same data in the file where I train the model, and it works smoothly. The model loading must be the problem, not the data used to predict.
This mysterious float64 tensor is the value I passed into the masking layer. I don't understand why keras is unable to recognize this JSON object as a Tensor and apply the masking operation as such. I have included snippets of my code below, edited for clarity and brevity:
model_generation.py:
# Create model
model = tf.keras.Sequential([
tf.keras.layers.Input((352, 4)),
tf.keras.layers.Masking(mask_value=tf.convert_to_tensor(np.array([0.0, 0.0, 0.0, 0.0]))),
tf.keras.layers.GRU(50, return_sequences=True, activation='tanh'),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.GRU(50,activation='tanh'),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Dense(units=1, activation='sigmoid')])
# Compile Model...
# Train Model...
model.save('model.keras')
model.predict(data) # Line works here
model_testing.py
model = tf.keras.models.load_model('model.keras')
model.predict(data) # this line generates the error
I have tried to re-load the model in the model_generation.py file and I get the exact same issue.
The text was updated successfully, but these errors were encountered:
Hi @JoeDoyle12, thanks for reporting this. The error seems to be coming from the mask_value that you are trying to pass. If you try passing your like this mask_value=[0.0,0.0,0.0,0.0] , your code should work fine. Attaching gist
I am currently developing and testing a RNN that relies upon a large amount of data for training, and so have attempted to separate my training and testing files. I have one file where I create, train, and save a tensorflow.keras model to a file 'model.keras' I then load this model in another file and predict some values, but get the following error: Failed to convert elements of {'class_name': 'tensor', 'config': {'dtype': 'float64', 'value': [0.0, 0.0, 0.0, 0.0]}} to Tensor. Consider casting elements to a supported type. See https://www.tensorflow.org/api_docs/python/tf/dtypes for supported TF dtypes
By the way, I have tried running model.predict with this exact same data in the file where I train the model, and it works smoothly. The model loading must be the problem, not the data used to predict.
This mysterious float64 tensor is the value I passed into the masking layer. I don't understand why keras is unable to recognize this JSON object as a Tensor and apply the masking operation as such. I have included snippets of my code below, edited for clarity and brevity:
model_generation.py:
model_testing.py
I have tried to re-load the model in the
model_generation.py
file and I get the exact same issue.The text was updated successfully, but these errors were encountered: