tensorflow对象检测API train.py自错误

时间:2018-07-11 13:38:17

标签: python tensorflow machine-learning object-detection

我已经完成了tensorflow对象检测API的所有安装步骤。我已经检查了一些有关正确安装的指南,只是为了确保我正确地进行了安装。但是我仍然一次又一次收到此错误:

Instructions for updating:
Please switch to tf.train.create_global_step
Traceback (most recent call last):
  File "train.py", line 183, in <module>
    tf.app.run()
  File "/usr/local/lib/python3.7/site-packages/tensorflow/python/platform/app.py", line 126, in run
    _sys.exit(main(argv))
  File "train.py", line 179, in main
    graph_hook_fn=graph_rewriter_fn)
  File "/xxxx/models/research/object_detection/trainer.py", line 262, in train
    global_step = slim.create_global_step()
  File "/usr/local/lib/python3.7/site-packages/tensorflow/python/util/deprecation.py", line 250, in new_func
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/tensorflow/contrib/framework/python/ops/variables.py", line 135, in create_global_step
    return training_util.create_global_step(graph)
  File "/usr/local/lib/python3.7/site-packages/tensorflow/python/training/training_util.py", line 143, in create_global_step
    ops.GraphKeys.GLOBAL_STEP])
  File "/usr/local/lib/python3.7/site-packages/tensorflow/python/ops/variable_scope.py", line 1297, in get_variable
    constraint=constraint)
  File "/usr/local/lib/python3.7/site-packages/tensorflow/python/ops/variable_scope.py", line 1093, in get_variable
    constraint=constraint)
  File "/usr/local/lib/python3.7/site-packages/tensorflow/python/ops/variable_scope.py", line 439, in get_variable
    constraint=constraint)
  File "/usr/local/lib/python3.7/site-packages/tensorflow/python/ops/variable_scope.py", line 408, in _true_getter
    use_resource=use_resource, constraint=constraint)
  File "/usr/local/lib/python3.7/site-packages/tensorflow/python/ops/variable_scope.py", line 800, in _get_single_variable
    use_resource=use_resource)
  File "/usr/local/lib/python3.7/site-packages/tensorflow/python/ops/variable_scope.py", line 2157, in variable
    use_resource=use_resource)
  File "/usr/local/lib/python3.7/site-packages/tensorflow/python/ops/variable_scope.py", line 2147, in <lambda>
    previous_getter = lambda **kwargs: default_variable_creator(None, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/tensorflow/python/ops/variable_scope.py", line 2130, in default_variable_creator
    constraint=constraint)
  File "/usr/local/lib/python3.7/site-packages/tensorflow/python/ops/variables.py", line 235, in __init__
    constraint=constraint)
  File "/usr/local/lib/python3.7/site-packages/tensorflow/python/ops/variables.py", line 337, in _init_from_args
    initial_value(), name="initial_value", dtype=dtype)
  File "/usr/local/lib/python3.7/site-packages/tensorflow/python/ops/variable_scope.py", line 784, in <lambda>
    shape.as_list(), dtype=dtype, partition_info=partition_info)
  File "/usr/local/lib/python3.7/site-packages/tensorflow/python/ops/init_ops.py", line 99, in __call__
    return array_ops.zeros(shape, dtype)
  File "/usr/local/lib/python3.7/site-packages/tensorflow/python/ops/array_ops.py", line 1601, in zeros
    output = fill(shape, constant(zero, dtype=dtype), name=name)
  File "/usr/local/lib/python3.7/site-packages/tensorflow/python/framework/constant_op.py", line 214, in constant
    value, dtype=dtype, shape=shape, verify_shape=verify_shape))
  File "/usr/local/lib/python3.7/site-packages/tensorflow/python/framework/tensor_util.py", line 533, in make_tensor_proto
    append_fn(tensor_proto, proto_values)
  File "tensorflow/python/framework/fast_tensor_util.pyx", line 45, in tensorflow.python.framework.fast_tensor_util.AppendInt64ArrayToTensorProto
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/google/protobuf/internal/containers.py", line 251, in append
    self._values.append(self._type_checker.CheckValue(value))
UnboundLocalError: local variable 'self' referenced before assignment

我正在使用一个非常小的训练集(15张图像),只是为了掌握整个过程-当然,稍后我会添加更多内容以确保准确性。我会提及这一点,以防万一。

我怀疑配置文件,train.py文件本身(相对于我的数据集)或.record文件有问题。但是对我来说,一切似乎都符合要求。

我正在使用ssd_mobilenet_v1_coco_11_06_2017数据集和ssd_mobilenet_v1_pets配置。

任何提示都非常感谢。如果我遗漏了必要的详细信息,请告诉我。

1 个答案:

答案 0 :(得分:0)

我在python版本3.7(MacOS 10.13.4)中也遇到了同样的问题,我重新检查了.config文件中给出的路径,但这是正确的。我可以通过将python降级到version2.7并在tensorflow对象识别中遵循相同的安装步骤,并在schedule文件中搜索.config并删除下面的代码块来解决该问题。

schedule { step: 0 learning_rate: .0001 }

然后运行

python legacy/train.py --logtostderr --train_dir=training/ --pipeline_config_path=training/faster_rcnn_inception_v2_pets.config

这可能是由于版本不匹配所致。