What is the top-level directory of the model you are using: models/research/slim/nets
Have I written custom code (as opposed to using a stock example script provided in TensorFlow): No
OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10
TensorFlow installed from (source or binary): pip
TensorFlow version (use command below): 1.8
Bazel version (if compiling from source):
CUDA/cuDNN version: 8.0
GPU model and memory: Nvidia GeForce GTX 1060
Exact command to reproduce: Running mobilenet_v1_eval.py or eval_image_classifier.py in slim dir
InvalidArgumentError: Can not squeeze dim[1], expected a dimension of 1, got 2 for 'FeatureExtractor/MobilenetV1/Logits/SpatialSqueeze' (op: 'Squeeze') with input shapes: [250,2,2,8].
I get this error using model.ckpt from ssd_mobilenet_v1_coco_2017_11_17 and my own mobilenet models that have been fine tuned with no network modification.
I can run the eval script from the object detection API but am looking to add to slim's eval at a lower level for better metrics.
In order to get the object detection checkpointed model to run, the scope in mobilenet_v1.py has to be prepended with 'FeatureExtractor/'. From what I can gather, it seems this issue may be related to slim building the dataset different from the object detection API, because all model parameters as inspected via the 'inspect_checkpoint' tool are correct.
Source code / logs
Traceback
(most recent call last)
~\Anaconda3\envs\tensorflow2\lib\site-packages\tensorflow\python\framework\ops.py in _create_c_op(graph, node_def, inputs, control_inputs)
1566 try:
-> 1567 c_op = c_api.TF_FinishOperation(op_desc)
1568 except errors.InvalidArgumentError as e:
InvalidArgumentError: Can not squeeze dim[1], expected a dimension of 1, got 2 for 'FeatureExtractor/MobilenetV1/Logits/SpatialSqueeze' (op: 'Squeeze') with input shapes: [250,2,2,8].
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
<ipython-input-1-b2f90a361522> in <module>()
150
151
--> 152 tf.app.run(main)
~\Anaconda3\envs\tensorflow2\lib\site-packages\tensorflow\python\platform\app.py in run(main, argv)
124 # Call the main function, passing through any arguments
125 # to the final program.
--> 126 _sys.exit(main(argv))
127
128
<ipython-input-1-b2f90a361522> in main(unused_arg)
147
148 def main(unused_arg):
--> 149 eval_model()
150
151
<ipython-input-1-b2f90a361522> in eval_model()
135 def eval_model():
136 """Evaluates mobilenet_v1."""
--> 137 g, eval_ops = build_model()
138 with g.as_default():
139 num_batches = math.ceil(FLAGS.num_examples / float(FLAGS.batch_size))
<ipython-input-1-b2f90a361522> in build_model()
123 is_training=False,
124 depth_multiplier=FLAGS.depth_multiplier,
--> 125 num_classes=FLAGS.num_classes)
126
127 if FLAGS.quantize:
~\Anaconda3\envs\tensorflow2\Lib\site-packages\tensorflow\models\research\slim\nets\mobilenet_v1.py in mobilenet_v1(inputs, num_classes, dropout_keep_prob, is_training, min_depth, depth_multiplier, conv_defs, prediction_fn, spatial_squeeze, reuse, scope, global_pool)
384 normalizer_fn=None, scope='Conv2d_1c_1x1')
385 if spatial_squeeze:
--> 386 logits = tf.squeeze(logits, [1, 2], name='SpatialSqueeze')
387 end_points['Logits'] = logits
388 if prediction_fn:
~\Anaconda3\envs\tensorflow2\lib\site-packages\tensorflow\python\ops\array_ops.py in squeeze(input, axis, name, squeeze_dims)
2628 if np.isscalar(axis):
2629 axis = [axis]
-> 2630 return gen_array_ops.squeeze(input, axis, name)
2631
2632
~\Anaconda3\envs\tensorflow2\lib\site-packages\tensorflow\python\ops\gen_array_ops.py in squeeze(input, axis, name)
9662 axis = [_execute.make_int(_i, "axis") for _i in axis]
9663 _, _, _op = _op_def_lib._apply_op_helper(
-> 9664 "Squeeze", input=input, squeeze_dims=axis, name=name)
9665 _result = _op.outputs[:]
9666 _inputs_flat = _op.inputs
~\Anaconda3\envs\tensorflow2\lib\site-packages\tensorflow\python\framework\op_def_library.py in _apply_op_helper(self, op_type_name, name, **keywords)
785 op = g.create_op(op_type_name, inputs, output_types, name=scope,
786 input_types=input_types, attrs=attr_protos,
--> 787 op_def=op_def)
788 return output_structure, op_def.is_stateful, op
789
~\Anaconda3\envs\tensorflow2\lib\site-packages\tensorflow\python\framework\ops.py in create_op(self, op_type, inputs, dtypes, input_types, name, attrs, op_def, compute_shapes, compute_device)
3390 input_types=input_types,
3391 original_op=self._default_original_op,
-> 3392 op_def=op_def)
3393
3394 # Note: shapes are lazily computed with the C API enabled.
~\Anaconda3\envs\tensorflow2\lib\site-packages\tensorflow\python\framework\ops.py in __init__(self, node_def, g, inputs, output_types, control_inputs, input_types, original_op, op_def)
1732 op_def, inputs, node_def.attr)
1733 self._c_op = _create_c_op(self._graph, node_def, grouped_inputs,
-> 1734 control_input_ops)
1735 else:
1736 self._c_op = None
~\Anaconda3\envs\tensorflow2\lib\site-packages\tensorflow\python\framework\ops.py in _create_c_op(graph, node_def, inputs, control_inputs)
1568 except errors.InvalidArgumentError as e:
1569 # Convert to ValueError for backwards compatibility.
-> 1570 raise ValueError(str(e))
1571
1572 return c_op
ValueError: Can not squeeze dim[1], expected a dimension of 1, got 2 for 'FeatureExtractor/MobilenetV1/Logits/SpatialSqueeze' (op: 'Squeeze') with input shapes: [250,2,2,8].
System information
InvalidArgumentError: Can not squeeze dim[1], expected a dimension of 1, got 2 for 'FeatureExtractor/MobilenetV1/Logits/SpatialSqueeze' (op: 'Squeeze') with input shapes: [250,2,2,8].
I get this error using model.ckpt from ssd_mobilenet_v1_coco_2017_11_17 and my own mobilenet models that have been fine tuned with no network modification.
I can run the eval script from the object detection API but am looking to add to slim's eval at a lower level for better metrics.
In order to get the object detection checkpointed model to run, the scope in mobilenet_v1.py has to be prepended with 'FeatureExtractor/'. From what I can gather, it seems this issue may be related to slim building the dataset different from the object detection API, because all model parameters as inspected via the 'inspect_checkpoint' tool are correct.
Source code / logs