Can I replace tf.keras.backend with tf?

Viewed 364

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 Answers

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.

Related