Closed1

module 'tensorflow' has no attribute 'InteractiveSession'

おっくソおっくソ

https://www.atmarkit.co.jp/ait/articles/1804/19/news136_2.html

こちらの記事通りtensorflowを使おうとすると、InteractiveSession()の部分でエラーがおきました。

(introtensorflow4) MacBook-Pro:~ username$ python
Python 3.8.5 (default, Sep  4 2020, 02:22:02) 
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> sess = tf.InteractiveSession()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'tensorflow' has no attribute 'InteractiveSession'

調べてみるとtensorflowのバージョンによって、呼び出し方が違うみたい。

https://stackoverflow.com/questions/41333798/attributeerror-module-tensorflow-has-no-attribute-interactivesession

こちらの記事によるとv2以上だと、tf.compat.v1.InteractiveSession()で使えるみたい。

自分が使っているtensorflowのバージョンをpip listで確認すると、

tensorflow             2.4.1

ということで、以下のように再トライすると無事進めました。

>>> import tensorflow as tf
>>> sess = tf.compat.v1.InteractiveSession()

公式サイトにもtf.compat.v1.InteractiveSession()と書いてありました。
https://www.tensorflow.org/api_docs/python/tf/compat/v1/InteractiveSession?hl=ja

このスクラップは2021/01/31にクローズされました