Help us understand the problem. What is going on with this article?

module 'keras.backend' has no attribute 'control_flow_ops'というエラーに対処するために

はじめに

kerasのバージョンアップに伴い、以上のエラーが出てしまいました。これの解決方法を備忘録として残しておきます。

環境

MacOS Mojave
Python 3.7.2
Keras 2.3.1
tensorflow 1.13.1

手順

kerasの場所を調べる

terminalでpythonの対話シェルを開き、以下のコマンドでkerasのパスを特定します。
(***には自分の環境のパスを入れます。)

>>>import keras
>>>keras.__file__
/***/python3.7/site-packages/keras/__init__.py

/***/python3.7/site-packages/keras/backend/__init__.pyを開く

場所が特定できたら、/***/python3.7/site-packages/keras/backendに入っている__init__.pyを開きます。

from tensorflow.python.ops import control_flow_opsを追加する

from .load_backend importの並びの中に
from tensorflow.python.ops import control_flow_ops
を追加します。

__init__.py
                  .
                  .
                  .
from .load_backend import eager
from .load_backend import size
from .load_backend import control_dependencies

from tensorflow.python.ops import control_flow_ops

終わり

私はこの方法で動かすことができました。もしかしたら、物によっては動かないかもしれないので悪しからず、、、

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした