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

Question:

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:Userstgmjackanaconda3libsite-packageskerasbackend.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:Userstgmjackanaconda3libsite-packageskerasbackend.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

Asked By: tgm_learn

||

Answers:

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
Answered By: ClaudiaR
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.