解决Keras-Yolo v3错误:AttributeError: module 'keras.backend' has no attribute 'control_flow_ops'

  • 在使用Keras-YOLO v3训练自己的数据集时出现了module ‘keras.backend’ has no attribute 'control_flow_ops’错误,具体错误信息如下.
  • 错误信息:
 Freeze the first 249 layers of total 252 layers.
Traceback (most recent call last):
  File "train.py", line 195, in <module>
    _main()
  File "train.py", line 38, in _main
    freeze_body=2, weights_path='model_data/yolo_weights.h5') # make sure you know what you freeze
  File "train.py", line 135, in create_model
    [*model_body.output, *y_true])
  File "/home/ligy/anaconda3/lib/python3.6/site-packages/Keras-2.2.4-py3.6.egg/keras/engine/base_layer.py", line 457, in __call__
    output = self.call(inputs, **kwargs)
  File "/home/ligy/anaconda3/lib/python3.6/site-packages/Keras-2.2.4-py3.6.egg/keras/layers/core.py", line 716, in call
    return self.function(inputs, **arguments)
  File "/home/ligy/Programming/ShellDetection/keras/keras-yolo3-master/yolo3/model.py", line 394, in yolo_loss
    _, ignore_mask = K.control_flow_ops.while_loop(lambda b,*args: b<m, loop_body, [0, ignore_mask])
AttributeError: module 'keras.backend' has no attribute 'control_flow_ops'

  • 解决方法:
  • 修改以下目录中的“__ init__.py”文件,每个人的路径不太相同,请自行修改~
# 打开目录文件
vim ~/anaconda3/lib/python3.6/site-packages/Keras-2.2.4-py3.6.egg/keras/backend/__init__.py

# 在150行左右加入以下导包语句
from .load_backend import control_flow_ops
from .load_backend import set_image_dim_ordering

# 保存并关闭
按键顺序: ESC ——> : w q 回车    (英文状态下,:不可少)

如图所示:
解决Keras-Yolo v3错误:AttributeError: module 'keras.backend' has no attribute 'control_flow_ops'_第1张图片
再次执行训练程序,不再报错,可以顺利执行~:

你可能感兴趣的:(TensorFlow)