tensorflow: label_image example does not work with Mobilenetv1 (224)
System information
-
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): Mac OS X 10.12.5
-
TensorFlow installed from (source or binary): Source
-
TensorFlow version (use command below): Github tag 1.2 release
-
Python version: 2.7 (Mac OS X System install)
-
Bazel version (if compiling from source): Homebrew 0.4.5
-
CUDA/cuDNN version: NA
-
GPU model and memory: NA
-
Exact command to reproduce:
bazel-bin/tensorflow/examples/label_image/label_image --image=/Path/to/image.jpg --input_layer=input --output_layer=MobilenetV1/Predictions/Reshape_1 --graph=/Path/To/my/trained/mobilenet.pb --labels=/Path/To/My/labels.txt --input_mean=0 --input_std=255
Describe the problem
Ive retrained MobileNetV1 (224) via the TF Slim readme.md and have produced a graph.pb trained against a data set with 5 labels to classify. I am attempting to validate my training by running the exported graph on some validation and training data myself, and have build label_image and specified the above flags to run.
Its unclear if label image is expected able to run MobileNet , but it does not: it errors with:
E tensorflow/examples/label_image/main.cc:312] Running model failed: Invalid argument: Tried to explicitly squeeze dimension 1 but dimension was not 1: 2 [[Node: MobilenetV1/Logits/SpatialSqueeze = Squeeze[T=DT_FLOAT, squeeze_dims=[1, 2], _device="/job:localhost/replica:0/task:0/cpu:0"](MobilenetV1/Logits/Conv2d_1c_1x1/BiasAdd)]]
Source code / logs
Full execution command and output:
Mayalls-Object:tensorflow vade$ bazel-bin/tensorflow/examples/label_image/label_image --image=/Volumes/MediaArchive/datasets/SynopsisCinemaNet/data/Framing/original_photos/Extreme\ Close\ Up/images_12\ copy.jpg --input_layer=input --output_layer=MobilenetV1/Predictions/Reshape_1 --graph=/Volumes/MediaArchive/datasets/SynopsisCinemaNet/model/FramingWeekend/CinemaNetFraming.pb --labels=/Volumes/MediaArchive/datasets/SynopsisCinemaNet/datasets/Framing/labels.txt --input_mean=0 --input_std=255 2017-07-03 14:44:05.971869: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations. 2017-07-03 14:44:05.972224: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations. 2017-07-03 14:44:05.972228: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations. 2017-07-03 14:44:05.972231: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations. 2017-07-03 14:44:06.123365: E tensorflow/examples/label_image/main.cc:312] Running model failed: Invalid argument: Tried to explicitly squeeze dimension 1 but dimension was not 1: 2 [[Node: MobilenetV1/Logits/SpatialSqueeze = Squeeze[T=DT_FLOAT, squeeze_dims=[1, 2], _device="/job:localhost/replica:0/task:0/cpu:0"](MobilenetV1/Logits/Conv2d_1c_1x1/BiasAdd)]] Mayalls-Object:tensorflow vade$ bazel-bin/tensorflow/examples/label_image/label_image --image=/Volumes/MediaArchive/datasets/SynopsisCinemaNet/data/Framing/converted_photos/Extreme\ Close\ Up/images_12\ copy.jpg --input_layer=input --output_layer=MobilenetV1/Predictions/Reshape_1 --graph=/Volumes/MediaArchive/datasets/SynopsisCinemaNet/model/FramingWeekend/CinemaNetFraming.pb --labels=/Volumes/MediaArchive/datasets/SynopsisCinemaNet/datasets/Framing/labels.txt --input_mean=0 --input_std=255 2017-07-03 14:44:47.201141: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations. 2017-07-03 14:44:47.201530: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations. 2017-07-03 14:44:47.201534: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations. 2017-07-03 14:44:47.201538: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations. 2017-07-03 14:44:47.365892: E tensorflow/examples/label_image/main.cc:312] Running model failed: Invalid argument: Tried to explicitly squeeze dimension 1 but dimension was not 1: 2 [[Node: MobilenetV1/Logits/SpatialSqueeze = Squeeze[T=DT_FLOAT, squeeze_dims=[1, 2], _device="/job:localhost/replica:0/task:0/cpu:0"](MobilenetV1/Logits/Conv2d_1c_1x1/BiasAdd)]] Mayalls-Object:tensorflow vade$
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 19 (7 by maintainers)
I think this may be a documentation issue. Here’s an example set of arguments I’ve been able to run on my copies of Mobilenet:
The key differences from yours are that I’m specifying the width and height explicitly, that I’m using -127 to 127 as the range, and that I’m using the set of labels required for Mobilenet.
I’ve recently updated the TF for Poets docs and scripts to support Mobilenet by the way:
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/docs_src/tutorials/image_retraining.md#other-model-architectures
I am taking images from mobile Gallery, and then calling recognizeImage method of Classifier with InputSize from 224 to 1024, and in all this values its throwing ArrayIndexOutOfBound Exception. So to resolve this exception, I passes InputSize as 1600 and more, and then I am getting exception as “java.lang.IllegalArgumentException: Tried to explicitly squeeze dimension 1 but dimension was not 1: 22 [[Node: MobilenetV1/Logits/SpatialSqueeze = SqueezeT=DT_FLOAT, squeeze_dims=[1, 2], _device=“/job:localhost/replica:0/task:0/cpu:0”]]”
Then I was trying to retrain the model with flag IMAGE_SIZE=2048 and ARCHITECTURE=“mobilenet_0.50_${IMAGE_SIZE}”, but its throwing error like:- tensorflow:The Mobilenet input size should be ‘224’, ‘192’, ‘160’, or ‘128’, but found ‘2048’ for architecture ‘mobilenet_0.50_2048’ ERROR:tensorflow:Did not recognize architecture flag
Any idea, how to resolve this issue?
Hi, I’m facing the same kind of problem. I fine-tuned MobileNetV1_224 on flowers dataset using procedure in https://www.tensorflow.org/tutorials/image_retraining. It seems to works as it generated an output_graph.pb and output_labels.txt as expected. but when I try my fine-tuned model with label_image, it fails (but it works well with a fine-tuned inception v3). I tried the suggestion made by petewarden but it did not work. I had the following error:
ValueError: The name 'MobilenetV1/Predictions/Reshape_1' looks like an (invalid) Operation name, not a Tensor. Tensor names must be of the form "<op_name>:<output_index>".
So I tested summarize_graph on my model and it found 1 possible input (name=input) and one possible output (name=final_result). when I put these values as input_layer and output_layer, I have this:
Traceback (most recent call last): File "label_image_mobilenet.py", line 149, in <module> tf.app.run(main=main, argv=sys.argv[:1]+unparsed) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 48, in run _sys.exit(main(_sys.argv[:1] + flags_passthrough)) File "label_image_mobilenet.py", line 145, in main FLAGS.num_top_predictions) File "label_image_mobilenet.py", line 107, in run_graph predictions, = sess.run(softmax_tensor, {input_layer_name: image_data}) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 789, in run run_metadata_ptr) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 968, in _run np_val = np.asarray(subfeed_val, dtype=subfeed_dtype) File "/usr/local/lib/python2.7/dist-packages/numpy/core/numeric.py", line 531, in asarray return array(a, dtype, copy=False, order=order) ValueError: could not convert string to float: ����
I really don’t understand what is going on. Do you have any idea? Thanks in advance for your help.
Regards, Stephane