Tensorflow Object Detection API - 'ValueError: anchor_strides must be a list with the same length as self._box_specs'
Asked Answered
E

1

7

I'm working on an object detection problem using Tensorflow's Object Detection API, specifically the facessd model trained on the open images dataset. Can anyone clarify what

anchor_strides must be a list with the same length as self.box_specs

means? I am going through the source code but can't find where self._box_specs is even defined. I'm assuming it's for the bounding box ultimately drawn during inference. I tried resizing the images and nothing changed.

Every time I run the model I get the following error and traceback:

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

Edit: When I printed box_specs_list and anchor_strides, here was my output:

    [[(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)]

They're both the same length (6 items), so I'm extremely confused.

Expiration answered 30/11, 2018 at 19:48 Comment(0)
E
10

Update! I went into the source code --> tensorflow/models/research/object_detection/anchor_generators/multiple_grid_anchor_generator.py and changed line 100 from:

self._anchor_strides = anchor_strides

to

self._anchor_strides = list(anchor_strides)

I solved this problem by just repeatedly going into multiple_grid_anchor_generator.py and printing the box_specs and anchor_strides until I figured out that the length of the list wasn't the issue, it was actually that anchor_strides was being stored as a zip object rather than a list. :)

Expiration answered 30/11, 2018 at 21:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.