-
Notifications
You must be signed in to change notification settings - Fork 19.5k
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
Callingmodel.predict()
from inside batch generator raises thread-local storage error
#13336
Comments
I just realized that this issue can be resolved by passing I'm going to leave this here just in case others run into the same issue. |
I have fixed this issue on |
@fchollet First, thank you for taking a look so quickly. I saw the commit (977d55c) and expected it would solve the problem. Instead, a new exception is now raised that is possibly related to #1638. The same test code as in the original (re-pasted for completeness) now yields Code to reproduce the issue import keras
import numpy as np
input_layer = keras.layers.Input((1, ))
x = keras.layers.Dense(1, activation='sigmoid')(input_layer)
model = keras.models.Model(inputs=input_layer, outputs=x)
model.compile(loss='binary_crossentropy', optimizer='sgd')
model._make_predict_function()
def generate():
while True:
# If you comment this next line out, no error is raised.
yt = model.predict(np.random.randn(5, 1))
yield np.random.randn(5, 1), np.ones((5, 1))
model.fit_generator(generate(), epochs=3, steps_per_epoch=10) Traceback
|
The error is now limited to tensorflow==1.14.0. No exception is raised with tensorflow==2.0.0rc1. |
I am also having this issue. Downgrading tensorflow to 1.13.1 and Keras to 2.2.4 is another workaround. |
This helped me since upgrading to |
The original issue that I raised here (the thread-local storage error) was fully resolved so I think it makes sense to close this issue. The second issue that arose appears to be addressed by upgrading or downgrading TensorFlow depending on your specific need. If upgrading or downgrading are unsuitable for you, it may make sense to open a new issue focused on the TensorFlow compatibility issue. |
I am getting this error if _SYMBOLIC_SCOPE.value: while I am trying to predict using the model Traceback (most recent call last): |
I have got my one working with I have used
Don't import Hope it helps. |
indeed, it solved my problem |
Example: |
from tensorflow.keras.models import load_model - solved my problem |
System information
Describe the current behavior
When calling a model during training (e.g., from a batch generator), an attribute error is raised related to thread-local data. This occurs in Keras 2.3.0 but not in Keras <= 2.2.5. It appears the thread-local storage elements were added in Keras 2.3.0.
Describe the expected behavior
I expect the model to be callable during training, as has been the case in prior Keras versions. The test code is intentionally trivial to demonstrate the issue. In practice, being able to call a model during batch generation is useful for cases where we generate batches based on current model behavior (e.g., selecting hard examples for a model using triplet loss).
Code to reproduce the issue
Other info / logs
The text was updated successfully, but these errors were encountered: