【问题标题】:Tensorflow - Train.py - ValueError: ('%s is not decorated with @add_arg_scope', ('nets.mobilenet.mobilenet', 'depth_multiplier'))Tensorflow - Train.py - ValueError: ('%s is not decorated with @add_arg_scope', ('nets.mobilenet.mobilenet', 'depth_multiplier'))
【发布时间】:2020-06-28 23:21:34
【问题描述】:

我正在尝试按照本教程制作自定义对象检测模型:https://towardsdatascience.com/custom-object-detection-using-tensorflow-from-scratch-e61da2e10087

在第 10 步之前一切正常,我必须使用 train.py 脚本(使用 tensorflow 1)训练我的模型。

当我运行脚本时(macOS):

python3 train.py     --alsologtostderr     --train_dir=train     --pipeline_config_path=/Users/sol.arabehety/Desktop/models-master/ssd_mobilenet_v2_coco.config

我收到此错误:

File "/Users/sol.arabehety/Library/Python/3.7/lib/python/site-packages/tensorflow/contrib/framework/python/ops/arg_scope.py", line 152, in arg_scope
    _name_op(op))
ValueError: ('%s is not decorated with @add_arg_scope', ('nets.mobilenet.mobilenet', 'depth_multiplier'))

我找到了这个解决方案https://stackoverflow.com/a/53038290/1269404,但我不知道我必须在哪里添加 @add_arg_scope 标签,你能帮帮我吗?

这是 arg_scope.py 文件: https://github.com/google-research/tf-slim/blob/master/tf_slim/ops/arg_scope.py(第 152 行)

这是完整的错误:


models-master$ sudo python3 train.py     --alsologtostderr     --train_dir=train     --pipeline_config_path=/Users/sol.arabehety/Desktop/models-master/ssd_mobilenet_v2_coco.config
/Users/sol.arabehety/Library/Python/3.7/lib/python/site-packages/tensorflow/python/framework/dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/Users/sol.arabehety/Library/Python/3.7/lib/python/site-packages/tensorflow/python/framework/dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/Users/sol.arabehety/Library/Python/3.7/lib/python/site-packages/tensorflow/python/framework/dtypes.py:528: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/Users/sol.arabehety/Library/Python/3.7/lib/python/site-packages/tensorflow/python/framework/dtypes.py:529: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/Users/sol.arabehety/Library/Python/3.7/lib/python/site-packages/tensorflow/python/framework/dtypes.py:530: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
/Users/sol.arabehety/Library/Python/3.7/lib/python/site-packages/tensorflow/python/framework/dtypes.py:535: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])

WARNING: The TensorFlow contrib module will not be included in TensorFlow 2.0.
For more information, please see:
  * https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md
  * https://github.com/tensorflow/addons
If you depend on functionality not listed there, please file an issue.

WARNING:tensorflow:From /Users/sol.arabehety/Library/Python/3.7/lib/python/site-packages/tensorflow/python/platform/app.py:125: 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 /Users/sol.arabehety/Library/Python/3.7/lib/python/site-packages/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:From /Users/sol.arabehety/Library/Python/3.7/lib/python/site-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.
WARNING:tensorflow:num_readers has been reduced to 1 to match input file shards.
WARNING:tensorflow:From /Users/sol.arabehety/Library/Python/3.7/lib/python/site-packages/object_detection/core/preprocessor.py:188: sample_distorted_bounding_box (from tensorflow.python.ops.image_ops_impl) is deprecated and will be removed in a future version.
Instructions for updating:
`seed2` arg is deprecated.Use sample_distorted_bounding_box_v2 instead.
WARNING:tensorflow:From /Users/sol.arabehety/Library/Python/3.7/lib/python/site-packages/object_detection/core/batcher.py:96: batch (from tensorflow.python.training.input) is deprecated and will be removed in a future version.
Instructions for updating:
Queue-based input pipelines have been replaced by `tf.data`. Use `tf.data.Dataset.batch(batch_size)` (or `padded_batch(...)` if `dynamic_pad=True`).
WARNING:tensorflow:From /Users/sol.arabehety/Library/Python/3.7/lib/python/site-packages/tensorflow/python/training/input.py:753: QueueRunner.__init__ (from tensorflow.python.training.queue_runner_impl) is deprecated and will be removed in a future version.
Instructions for updating:
To construct input pipelines, use the `tf.data` module.
WARNING:tensorflow:From /Users/sol.arabehety/Library/Python/3.7/lib/python/site-packages/tensorflow/python/training/input.py:753: add_queue_runner (from tensorflow.python.training.queue_runner_impl) is deprecated and will be removed in a future version.
Instructions for updating:
To construct input pipelines, use the `tf.data` module.
WARNING:tensorflow:From /Users/sol.arabehety/Library/Python/3.7/lib/python/site-packages/tensorflow/python/training/input.py:784: to_float (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.cast instead.
Traceback (most recent call last):
  File "train.py", line 186, in <module>
    tf.app.run()
  File "/Users/sol.arabehety/Library/Python/3.7/lib/python/site-packages/tensorflow/python/platform/app.py", line 125, in run
    _sys.exit(main(argv))
  File "/Users/sol.arabehety/Library/Python/3.7/lib/python/site-packages/tensorflow/python/util/deprecation.py", line 324, in new_func
    return func(*args, **kwargs)
  File "train.py", line 182, in main
    graph_hook_fn=graph_rewriter_fn)
  File "/Users/sol.arabehety/Library/Python/3.7/lib/python/site-packages/object_detection/legacy/trainer.py", line 291, in train
    clones = model_deploy.create_clones(deploy_config, model_fn, [input_queue])
  File "/Users/sol.arabehety/Desktop/models-master/research/slim/deployment/model_deploy.py", line 192, in create_clones
    outputs = model_fn(*args, **kwargs)
  File "/Users/sol.arabehety/Library/Python/3.7/lib/python/site-packages/object_detection/legacy/trainer.py", line 204, in _create_losses
    prediction_dict = detection_model.predict(images, true_image_shapes)
  File "/Users/sol.arabehety/Library/Python/3.7/lib/python/site-packages/object_detection/meta_architectures/ssd_meta_arch.py", line 568, in predict
    preprocessed_inputs)
  File "/Users/sol.arabehety/Library/Python/3.7/lib/python/site-packages/object_detection/models/ssd_mobilenet_v2_feature_extractor.py", line 118, in extract_features
    [mobilenet.depth_multiplier], min_depth=self._min_depth):
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/contextlib.py", line 112, in __enter__
    return next(self.gen)
  File "/Users/sol.arabehety/Library/Python/3.7/lib/python/site-packages/tensorflow/contrib/framework/python/ops/arg_scope.py", line 152, in arg_scope
    _name_op(op))
ValueError: ('%s is not decorated with @add_arg_scope', ('nets.mobilenet.mobilenet', 'depth_multiplier'))

【问题讨论】:

  • 那么...是否有文件文件“/Users/sol.arabehety/Library/Python/3.7/lib/python/site-packages/tensorflow/contrib/framework/python/ops/arg_scope .py" ??你看到第 152 行了吗?
  • 我用 arg_scope.py 文件更新了帖子,我不知道我必须把标签放在哪里(如果这是正确的解决方案)
  • 您的link 显示了问题。在那里,程序员必须在 main 处找到瓶颈函数。因此,在您的情况下,您必须在 nets.mobilenet.mobilenet 找到 depth_multiplier。如果最后一个是在为模型选择主干期间下载的,那么你就陷入了死胡同。抱歉,您必须使用 Tensorflow v2 进行训练。最好遵循 Tensorflow github 上的说明。如果您有……数据集,我很乐意为您提供帮助。
  • 如果我想训练我会关注this。这是带有示例的最安全的解决方案。在里面你可以找到如何bring你自己的数据集....这是最难的部分,因为它需要时间来准备它!
  • 哦,这就解释了为什么我找不到 depth_multiplier 定义...我看到我陷入了死胡同。我尝试使用 Tensorflow2,但我在使用 Slim/contrib 库时遇到了问题……无论如何,我会按照你给我的教程再试一次。谢谢!请在下面给出答案,以便我将其标记为正确:)

标签: python python-3.x tensorflow object-detection tensorflow-lite


【解决方案1】:

您的link 显示了问题。在那里,程序员必须在 main 处找到瓶颈函数。因此,在您的情况下,您必须在 nets.mobilenet.mobilenet 找到 depth_multiplier。如果最后一个是在为模型选择主干期间下载的东西,那么你就陷入了死胡同。抱歉,您必须使用 Tensorflow v2 进行训练。最好遵循 Tensorflow github 上的说明。如果您有……数据集,我很乐意为您提供帮助。

如果我想训练,我会关注this。这是带有示例的最安全的解决方案。在里面你可以找到如何bring你自己的数据集....这是最难的部分,因为它需要时间来准备它!

【讨论】:

    【解决方案2】:

    所以我相信我遇到了完全相同的问题。修复它的唯一方法是实际注释掉对 add_arg_scope 的检查。就我而言,我必须找到 E:\anaconda3\envs\myenv\Lib\site-packages\tensorflow_core\contrib\framework\python\ops\arg_scope.py 并开始执行步骤。

    【讨论】:

      猜你喜欢
      • 2020-02-24
      • 1970-01-01
      • 2022-11-20
      • 2015-04-29
      • 1970-01-01
      • 2021-11-09
      • 2016-11-22
      • 1970-01-01
      • 2023-01-23
      相关资源
      最近更新 更多