cannot import name 'binary_weighted_focal_crossentropy' from 'keras.backend'

im trying to import categorical_dqn

when i try the following

from tf_agents.agents.categorical_dqn import categorical_dqn_agent

i get

ImportError: cannot import name 'binary_weighted_focal_crossentropy' from 'keras.backend' (C:\Users\tgmjack\anaconda3\lib\site-packages\keras\backend.py)

the advice i find around the internet Error importing binary_weighted_focal_crossentropy from keras backend: Cannot import name is to try importing this stuff first

from tensorflow import keras
from tensorflow.keras import layers
from tensorflow.keras.metrics import binary_focal_crossentropy

i end up with the exact same error caused by the second line of this suggestion however.

ImportError: cannot import name 'binary_weighted_focal_crossentropy' from 'keras.backend' (C:\Users\tgmjack\anaconda3\lib\site-packages\keras\backend.py)

####### bonus info ########

im running all this on anaconda

tensorflow version = 2.9.2

tf agents version = 0.5.0

keras version = 2.9.0

im trying to follow this tutorial = https://github.com/tensorflow/agents/blob/master/docs/tutorials/9_c51_tutorial.ipynb

>Solution :

I had a similar problem with tf_agents a few months ago. Doing this fixed it for me:

pip install tf-agents[reverb]

I have the following packages with their respective versions:

keras                         2.9.0
tensorflow                    2.9.2
tf-agents                     0.13.0

Leave a Reply