如何解决 'tensorflow' 没有属性 'init_scope'

how to solve 'tensorflow' has no attribute 'init_scope'

我在 windows 中使用 TensorFlow 1.8。我为我的项目使用了 object_detection 样本,当我 运行 train.py 我得到这个错误:

    (tensorflow_gpu) C:\Users\hewil\Desktop\Tensorflow\models\research>python train.py --logtostderr --train_dir=object_detection/CAPTCHA_training/ --pipeline_config_path=object_detection/CAPTCHA_training/faster_rcnn_inception_v2_coco.config
WARNING:tensorflow:From C:\Users\hewil\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\platform\app.py:126: main (from __main__) is deprecated and will be removed in a future version.
Instructions for updating:
Use object_detection/model_main.py.
WARNING:tensorflow:From C:\Users\hewil\Desktop\Tensorflow\models\research\object_detection\legacy\trainer.py:266: create_global_step (from tensorflow.contrib.framework.python.ops.variables) is deprecated and will be removed in a future version.
Instructions for updating:
Please switch to tf.train.create_global_step
WARNING:tensorflow:num_readers has been reduced to 1 to match input file shards.
Traceback (most recent call last):
  File "train.py", line 184, in <module>
    tf.app.run()
  File "C:\Users\hewil\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\platform\app.py", line 126, in run
    _sys.exit(main(argv))
  File "C:\Users\hewil\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\util\deprecation.py", line 250, in new_func
    return func(*args, **kwargs)
  File "train.py", line 180, in main
    graph_hook_fn=graph_rewriter_fn)
  File "C:\Users\hewil\Desktop\Tensorflow\models\research\object_detection\legacy\trainer.py", line 291, in train
    clones = model_deploy.create_clones(deploy_config, model_fn, [input_queue])
  File "C:\Users\hewil\Desktop\Tensorflow\models\research\slim\deployment\model_deploy.py", line 193, in create_clones
    outputs = model_fn(*args, **kwargs)
  File "C:\Users\hewil\Desktop\Tensorflow\models\research\object_detection\legacy\trainer.py", line 204, in _create_losses
    prediction_dict = detection_model.predict(images, true_image_shapes)
  File "C:\Users\hewil\Desktop\Tensorflow\models\research\object_detection\meta_architectures\faster_rcnn_meta_arch.py", line 822, in predict
    prediction_dict = self._predict_first_stage(preprocessed_inputs)
  File "C:\Users\hewil\Desktop\Tensorflow\models\research\object_detection\meta_architectures\faster_rcnn_meta_arch.py", line 873, in _predict_first_stage
    image_shape) = self._extract_rpn_feature_maps(preprocessed_inputs)
  File "C:\Users\hewil\Desktop\Tensorflow\models\research\object_detection\meta_architectures\faster_rcnn_meta_arch.py", line 1252, in _extract_rpn_feature_maps
    feature_map_shape[2])]))
  File "C:\Users\hewil\Desktop\Tensorflow\models\research\object_detection\core\anchor_generator.py", line 108, in generate
    anchors_list = self._generate(feature_map_shape_list, **params)
  File "C:\Users\hewil\Desktop\Tensorflow\models\research\object_detection\anchor_generators\grid_anchor_generator.py", line 111, in _generate
    with tf.init_scope():
AttributeError: module 'tensorflow' has no attribute 'init_scope'

我该如何解决?

关注此线程 https://github.com/tensorflow/hub/issues/324 似乎 TensorFlow 在高于 9 的版本上只有 init_scope 属性。我有 TensorFlow 1.12 和 运行 也非常适合对象检测。 试一试,让我知道进展如何。 P.S。您可能想要清除您的安装并从头开始使用特定版本。 1.12.0 应该可以解决问题。

干杯,