Keras YoloV3 在 Google Colab 上,AttributeError:模块 'keras.backend' 没有属性 'control_flow_ops



我使用Roboflow提供的Keras YoloV3实现在Google Colab上训练我自己的数据集。尝试演示运行,但出现AttributeError。

失败的解决方案1:Github Ticket尝试将K.control_flow_ops.wile…更改为tf.wile…,这对我的colab笔记本不起作用。

错误代码:

/content/keras-yolo3/yolo3/model.py in yolo_loss(args, anchors, num_classes, ignore_thresh, print_loss)
392             ignore_mask = ignore_mask.write(b, K.cast(best_iou<ignore_thresh, K.dtype(true_box)))
393             return b+1, ignore_mask
--> 394         _, ignore_mask = ts.while_loop(lambda b,*args: b<m, loop_body, [0, ignore_mask])
395         ignore_mask = ignore_mask.stack()
396         ignore_mask = K.expand_dims(ignore_mask, -1)
AttributeError: module 'keras.backend' has no attribute 'control_flow_ops' 

我知道由于Google Colab对预装库的不断更新,存在一些问题。

Google Colab库的原始版本如下

Python 3.7.11
Name: tensorflow
Version: 2.5.0
Summary: TensorFlow is an open source machine learning framework for everyone.
Home-page: https://www.tensorflow.org/
Author: Google Inc.
Author-email: packages@tensorflow.org
License: Apache 2.0
Location: /usr/local/lib/python3.7/dist-packages
Requires: numpy, wheel, termcolor, astunparse, opt-einsum, keras-nightly, flatbuffers, protobuf, typing-extensions, six, google-pasta, gast, tensorflow-estimator, keras-preprocessing, tensorboard, wrapt, h5py, grpcio, absl-py
Required-by: kapre
Name: Keras
Version: 2.4.3
Summary: Deep Learning for humans
Home-page: https://github.com/keras-team/keras
Author: Francois Chollet
Author-email: francois.chollet@gmail.com
License: MIT
Location: /usr/local/lib/python3.7/dist-packages
Requires: scipy, h5py, pyyaml, numpy
Required-by: keras-vis
Name: h5py
Version: 3.1.0
Summary: Read and write HDF5 files from Python
Home-page: http://www.h5py.org
Author: Andrew Collette
Author-email: andrew.collette@gmail.com
License: BSD
Location: /usr/local/lib/python3.7/dist-packages
Requires: numpy, cached-property
Required-by: tensorflow, Keras, keras-vis

我也关注了这篇帖子,并将所有库降级为此响应。此外,我尝试使用以下替代方案降级TensorFlow:

%tensorflow_version 1.x

这并没有解决问题。任何帮助都将不胜感激。

选项1:您可以根据存储库要求将Keras从2.4.3降级到2.1

选项2:您可以使用tf.while_loop,而不是在"import tensorflow as tf "之后使用K.control_flow_ops.while_oop
看到一个打字错误"ts";此处而不是tf

_, ignore_mask = ts.while_loop(lambda b,*args: b<m, loop_body, [0, ignore_mask])

已编辑

_, ignore_mask = tf.while_loop(lambda b,*args: b<m, loop_body, [0, ignore_mask])

相关内容

  • 没有找到相关文章

最新更新