models icon indicating copy to clipboard operation
models copied to clipboard

export_tflite_ssd_graph.py - doesn't create anything in /tmp/tflite

Open anonym24 opened this issue 8 years ago • 13 comments

from the next link I'm trying to get the frozen graph

https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/running_on_mobile_tensorflowlite.md

object_detection/export_tflite_ssd_graph.py \
--pipeline_config_path=/home/user/Downloads/ssd_mobilenet_v1_quantized_300x300_coco14_sync_2018_07_18/pipeline.config \
--trained_checkpoint_prefix=/home/user/Downloads/ssd_mobilenet_v1_quantized_300x300_coco14_sync_2018_07_18/model.ckpt \
--output_directory=/tmp/tflite \
--add_postprocessing_op=true

Logs:

object_detection/export_tflite_ssd_graph.py \
> --pipeline_config_path=/home/user/Downloads/ssd_mobilenet_v1_quantized_300x300_coco14_sync_2018_07_18/pipeline.config \
> --trained_checkpoint_prefix=/home/user/Downloads/ssd_mobilenet_v1_quantized_300x300_coco14_sync_2018_07_18/model.ckpt \
> --output_directory=/tmp \
> --add_postprocessing_op=true
object_detection/export_tflite_ssd_graph.py: line 81: preprocess: command not found
object_detection/export_tflite_ssd_graph.py: line 81: config_override: command not found
object_detection/export_tflite_ssd_graph.py: line 81: rExports an SSD detection model to use with tf-lite.

Outputs file:
* A tflite compatible frozen graph - /tflite_graph.pb

The exported graph has the following input and output nodes.

Inputs:
'normalized_input_image_tensor': a float32 tensor of shape
[1, height, width, 3] containing the normalized input image. Note that the
height and width must be compatible with the height and width configured in
the fixed_shape_image resizer options in the pipeline config proto.

In floating point Mobilenet model, 'normalized_image_tensor' has values
between [-1,1). This typically means mapping each pixel (linearly)
to a value between [-1, 1]. Input image
values between 0 and 255 are scaled by (1/128.0) and then a value of
-1 is added to them to ensure the range is [-1,1).
In quantized Mobilenet model, 'normalized_image_tensor' has values between [0,
255].
In general, see the  function defined in the feature extractor class
in the object_detection/models directory.

Outputs:
If add_postprocessing_op is true: frozen graph adds a
  TFLite_Detection_PostProcess custom op node has four outputs:
  detection_boxes: a float32 tensor of shape [1, num_boxes, 4] with box
  locations
  detection_classes: a float32 tensor of shape [1, num_boxes]
  with class indices
  detection_scores: a float32 tensor of shape [1, num_boxes]
  with class scores
  num_boxes: a float32 tensor of size 1 containing the number of detected boxes
else:
  the graph has two outputs:
   'raw_outputs/box_encodings': a float32 tensor of shape [1, num_anchors, 4]
    containing the encoded box predictions.
   'raw_outputs/class_predictions': a float32 tensor of shape
    [1, num_anchors, num_classes] containing the class scores for each anchor
    after applying score conversion.

Example Usage:
--------------
python object_detection/export_tflite_ssd_graph     --pipeline_config_path path/to/ssd_mobilenet.config     --trained_checkpoint_prefix path/to/model.ckpt     --output_directory path/to/exported_model_directory

The expected output would be in the directory
path/to/exported_model_directory (which is created if it does not exist)
with contents:
 - tflite_graph.pbtxt
 - tflite_graph.pb
Config overrides (see the  flag) are text protobufs
(also of type pipeline_pb2.TrainEvalPipelineConfig) which are used to override
certain fields in the provided pipeline_config_path.  These are useful for
making small changes to the inference graph that differ from the training or
eval config.

Example Usage (in which we change the NMS iou_threshold to be 0.5 and
NMS score_threshold to be 0.0):
python object_detection/export_tflite_ssd_graph     --pipeline_config_path path/to/ssd_mobilenet.config     --trained_checkpoint_prefix path/to/model.ckpt     --output_directory path/to/exported_model_directory
    --config_override : No such file or directory
import-im6.q16: not authorized `tf' @ error/constitute.c/WriteImage/1037.
from: can't read /var/mail/google.protobuf
from: can't read /var/mail/object_detection
from: can't read /var/mail/object_detection.protos
object_detection/export_tflite_ssd_graph.py: line 99: flags: command not found
object_detection/export_tflite_ssd_graph.py: line 100: syntax error near unexpected token `'output_directory','
object_detection/export_tflite_ssd_graph.py: line 100: `flags.DEFINE_string('output_directory', None, 'Path to write outputs.')'

System information

  • What is the top-level directory of the model you are using: http://download.tensorflow.org/models/object_detection/ssd_mobilenet_v1_quantized_300x300_coco14_sync_2018_07_18.tar.gz
  • 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): 16.04
  • TensorFlow installed from (source or binary): python pip tensorflow-gpu
  • TensorFlow version (use command below): 1.11
  • Bazel version (if compiling from source): -
  • CUDA/cuDNN version: 9.0/7
  • GPU model and memory: GTX 1060 6GB

anonym24 avatar Nov 07 '18 11:11 anonym24

Thank you for your post. We noticed you have not filled out the following field in the issue template. Could you update them if they are relevant in your case, or leave them as N/A? Thanks. Exact command to reproduce

tensorflowbutler avatar Nov 08 '18 00:11 tensorflowbutler

Any solution to this? Also facing the same issue here!

ColinWang1203 avatar Nov 08 '18 01:11 ColinWang1203

@tensorflowbutler I filled System information and described the problem clearly enough

anonym24 avatar Nov 08 '18 06:11 anonym24

Having the same problem too. No output was produced.

WendyFriend avatar Nov 15 '18 04:11 WendyFriend

Found the solution! Add python3 , ie :

python3 object_detection/export_tflite_ssd_graph.py
--pipeline_config_path=$CONFIG_FILE
--trained_checkpoint_prefix=$CHECKPOINT_PATH
--output_directory=$OUTPUT_DIR
--add_postprocessing_op=true

ColinWang1203 avatar Nov 15 '18 05:11 ColinWang1203

mmmm... still getting no output.

Here's the command I used:

python3 object_detection/export_tflite_ssd_graph.py \
--pipeline_config_path=object_detection/training/ssd_inception_v2_coco.config \
--trained_checkpoint_prefix=object_detection/training/model.ckpt-2012 \
--output_directory=/tmp/tflite \
--add_postprocessing_op=true

Logs:

WARNING:tensorflow:From /Users/qinwen/Documents/test/venv/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.
W1115 22:52:46.746988 4321362816 deprecation.py:328] From /Users/qinwen/Documents/test/venv/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.
WARNING:tensorflow:From /Users/qinwen/Documents/test/models/research/object_detection/anchor_generators/multiple_grid_anchor_generator.py:183: to_float (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.cast instead.
W1115 22:52:49.546639 4321362816 deprecation.py:328] From /Users/qinwen/Documents/test/models/research/object_detection/anchor_generators/multiple_grid_anchor_generator.py:183: to_float (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.cast instead.
2018-11-15 22:52:50.581360: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
WARNING:tensorflow:From /Users/qinwen/Documents/test/venv/lib/python3.6/site-packages/tensorflow/python/tools/freeze_graph.py:127: checkpoint_exists (from tensorflow.python.training.checkpoint_management) is deprecated and will be removed in a future version.
Instructions for updating:
Use standard file APIs to check for files with this prefix.
W1115 22:52:51.221764 4321362816 deprecation.py:328] From /Users/qinwen/Documents/test/venv/lib/python3.6/site-packages/tensorflow/python/tools/freeze_graph.py:127: checkpoint_exists (from tensorflow.python.training.checkpoint_management) is deprecated and will be removed in a future version.
Instructions for updating:
Use standard file APIs to check for files with this prefix.
WARNING:tensorflow:From /Users/qinwen/Documents/test/venv/lib/python3.6/site-packages/tensorflow/python/tools/freeze_graph.py:232: convert_variables_to_constants (from tensorflow.python.framework.graph_util_impl) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.compat.v1.graph_util.convert_variables_to_constants
W1115 22:52:52.826546 4321362816 deprecation.py:328] From /Users/qinwen/Documents/test/venv/lib/python3.6/site-packages/tensorflow/python/tools/freeze_graph.py:232: convert_variables_to_constants (from tensorflow.python.framework.graph_util_impl) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.compat.v1.graph_util.convert_variables_to_constants
WARNING:tensorflow:From /Users/qinwen/Documents/test/venv/lib/python3.6/site-packages/tensorflow/python/framework/graph_util_impl.py:245: extract_sub_graph (from tensorflow.python.framework.graph_util_impl) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.compat.v1.graph_util.extract_sub_graph
W1115 22:52:52.827930 4321362816 deprecation.py:328] From /Users/qinwen/Documents/test/venv/lib/python3.6/site-packages/tensorflow/python/framework/graph_util_impl.py:245: extract_sub_graph (from tensorflow.python.framework.graph_util_impl) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.compat.v1.graph_util.extract_sub_graph
2018-11-15 22:52:53.720731: I tensorflow/tools/graph_transforms/transform_graph.cc:317] Applying strip_unused_nodes`

Does anyone what the problem is? Thanks in advance!

System information

What is the top-level directory of the model you are using: http://download.tensorflow.org/models/object_detection/ssd_inception_v2_coco_2018_01_28.tar.gz

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): macOS high Sierra version 10.13.6 TensorFlow installed from (source or binary): pip install tensorflow TensorFlow version (use command below): 1.9 Bazel version (if compiling from source): NA

WendyFriend avatar Nov 15 '18 12:11 WendyFriend

@SunnQinnWenn did you solve it? having the same issue

Tonto5000 avatar Mar 14 '19 17:03 Tonto5000

@Tonto5000 please check that the directory exists - this is file I/O error in running python

achowdhery avatar Mar 14 '19 17:03 achowdhery

Can confirm with @achowdhery . This happened to me in multiple occasions when my dataset was renamed to something else.

DrLeucine avatar Mar 18 '19 20:03 DrLeucine

I had the same problem and I solved it by activating the appropriate conda environment (since I use Anaconda) and typing python before the command.

ReemRashwan avatar May 03 '19 03:05 ReemRashwan

python: can't open file 'export_tflite_ssd_graph.py': [Errno 2] No such file or directory please help

MIRAzad avatar Aug 08 '19 12:08 MIRAzad

Are you running it from /path/to/projects/models/research/object_detection, which some folks export as $MODELS_RESEARCH_DIR?

jrasor avatar Aug 10 '19 21:08 jrasor

Hi There, We are checking to see if you still need help on this, as this seems to be considerably old issue. Please update this issue with the latest information, code snippet to reproduce your issue and error you are seeing. If we don't hear from you in the next 7 days, this issue will be closed automatically. If you don't need help on this issue any more, please consider closing this.

tensorflowbutler avatar Jan 29 '20 22:01 tensorflowbutler