keras: I get AttributeError on tf 0.10.0 running model_from_json
cnn = model_from_json(jsn)
File "/usr/local/lib/python3.5/dist-packages/keras/models.py", line 197, in model_fr
om_json
return layer_from_config(config, custom_objects=custom_objects)
File "/usr/local/lib/python3.5/dist-packages/keras/utils/layer_utils.py", line 36, i
n layer_from_config
return layer_class.from_config(config['config'])
File "/usr/local/lib/python3.5/dist-packages/keras/models.py", line 1025, in from_co
nfig
model.add(layer)
File "/usr/local/lib/python3.5/dist-packages/keras/models.py", line 308, in add
output_tensor = layer(self.outputs[0])
File "/usr/local/lib/python3.5/dist-packages/keras/engine/topology.py", line 515, in __call__
self.add_inbound_node(inbound_layers, node_indices, tensor_indices)
File "/usr/local/lib/python3.5/dist-packages/keras/engine/topology.py", line 573, in add_inbound_node
Node.create_node(self, inbound_layers, node_indices, tensor_indices)
File "/usr/local/lib/python3.5/dist-packages/keras/engine/topology.py", line 150, in create_node
output_tensors = to_list(outbound_layer.call(input_tensors[0], mask=input_masks[0]))
File "/usr/local/lib/python3.5/dist-packages/keras/layers/core.py", line 91, in call
x = K.in_train_phase(K.dropout(x, self.p, noise_shape), x)
File "/usr/local/lib/python3.5/dist-packages/keras/backend/tensorflow_backend.py", line 1243, in in_train_phase
x = tf.python.control_flow_ops.cond(tf.cast(_LEARNING_PHASE, 'bool'),
AttributeError: module 'tensorflow.python' has no attribute 'control_flow_ops'
The issue is reproduced by doing a model_from_json
on tf 0.10.0, this doesnt happen below tf 0.9.0. Thanks.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 6
- Comments: 17 (6 by maintainers)
Quick fix / hack workaround for v0.11
I think I found the issue.
I’m running
Ubuntu 14.04.5 LTS
withtensorflow==0.10.0
andkeras==1.1.0
. I received the same error as above fromkeras/backend/tensorflow_backend.py
I attempted to install
TF 0.10.0 rc0
but the installation failed for unrelated reasons (though, in hindsight, it would have avoided the root problem if the installation did work).After some digging around, I found out that tensorflow had made a change to remove undocumented symbols in their
tensorflow/python/__init__.py
: https://github.com/tensorflow/tensorflow/commit/5563229b5b45917cd8155bc47a8356af90fb20a2#diff-6ad579dc34adb7a581b8c0bcb1a4dd79Probably as an accident, they made it so that
control_flow_ops
was no longer visible as a submodule oftensorflow.python
. But it can still be imported withfrom tensorflow.python.ops import control_flow_ops
so I addedfrom tensorflow.python.ops import control_flow_ops as tf_control_flow_ops
at the top ofkeras/backend/tensorflow_backend.py
and replaced all references totensorflow.python.control_flow_ops
withtf_control_flow_ops
and it fixed the issue.I’ll go over the contribution guide and submit a pull request.
you can simply go for this monkey patch in your code :
I had the same problem with master version of TF today. Changed to TF 0.10.0 rc0 solved the issue for me.
TF 0.10 appears to be breaking some imports. I’ll look into it, we have to fix it while maintaining compatibility with 0.9.
Of course it does, because
1
just disables dropout.I was getting following error while running kears and tensor flow as backend
x = tf.python.control_flow_ops.cond(tf.cast(_LEARNING_PHASE, ‘bool’), AttributeError: ‘module’ object has no attribute ‘control_flow_ops’
but when i did following, error got vanished, now its working fine import tensorflow as tf tf.python.control_flow_ops = tf