我正在使用Tensorflow的对象检测API解决对象检测问题,特别是在开放图像数据集上训练的facessd
模型。谁能澄清一下
anchor_strides must be a list with the same length as self.box_specs
是什么意思?我正在查看源代码,但找不到self._box_specs
的定义位置。我假设这是在推断过程中最终绘制的边界框。我尝试调整图像的大小,但没有任何改变。
每次运行模型时,都会出现以下错误和回溯信息:
Traceback (most recent call last):
File "object_detection/model_main.py", line 109, in <module>
tf.app.run()
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 125, in run
_sys.exit(main(argv))
File "object_detection/model_main.py", line 105, in main
tf.estimator.train_and_evaluate(estimator, train_spec, eval_specs[0])
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/estimator/training.py", line 471, in train_and_evaluate
return executor.run()
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/estimator/training.py", line 610, in run
return self.run_local()
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/estimator/training.py", line 711, in run_local
saving_listeners=saving_listeners)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/estimator/estimator.py", line 354, in train
loss = self._train_model(input_fn, hooks, saving_listeners)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/estimator/estimator.py", line 1207, in _train_model
return self._train_model_default(input_fn, hooks, saving_listeners)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/estimator/estimator.py", line 1234, in _train_model_default
input_fn, model_fn_lib.ModeKeys.TRAIN))
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/estimator/estimator.py", line 1075, in _get_features_and_labels_from_input_fn
self._call_input_fn(input_fn, mode))
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/estimator/estimator.py", line 1162, in _call_input_fn
return input_fn(**kwargs)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/models/research/object_detection/inputs.py", line 479, in _train_input_fn
batch_size=params['batch_size'] if params else train_config.batch_size)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/models/research/object_detection/builders/dataset_builder.py", line 145, in build
num_parallel_calls=num_parallel_calls)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/data/ops/dataset_ops.py", line 1040, in map
return ParallelMapDataset(self, map_func, num_parallel_calls)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/data/ops/dataset_ops.py", line 2649, in __init__
use_inter_op_parallelism)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/data/ops/dataset_ops.py", line 2611, in __init__
map_func, "Dataset.map()", input_dataset)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/data/ops/dataset_ops.py", line 1860, in __init__
self._function.add_to_graph(ops.get_default_graph())
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/function.py", line 479, in add_to_graph
self._create_definition_if_needed()
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/function.py", line 335, in _create_definition_if_needed
self._create_definition_if_needed_impl()
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/function.py", line 344, in _create_definition_if_needed_impl
self._capture_by_value, self._caller_device)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/function.py", line 864, in func_graph_from_py_func
outputs = func(*func_graph.inputs)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/python/data/ops/dataset_ops.py", line 1794, in tf_data_structured_function_wrapper
ret = func(*nested_args)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/models/research/object_detection/builders/dataset_builder.py", line 129, in process_fn
processed_tensors = transform_input_data_fn(processed_tensors)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/models/research/object_detection/inputs.py", line 456, in transform_and_pad_input_data_fn
model = model_builder.build(model_config, is_training=True)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/models/research/object_detection/builders/model_builder.py", line 118, in build
return _build_ssd_model(model_config.ssd, is_training, add_summaries)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/models/research/object_detection/builders/model_builder.py", line 244, in _build_ssd_model
ssd_config.anchor_generator)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/models/research/object_detection/builders/anchor_generator_builder.py", line 81, in build
ssd_anchor_generator_config.reduce_boxes_in_lowest_layer))
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/models/research/object_detection/anchor_generators/multiple_grid_anchor_generator.py", line 334, in create_ssd_anchors
anchor_strides, anchor_offsets)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/tensorflow/models/research/object_detection/anchor_generators/multiple_grid_anchor_generator.py", line 121, in __init__
'as self._box_specs' % arg_name)
ValueError: anchor_strides must be a list with the same length as self._box_specs
编辑:当我打印box_specs_list和anchor_strides时,这是我的输出:
[[(0.1, 1.0), (0.20000000298023224, 2.0), (0.20000000298023224, 0.5)], [(0.35, 1.0), (0.35, 2.0), (0.35, 0.5), (0.35, 3.0), (0.35, 0.33329999446868896), (0.41833001202031717, 1.0)], [(0.4999999970197678, 1.0), (0.4999999970197678, 2.0), (0.4999999970197678, 0.5), (0.4999999970197678, 3.0), (0.4999999970197678, 0.33329999446868896), (0.5700877082367386, 1.0)], [(0.6499999940395356, 1.0), (0.6499999940395356, 2.0), (0.6499999940395356, 0.5), (0.6499999940395356, 3.0), (0.6499999940395356, 0.33329999446868896), (0.7211102477570095, 1.0)], [(0.7999999910593033, 1.0), (0.7999999910593033, 2.0), (0.7999999910593033, 0.5), (0.7999999910593033, 3.0), (0.7999999910593033, 0.33329999446868896), (0.8717797783669882, 1.0)], [(0.949999988079071, 1.0), (0.949999988079071, 2.0), (0.949999988079071, 0.5), (0.949999988079071, 3.0), (0.949999988079071, 0.33329999446868896), (0.9746794283655889, 1.0)]]
[(16, 16), (32, 32), (64, 64), (128, 128), (256, 256), (512, 512)]
它们的长度相同(6个项),所以我非常困惑。
答案 0 :(得分:4)
更新!我进入源代码-> tensorflow/models/research/object_detection/anchor_generators/multiple_grid_anchor_generator.py
,并将第100行更改为:
self._anchor_strides = anchor_strides
到
self._anchor_strides = list(anchor_strides)
我解决了这个问题,只是反复进入multiple_grid_anchor_generator.py并打印box_specs和anchor_strides,直到我发现列表的长度不是问题,实际上是anchor_strides被存储为zip对象而不是比清单。 :)