4

In the standard implementation of Keras, one can get the API version using keras.__version__.

However, there is no tf.keras.__version__.

So how do I check the version of the Keras API implemented in tf.keras?

P-Gn
  • 23,115
  • 9
  • 87
  • 104

3 Answers3

5

You can simply run this code

from tensorflow.python import keras
print(keras.__version__)

which is compatible with TF v1.8.0.

nbro
  • 15,395
  • 32
  • 113
  • 196
Abhishek Sehgal
  • 590
  • 4
  • 16
  • On TF 1.8 it returns `AttributeError: module 'tensorflow.tools.api.generator.api.keras' has no attribute '__version__'`. Which version of TF are you running? – P-Gn Jul 06 '18 at 06:03
  • You're right. In 1.8.0, I checked and it didn't work, but this was working in previous versions. So I tried `from tensorflow.python import keras; print(keras.__version__);` It printed `2.1.5-tf` – Abhishek Sehgal Jul 06 '18 at 15:26
  • Yes, this one works — and is shorter that my version. If you edit your solution I will accept it. – P-Gn Jul 07 '18 at 08:32
2

This has recently been updated:

>>> import tensorflow as tf
>>> print(tf.keras.__version__)
2.1.6-tf
>>> print(tf.__version__)
1.12.0
user3076252
  • 1,919
  • 13
  • 13
1

You can retrieve the version of Keras implemented in tf.keras using

from tensorflow.python.keras._impl.keras import __version__ as tf_keras_version
print(tf_keras_version)
# 2.1.5-tf (in TF 1.8)

It seems that from TF 1.9 on, it will actually be accessible as tf.keras.__version__, as it should.

P-Gn
  • 23,115
  • 9
  • 87
  • 104