Can I replace tf.keras.backend with tf?

513 views Asked by At

Implementations in tf.keras.backend have duplicates in pure tensorflow. For example: tf.keras.backend.ones vs tf.ones.

My question: Can I use tensorflow instead of tf.keras.backend, by just replacing it? Both are same API?

2

There are 2 answers

0
OverLordGoldDragon On

Most of the time, yes. To learn of the difference, do:

  1. tf.ones? or tf.ones?? if your IDE supports it; this'll show docs + source code + file location
  2. from inspect import getsource; print(getsource(tf.ones)) will show source code

I'd not replace K with tf, though; stuff gets moved around between versions, and functionality may break. Each has its own list of imports: tensorflow/__init__.py and tensorflow/python/keras/backend.py.

0
AudioBubble On

Yes, you can use tf but there might be minor difference in the results as both of them have different repo maintained.

For example the tf.keras.backend.binary_crossentropy and tf.keras.losses.binary_crossentropy have different code repo maintained but objective should remain the same.