Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when using TF-Lite visualizer to create the HTML file from a TF-Lite model #18857

Closed
HwMohanLiu opened this issue Apr 25, 2018 · 17 comments
Assignees
Labels
comp:lite TF Lite related issues

Comments

@HwMohanLiu
Copy link

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): Ubuntu 16.04
  • TensorFlow installed from (source or binary): source
  • TensorFlow version (use command below): 1.7
  • Python version: 3.5
  • Bazel version (if compiling from source): 0.11.0
  • GCC/Compiler version (if compiling from source): 4.9
  • CUDA/cuDNN version: 9.0
  • GPU model and memory: 16GB
  • Exact command to reproduce:

Describe the problem

  1. I am trying to use TF-Lite visualization tool to create a graph image on the toco quantized model. However, it dose not work.
  2. I am also tried to use visualize.py to create the html file, but it can not create the corresponding JSON file of the model. It seems that the binary file of "flatc" cannot be found.

Source code / logs

  1. using toco command line tools to converting and quantizing TF model to TF-Lite model
  2. using bazel to build and run TF-Lite visualizer

bazel run tensorflow/contrib/lite/tools:visualize -- quant_mobilenet_v1_infer.tflite quant_mobilenet_v1_infer.html

However, I got error info:

RuntimeError: Invalid filename 'quant_mobilenet_v1_infer.tflite'
ERROR: Non-zero return code '1' from command: Process exited with status 1

which is caused by CreateHtmlFile function in visualize.py

@andrehentz
Copy link
Contributor

Try:
bazel run tensorflow/contrib/lite/tools:visualize -- realpath ./quant_mobilenet_v1_infer.tflite

@andrehentz andrehentz added the comp:lite TF Lite related issues label Apr 25, 2018
@HwMohanLiu
Copy link
Author

The same problem:

RuntimeError: Invalid filename 'realpath'
ERROR: Non-zero return code '1' from command: Process exited with status 1

@andrehentz
Copy link
Contributor

Oh.. I see. You need back-quotes around the last portion of the command:

bazel run tensorflow/contrib/lite/tools:visualize -- `realpath ./quant_mobilenet_v1_infer.tflite`

@HwMohanLiu
Copy link
Author

@andrehentz Thanks a lot. The previous error is solved. However, another error occurs:

IOError: [Errno 2] No such file or directory: '/tmp/quant_mobilenet_v1_infer.json'
ERROR: Non-zero return code '1' from command: Process exited with status 1

It seems that "flatc" is not correctly generated?

@andrehentz
Copy link
Contributor

That's possible, but it looks like the tool is looking for it in the wrong place. We will fix that.

@tensorflowbutler
Copy link
Member

Nagging Assignee @andrehentz: It has been 14 days with no activity and this issue has an assignee. Please update the label and/or status accordingly.

@samsun639
Copy link

same problem , is there any update?

@tingxingdong
Copy link

tingxingdong commented Jun 1, 2018

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
TensorFlow installed from (source or binary): source
TensorFlow version (use command below): 1.7
Python version: 2.7
Bazel version (if compiling from source): 0.12.0
GCC/Compiler version (if compiling from source): 4.9
CUDA/cuDNN version: N/A
GPU model and memory: N/A
Exact command to reproduce:

Describe the problem
I am trying to use TF-Lite visualization tool to create a graph image on the toco convert model. However, it only build but not run and produce html file.

After download mobileNet with *tflite.
1)
cd all the way to visualize.py
"bazel run visualize.py -- ~/mobilenet/mobilenet_v1_1.0_224.tflite ./foo.html "
bazel only builds, but no foo.html produced.

  1. if

bazel run tensorflow/contrib/lite/tools:visualize -- ~/mobilenet/mobilenet_v1_1.0_224.tflite ./foo.html

bazel still builds, but smilar errors like the above reported are seen

sh: third_party/flatbuffers/flatc: No such file or directory
Traceback (most recent call last):

IOError: [Errno 2] No such file or directory: '/tmp/mobilenet_v1_1.0_224.json'

@tingxingdong
Copy link

The realpath trick mentioned above has no help.

@tensorflowbutler
Copy link
Member

Nagging Assignee @andrehentz: It has been 14 days with no activity and this issue has an assignee. Please update the label and/or status accordingly.

@andrewginns
Copy link
Contributor

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): macOS 10.13
TensorFlow installed from (source or binary): source
TensorFlow version (use command below): 1.8
Python version: 2.7
Bazel version (if compiling from source): 0.11.0
GCC/Compiler version (if compiling from source): Apple LLVM version 9.1.0 (clang-902.0.39.2)
CUDA/cuDNN version:
GPU model and memory:
Exact command to reproduce:

I'm having the same problem. Attempting to use the command

bazel run tensorflow/contrib/lite/tools:visualize -- `realpath ./graph.tflite` ./tmp/viz.html

The full error is:

sh: third_party/flatbuffers/flatc: No such file or directory
third_party/flatbuffers/flatc -t --strict-json --defaults-json -o /tmp third_party/tensorflow/contrib/lite/schema/schema.fbs -- /Users/andrewginns/tensorflow-r1.8/tensorflow/contrib/lite/graph.tflite
Traceback (most recent call last):
  File "/private/var/tmp/_bazel_andrewginns/8cde35fd4c3cb2b9d28d654996fb7651/execroot/org_tensorflow/bazel-out/darwin-opt/bin/tensorflow/contrib/lite/tools/visualize.runfiles/org_tensorflow/tensorflow/contrib/lite/tools/visualize.py", line 391, in <module>
    main(sys.argv)
  File "/private/var/tmp/_bazel_andrewginns/8cde35fd4c3cb2b9d28d654996fb7651/execroot/org_tensorflow/bazel-out/darwin-opt/bin/tensorflow/contrib/lite/tools/visualize.runfiles/org_tensorflow/tensorflow/contrib/lite/tools/visualize.py", line 387, in main
    CreateHtmlFile(tflite_input, html_output)
  File "/private/var/tmp/_bazel_andrewginns/8cde35fd4c3cb2b9d28d654996fb7651/execroot/org_tensorflow/bazel-out/darwin-opt/bin/tensorflow/contrib/lite/tools/visualize.runfiles/org_tensorflow/tensorflow/contrib/lite/tools/visualize.py", line 307, in CreateHtmlFile
    data = json.load(open(real_output))
IOError: [Errno 2] No such file or directory: '/tmp/graph.json'
ERROR: Non-zero return code '1' from command: Process exited with status 1

@tingxingdong
Copy link

It seems to be a general bug. Many people see it

@Sri-vatsa
Copy link

Sri-vatsa commented Jun 26, 2018

I have been able to replicate this issue using tensorflow-1.9.0 and Linux. I think the issue is with paths to the schema and also the missing flatc file in thirdparty/flatbuffers/flatc

The current workaround that works for me is to install flatbuffers cloning Google/flatbuffers repo using cmake to build. After which, I updated the paths to _BINARY and _SCHEMA at the top of tensorflow/contrib/lite/tools/visualize.py

Example:

_BINARY = path/to/flatc/file/in/cloned/flatbuffers/folder

_SCHEMA =
absolute/path/to/schema.fbs

Specify the output file to a path of your choice for example:
Bazel run tensorflow/contrib/lite/tools:visualize -- model.tflite ~/Desktop/model_viz.html

This has allowed me to visualize my tflite models. Hope that helps!

@andrewginns
Copy link
Contributor

andrewginns commented Jul 8, 2018

@Sri-vatsa could you provide instructions for how you fixed the missing flatc file? I'm a little lost as to what repo you cloned and how you updated the paths.

@Sri-vatsa @HwMohanLiu @samsun639 @tingxingdong

Figured it out. Requires cmake

  1. Clone https://github.com/google/flatbuffers
  2. Extract and navigate to the flatbuffers-master folder
  3. Run the appropriate cmake command
cmake -G "Unix Makefiles"
cmake -G "Visual Studio 10"
cmake -G "Xcode"
  1. Make
make
  1. Test that it was successful
./flattests
  1. Navigate to your tensorflow-master folder
  2. Edit tensorflow/contrib/lite/tools/visualize.py
  3. Change the _BINARY = path/to/flatc/file/in/cloned/flatbuffers/folder
  4. Change the _SCHEMA =absolute/path/to/schema.fbs
  5. Your TFLite visualise command should now work!

For reference my paths looks like:
_SCHEMA = "home/user/Downloads/tensorflow-master/tensorflow/contrib/lite/schema/schema.fbs"
_BINARY = "home/user/Downloads/flatbuffers-master/flatc"

@Sri-vatsa
Copy link

@andrewginns Thanks for writing the step by step instructions! I was typing it on my phone so I tried to keep it short.

@achowdhery achowdhery self-assigned this Jul 19, 2018
@achowdhery
Copy link

@HwMohanLiu Is this still an open issue?

@HwMohanLiu
Copy link
Author

No, I followed the solution of andrewginns and it works now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:lite TF Lite related issues
Projects
None yet
Development

No branches or pull requests

9 participants