eliberis / tflite-tools

TFLite model analyzer & memory optimizer
MIT License
120 stars 20 forks source link

Running on official SPICE tflite model fails with assertion #6

Open mrdeveloperdude opened 2 years ago

mrdeveloperdude commented 2 years ago

I cloned repo, installed pipenv, ran pipenv shell in my exising env and then started tflite_tools.py with the official SPICE model (audio pitch tracking model by google, included with tf) as input. It then failed with assertion error. Please see full transcript below:

(bob) leo@katana:~/Desktop/Projects/Singularity/libs/tflite_build$ pip install pipenv

Collecting pipenv
  Downloading pipenv-2022.5.2-py2.py3-none-any.whl (3.9 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.9/3.9 MB 5.3 MB/s eta 0:00:00
Requirement already satisfied: pip>=22.0.4 in /home/leo/.venv/bob/lib/python3.7/site-packages (from pipenv) (22.1.2)
Collecting virtualenv
  Downloading virtualenv-20.14.1-py2.py3-none-any.whl (8.8 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 8.8/8.8 MB 5.5 MB/s eta 0:00:00
Requirement already satisfied: setuptools>=36.2.1 in /home/leo/.venv/bob/lib/python3.7/site-packages (from pipenv) (40.8.0)
Collecting virtualenv-clone>=0.2.5
  Downloading virtualenv_clone-0.5.7-py3-none-any.whl (6.6 kB)
Requirement already satisfied: certifi in /home/leo/.venv/bob/lib/python3.7/site-packages (from pipenv) (2020.12.5)
Collecting distlib<1,>=0.3.1
  Downloading distlib-0.3.4-py2.py3-none-any.whl (461 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 461.2/461.2 kB 4.4 MB/s eta 0:00:00
Collecting filelock<4,>=3.2
  Downloading filelock-3.7.1-py3-none-any.whl (10 kB)
Requirement already satisfied: importlib-metadata>=0.12 in /home/leo/.venv/bob/lib/python3.7/site-packages (from virtualenv->pipenv) (3.4
.0)
Collecting platformdirs<3,>=2
  Downloading platformdirs-2.5.2-py3-none-any.whl (14 kB)
Requirement already satisfied: six<2,>=1.9.0 in /home/leo/.venv/bob/lib/python3.7/site-packages (from virtualenv->pipenv) (1.15.0)
Requirement already satisfied: typing-extensions>=3.6.4 in /home/leo/.venv/bob/lib/python3.7/site-packages (from importlib-metadata>=0.12
->virtualenv->pipenv) (3.7.4.3)
Requirement already satisfied: zipp>=0.5 in /home/leo/.venv/bob/lib/python3.7/site-packages (from importlib-metadata>=0.12->virtualenv->p
ipenv) (3.4.0)
Installing collected packages: distlib, virtualenv-clone, platformdirs, filelock, virtualenv, pipenv
  Attempting uninstall: filelock
    Found existing installation: filelock 3.0.12
    Uninstalling filelock-3.0.12:
      Successfully uninstalled filelock-3.0.12
Successfully installed distlib-0.3.4 filelock-3.7.1 pipenv-2022.5.2 platformdirs-2.5.2 virtualenv-20.14.1 virtualenv-clone-0.5.7

(bob) leo@katana:~/Desktop/Projects/Singularity/libs$ mkdir tflite_tools (bob) leo@katana:~/Desktop/Projects/Singularity/libs$ cd tflite_tools/ (bob) leo@katana:~/Desktop/Projects/Singularity/libs/tflite_tools$ git clone https://github.com/eliberis/tflite-tools

Cloning into 'tflite-tools'...
remote: Enumerating objects: 314, done.
remote: Counting objects: 100% (22/22), done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 314 (delta 15), reused 15 (delta 9), pack-reused 292
Receiving objects: 100% (314/314), 163.46 KiB | 2.27 MiB/s, done.
Resolving deltas: 100% (242/242), done.
(bob) leo@katana:~/Desktop/Projects/Singularity/libs/tflite_tools$ ll
total 12K
drwxr-xr-x 4 leo leo 4,0K juni   2 01:26 tflite-tools
drwxr-xr-x 3 leo leo 4,0K juni   2 01:26 .
drwxr-xr-x 7 leo leo 4,0K juni   2 01:26 ..

(bob) leo@katana:~/Desktop/Projects/Singularity/libs/tflite_tools$ cd tflite-tools/

(bob) leo@katana:~/Desktop/Projects/Singularity/libs/tflite_tools/tflite-tools$ ls

example_working_set.png  __init__.py  LICENSE  Pipfile  Pipfile.lock  README.md  tflite_tools  tflite_tools.py

(bob) leo@katana:~/Desktop/Projects/Singularity/libs/tflite_tools/tflite-tools$ pipenv install

Courtesy Notice: Pipenv found itself running within a virtual environment, so it will automatically use that environment, instead of creating 
its own for any project. You can set PIPENV_IGNORE_VIRTUALENVS=1 to force pipenv to ignore that environment and create its own instead. You ca
n set PIPENV_VERBOSITY=-1 to suppress this warning.
Installing dependencies from Pipfile.lock (f23fad)...
  🐍   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 17/17 — 00:00:21
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.

(bob) leo@katana:~/Desktop/Projects/Singularity/libs/tflite_tools/tflite-tools$ pipenv shell

Courtesy Notice: Pipenv found itself running within a virtual environment, so it will automatically use that environment, instead of creating its own for any project. You can set PIPENV_IGNORE_VIRTUALENVS=1 to force pipenv to ignore that environment and create its own instead. You can set PIPENV_VERBOSITY=-1 to suppress this warning.
Launching subshell in virtual environment...

(bob) leo@katana:~/Desktop/Projects/Singularity/libs/tflite_tools/tflite-tools$ python tflite_tools.py --help

usage: tflite_tools.py [-h] [-i INPUT_PATH] [-o OUTPUT_PATH]
                       [--clusters CLUSTERS] [--optimize]
                       [--csv CSV_OUTPUT_FOLDER] [--plot PLOT_FILE]
                       [--calc-macs] [--calc-size]

TFLite model analyser & memory optimizer

optional arguments:
  -h, --help            show this help message and exit
  -i INPUT_PATH         input model file (.tflite)
  -o OUTPUT_PATH        output model file (.tflite)
  --clusters CLUSTERS   cluster weights into n-many values (simulate code-book
                        quantization)
  --optimize            optimize peak working set size
  --csv CSV_OUTPUT_FOLDER
                        output model analysis in CSV format into the specified
                        folder
  --plot PLOT_FILE      plot memory usage for each operator during the
                        execution
  --calc-macs           Calculate approximate MAC usage
  --calc-size           Calculate parameter size

(bob) leo@katana:~/Desktop/Projects/Singularity/libs/tflite_tools/tflite-tools$ python tflite_tools.py -i ../../../data/ml/lite-model_spice_1.tflite

Traceback (most recent call last):
  File "tflite_tools.py", line 50, in <module>
    main()
  File "tflite_tools.py", line 24, in main
    model = TFLiteModel.load_from_file(args.input_path)
  File "/home/leo/Desktop/Projects/Singularity/libs/tflite_tools/tflite-tools/tflite_tools/tflite_model.py", line 119, in load_from_file
    return cls(bytearray(f.read()))
  File "/home/leo/Desktop/Projects/Singularity/libs/tflite_tools/tflite-tools/tflite_tools/tflite_model.py", line 114, in __init__
    self._build_graph()
  File "/home/leo/Desktop/Projects/Singularity/libs/tflite_tools/tflite-tools/tflite_tools/tflite_model.py", line 174, in _build_graph
    assert op.OutputsLength() <= 1
AssertionError
Sun2018421 commented 2 years ago

Hello, the assert code: op.OutputsLength() is to ensure each operator in your model has one or No output; you can check the module using Netron tools to see whether there are some operators has more than one output( it is unreasonable because each operator should have only one output). Hope it will help u