Keras-yolo3: module 'keras.backend' has no attribute 'control_flow_ops'

Created on 31 Aug 2019  Â·  12Comments  Â·  Source: qqwweee/keras-yolo3

I get this problem when run code on google colab. Please show me how to fix it? Thanks!

Most helpful comment

The code is old. It would not work with Keras 2.2.5. You can switch to
Keras 2.2.4 or lower, or change K.control_flow_ops.while_loop to
tf.while_loop. I havent tried this, though.

On Sat, Aug 31, 2019, 5:05 AM smalldroid notifications@github.com wrote:

I get this problem when run code on google colab. Please show me how to
fix it? Thanks!

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/qqwweee/keras-yolo3/issues/544?email_source=notifications&email_token=AFSNTUOYUPH6ZRL2TC27GJDQHIX6PA5CNFSM4ISTCQM2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HISOZOA,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AFSNTUPXSQM6N5WV2R6UK5LQHIX6PANCNFSM4ISTCQMQ
.

All 12 comments

The code is old. It would not work with Keras 2.2.5. You can switch to
Keras 2.2.4 or lower, or change K.control_flow_ops.while_loop to
tf.while_loop. I havent tried this, though.

On Sat, Aug 31, 2019, 5:05 AM smalldroid notifications@github.com wrote:

I get this problem when run code on google colab. Please show me how to
fix it? Thanks!

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/qqwweee/keras-yolo3/issues/544?email_source=notifications&email_token=AFSNTUOYUPH6ZRL2TC27GJDQHIX6PA5CNFSM4ISTCQM2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HISOZOA,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AFSNTUPXSQM6N5WV2R6UK5LQHIX6PANCNFSM4ISTCQMQ
.

Thanks for you answer! I tried to change to tf.while_loop but still not get luck.

tf.while_loop working here, using tensorflow 1.14.0

I also met this problem on google colab. Here's a solution:

add
from .load_backend import control_flow_ops
from .load_backend import set_image_dim_ordering
to /usr/local/lib/python3.6/dist-packages/keras/backend/__init__.py

code:
os.chdir('/usr/local/lib/python3.6/dist-packages/keras/backend')
!cat __init__.py
then copy and overwrite it:
%%writefile __init__.py

Run the following Bash script:

echo "from .load_backend import control_flow_ops
from .load_backend import set_image_dim_ordering
$(cat /usr/local/lib/python3.6/dist-packages/keras/backend/__init__.py)" > /usr/local/lib/python3.6/dist-packages/keras/backend/__init__.py

Following Jarvis Peng to solve this problem. Thanks all!

I also get this problem on google colab.how to overwrite file on google colab.It seems that it doesn't really change the _init_.py .Because when I see this file again,it remains the same.And I try to change the version of tensorflow and keras,but I don't know why it remain prints the original version.When I using pip list,it show the version I try to install

I even changed the __init.py. But the error still persist.
Any suggestion????

I think that control_flow_ops belongs to tensorflow, thus I added following to __init__.py in backend folder in keras folder. Then it worked.

elif backend() == 'tensorflow':
from tensorflow.python.ops import control_flow_ops

Im not sure about set_image_dim_ordering, though.

I finally solved the problem by downgrading my Keras from version 2.3 to 2.1.5.

I think that control_flow_ops belongs to tensorflow, thus I added following to init.py in backend folder in keras folder. Then it worked.

elif backend() == 'tensorflow':
from tensorflow.python.ops import control_flow_ops

Im not sure about set_image_dim_ordering, though.

thx, I ignored set_image_dim_ordering, it works on tf==1.15.2 keras==2.3.0

i used this
%tensorflow_version 2.x
!pip uninstall -y tensorflow
!pip install tensorflow-gpu==1.14.0

and it worked

Was this page helpful?
0 / 5 - 0 ratings