tensorflow: Toco not working on Windows

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): Windows 10
  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: n/a
  • TensorFlow installed from (source or binary): source, pip install --upgrade tf-nightly
  • TensorFlow version (use command below): GIT: ‘v1.9.0-rc2-798-gc818bf016d’, VERSION: ‘1.10.0-dev20180719’
  • Python version: 3.6.6
  • Bazel version (if compiling from source):
  • GCC/Compiler version (if compiling from source):
  • CUDA/cuDNN version:
  • GPU model and memory:
  • Exact command to reproduce:

Python API

`import tensorflow as tf

converter = tf.contrib.lite.TocoConverter.from_keras_model_file(“model.h5”) tflite_model = converter.convert() open(“model.tflite”, “wb”).write(tflite_model)` and

Command-line

toco

You can collect some of this information using our environment capture script:

https://github.com/tensorflow/tensorflow/tree/master/tools/tf_env_collect.sh

You can obtain the TensorFlow version with

python -c “import tensorflow as tf; print(tf.GIT_VERSION, tf.VERSION)”

Describe the problem

I’m trying to convert a keras model to the tflite format, but the sample code provided on the website doesn’t seem to work. As advised in my other issue, I installed tf-nightly. I used a venv to get a clean environment but for some reason, other issues have arisen. In the case of the Python API, ‘lite’ seems to be missing from ‘tensorflow.contrib’ whereas when I run ‘toco’ from the command line, it raises a ModuleNotFoundError as shown below. Any help would be greatly appreciated.

Source code / logs

Python API

Traceback (most recent call last): File "sandbox/run.py", line 3, in <module> converter = tf.contrib.lite.TocoConverter.from_keras_model_file("model.h5") File "C:\beta\lib\site-packages\tensorflow\python\util\lazy_loader.py", line 54, in __getattr__ return getattr(module, item) AttributeError: module 'tensorflow.contrib' has no attribute 'lite'

Command-line (running toco)

Traceback (most recent call last): File "c:\users\user\appdata\local\programs\python\python36\Lib\runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "c:\users\user\appdata\local\programs\python\python36\Lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "C:\beta\Scripts\toco.exe\__main__.py", line 5, in <module> ModuleNotFoundError: No module named 'tensorflow.contrib.lite.python.tflite_convert'

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16 (5 by maintainers)

Most upvoted comments

The TOCO converter was not working for me on Windows 10. For those still having problems, I used the Windows Built-In Subsystem for Linux (good tutorial here https://www.youtube.com/watch?v=xzgwDbe7foQ) as I don’t have knowledge of Docker or similar programs. This allowed me to use TOCO.

I was folowing the tutorial and had a problem running the toco.

This was the solution for me it was not easy because you need to have the exact version of tensorflow, and need to find the toco file but here it goes:

on windows 10 install Windows Subsystem for Linux see

so now you have linux subsystem and you installed Ubunto from store

next step setup your linux machine to have all the need python modules.

  1. install pip3
Note: I had a problem installing pip3, needed to install first pip, then pip3
sudo apt-get install python-pip
sudo apt-get install python3-pip

  1. install tensorflow 1.7 - pip3 install --upgrade “tensorflow==1.7.*” note - this is very important other versions may not work
  2. if you try to run toco you would get :
Command 'toco' not found, did you mean:

  command 'todo' from deb devtodo

Try: sudo apt install <deb name>

so where is toco?

  1. go to folder ~/.local/bin/ there you would find toco. this is a python file so run it python3 ~/.local/bin/toco now you can run the “exe” of toco to convert you can run the command explained in https://codelabs.developers.google.com/codelabs/tensorflow-for-poets-2-tflite/#2

just change the -graph_def_file=tf_files/retrained_graph.pb to --input_file=tf_files/retrained_graph.pb if you are following the tutorial, then go to the git repo folder - “tensorflow-for-poets-2” and run from there: python3 ~/.local/bin/toco --input_file=tf_files/retrained_graph.pb --output_file=tf_files/optimized_graph.lite --input_format=TENSORFLOW_GRAPHDEF --output_format=TFLITE --input_shape=1,224,224,3 --input_array=input --output_array=final_result --inference_type=FLOAT --input_data_type=FLOAT

Hope this helps someone

Note: you can access you windows folders under mnt example /mnt/c/Users/-----/source/repos/tensorflow-for-poets-2

The TOCO converter was not working for me on Windows 10. For those still having problems, I used the Windows Built-In Subsystem for Linux (good tutorial here https://www.youtube.com/watch?v=xzgwDbe7foQ) as I don’t have knowledge of Docker or similar programs. This allowed me to use TOCO.

Yes, unfortunately, we do not currently support tooling on Windows. You can use docker to workaround this or a linux instance. We hope to fix this in the future.