Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

License

NotificationsYou must be signed in to change notification settings

hpssjellis/tensorflowjs-to-arduino-for-tinymljs

Repository files navigation

install on your own Linux (Ubuntu) machine.

Not presently working on windows, hopefully that changes.Actually presently I can't even get this working on Ubuntu. Try the ipythonhttps://colab.research.google.com/drive/1OgCcKhklL3EH_SdWHdtlb5dbtYvjGQnn?usp=sharing or gitpod optionshttps://gitpod.io/#github.com/hpssjellis/Gitpod-auto-tensorflowJS-to-arduino

The steps (Suppossedly)

  1. Go to the location you downloaded the model .json and model.bin files fromhttps://hpssjellis.github.io/tinyMLjs/public/index.html
  2. Instal venvsudo apt install python3.12-venv so you can work in an environment and not have other things mess it up
  3. Install a virtual environmentpython3 -m venv myenv10
  4. Activate that environment (note it has a folder you can stay out of )source myenv10/bin/activate or on windowsmyenv10\scripts\activate
  5. pip install tensorflow
  6. pip install tensorflowjs
  7. pip install tensorRT
  8. tflite_convert --help
  9. tensorflowjs_converter --help10.tensorflowjs_converter --input_format=tfjs_layers_model --output_format=keras_saved_model ./model.json ./ Convert tfjs file to keras
  10. tflite_convert --keras_model_file ./ --output_file ./model.tflite Convert Keras file to tflite file
  11. xxd -i model.tflite model.h Convert tflite file to a c-header file (This needs xxd installed, several ways to do this also can do it from a web page)

Non of the above work for me that is why I have the other options

  1. use python notebookshttps://colab.research.google.com/drive/1OgCcKhklL3EH_SdWHdtlb5dbtYvjGQnn?usp=sharing (run both sketches then upload your files and run the last sketch again)
  2. This repohttps://github.com/hpssjellis/Gitpod-auto-tensorflowJS-to-arduino and run the gitpod which has a file that does the conversions. Basically it installs the above and then you can run the commands or a bash file I have ready to do the conversions for you. The autoloading gitpod is herehttps://gitpod.io/#github.com/hpssjellis/Gitpod-auto-tensorflowJS-to-arduino.

.

.

The old stuff

This github repository is athttps://github.com/hpssjellis/tensorflowjs-to-arduino-for-tinymljs

if you want to load it as a Gitpod clickhttps://gitpod.io/#github.com/hpssjellis/tensorflowjs-to-arduino-for-tinymljs

Click the above link to load the gitpod (docker in the browser) which installs all needed files

You can use the test-with folder to drag amodel.json file with it's shard .bin filemodel.weights.bin to the main folder

Look at the code in thea01-convert-tfjs-arduino.sh and then run it

Then run./a01-convert-tfjs-arduino.sh

Gotchas When making your own files themodel.json file is made with a link to themodel.weights.bin file, if you change the name of the binary file the model.json fle will not link to it properly

Install on a local machines

DRAFT Instructions

I assume python is installed probably best to have Python3 installed.

pip install tensorflowjspython -m site --user-base

to the above reply add

\bin\tensorflowjs_converter -h

Then run the commands for your files which are in the a01-convert-tfjs-arduino.sh bash file

tensorflowjs_converter --input_format=tfjs_layers_model --output_format=keras_saved_model ./model.json ./tflite_convert --keras_model_file ./ --output_file ./model.tflitexxd -i model.tflite model.h

Then you can load your model.tflite file onto thehttps://netron.app/ website to visualize it and then add the model.h file into your arduino machine learning code as it;s own include file.

See the Arduino ready library athttps://github.com/hpssjellis/RocksettaTinyML download the zip file and install it into the arduino ide using the normal zip file libary upload method.sketch --> include library --> add .zip file

Note: If the above commands don't work you can always try the python code below.

  1. convert from tensorflowJS to Keras
import tensorflowjs as tfjs# Define the pathsinput_format = "tfjs_layers_model"output_format = "keras_saved_model"input_model_json = "./model.json"output_dir = "./"# Convert the modeltfjs.converters.save_keras_model(input_model_json, output_dir, input_format, output_format)
  1. Then use tensorflow lite converter to convert the Keras file into tensorflow Lite (TFLITE)

   import tensorflow as tf# Define the pathskeras_model_file = "./model"  # Make sure the model file has the .h5 extensionoutput_file = "./model.tflite"# Convert the model to TensorFlow Liteconverter = tf.lite.TFLiteConverter.from_keras_model_file(keras_model_file)tflite_model = converter.convert()# Save the TensorFlow Lite model to a filewith open(output_file, 'wb') as f:    f.write(tflite_model)

If you have install ability then install the xxd application

sudo apt-get install xxd

and run the command

xxd -i model.tflite model.h

If you don't have admin access you can try using the online xxd -1 utility herehttps://hpssjellis.github.io/tinyMLjs/public/convert/xxd-i.html

Upload your tFLITE file and get the web to convert it into a c-header model.h file ready to run on a micro-controler with an appropriate sketch.

May 2024 trying to update. so far

python.exe -m pip install --upgrade pip

pip3 install --upgrade pip

python -m venv myenv2

myenv2\scripts\activate

pip3 install tensorflowjs

pip3 install tensorflow==2.15.0

pip3 install tensorflow-hub

pip3 install netron "dask[delayed]"

$env:TF_ENABLE_ONEDNN_OPTS=0

tflite_convert --helptensorflowjs_converter --help

xxd --help

https://sourceforge.net/projects/xxd-for-windows/

in power shell try
Format-Hex '.\your-file-name'

this set works

pip list--------------------------------- ---------absl-py                           2.1.0argon2-cffi                       21.1.0astroid                           2.7.3astunparse                        1.6.3attrs                             21.2.0autopep8                          1.5.7backcall                          0.2.0backports.entry-points-selectable 1.1.0bandit                            1.7.0bleach                            4.1.0cached-property                   1.5.2cachetools                        5.3.3certifi                           2021.5.30cffi                              1.14.6charset-normalizer                2.0.4chex                              0.1.7click                             8.1.7cloudpickle                       3.0.0colorama                          0.4.4cryptography                      3.4.8dask                              2023.5.0debugpy                           1.4.3decorator                         5.1.0defusedxml                        0.7.1distlib                           0.3.2dm-tree                           0.1.8docutils                          0.17.1entrypoints                       0.3etils                             1.3.0filelock                          3.0.12flake8                            3.9.2flatbuffers                       24.3.25flax                              0.7.2fsspec                            2024.5.0gast                              0.4.0gitdb                             4.0.7GitPython                         3.1.18google-auth                       2.29.0google-auth-oauthlib              1.0.0google-pasta                      0.2.0grpcio                            1.63.0h5py                              3.11.0idna                              3.2importlib_metadata                7.1.0importlib_resources               6.4.0ipykernel                         6.4.1ipython                           7.27.0ipython-genutils                  0.2.0isort                             5.9.3jax                               0.4.13jaxlib                            0.4.13jedi                              0.18.0jeepney                           0.7.1Jinja2                            3.0.1jsonschema                        3.2.0jupyter-client                    7.0.2jupyter-core                      4.7.1jupyterlab-pygments               0.1.2keras                             2.13.1keyring                           23.2.1lazy-object-proxy                 1.6.0libclang                          18.1.1locket                            1.0.0Markdown                          3.6markdown-it-py                    3.0.0MarkupSafe                        2.1.5matplotlib-inline                 0.1.3mccabe                            0.6.1mdurl                             0.1.2mistune                           0.8.4ml-dtypes                         0.2.0msgpack                           1.0.8mypy                              0.910mypy-extensions                   0.4.3nbclient                          0.5.4nbconvert                         6.1.0nbformat                          5.1.3nest-asyncio                      1.5.1netron                            7.6.6notebook                          6.4.3numpy                             1.24.3oauthlib                          3.2.2opt-einsum                        3.3.0optax                             0.1.8orbax-checkpoint                  0.2.3packaging                         23.2pandas                            2.0.3pandocfilters                     1.4.3parso                             0.8.2partd                             1.4.1pbr                               5.6.0pep8                              1.7.1pexpect                           4.8.0pickleshare                       0.7.5pip                               24.0pipenv                            2021.5.29pkginfo                           1.7.1platformdirs                      2.3.0prometheus-client                 0.11.0prompt-toolkit                    3.0.20protobuf                          4.25.3ptyprocess                        0.7.0pyasn1                            0.6.0pyasn1_modules                    0.4.0pycodestyle                       2.7.0pycparser                         2.20pydocstyle                        6.1.1pyflakes                          2.3.1Pygments                          2.18.0pylama                            7.7.1pylint                            2.10.2pyparsing                         2.4.7pyrsistent                        0.18.0python-dateutil                   2.8.2pytz                              2024.1PyYAML                            5.4.1pyzmq                             22.2.1readme-renderer                   29.0requests                          2.26.0requests-oauthlib                 2.0.0requests-toolbelt                 0.9.1rfc3986                           1.5.0rich                              13.7.1rope                              0.19.0rsa                               4.9scipy                             1.10.1SecretStorage                     3.3.1Send2Trash                        1.8.0setuptools                        58.0.4six                               1.16.0smmap                             4.0.0snowballstemmer                   2.1.0stevedore                         3.4.0tensorboard                       2.13.0tensorboard-data-server           0.7.2tensorflow                        2.13.1tensorflow-decision-forests       1.5.0tensorflow-estimator              2.13.0tensorflow-hub                    0.16.1tensorflow-io-gcs-filesystem      0.34.0tensorflowjs                      4.19.0tensorstore                       0.1.45termcolor                         2.4.0terminado                         0.12.1testpath                          0.5.0tf-keras                          2.15.0toml                              0.10.2toolz                             0.12.1tornado                           6.1tqdm                              4.62.2traitlets                         5.1.0twine                             3.4.2typing_extensions                 4.5.0tzdata                            2024.1urllib3                           1.26.6virtualenv                        20.7.2virtualenv-clone                  0.5.7wcwidth                           0.2.5webencodings                      0.5.1Werkzeug                          3.0.3wheel                             0.37.0wrapt                             1.12.1wurlitzer                         3.1.0zipp                              3.5.0

More attempts I think it is my python version is either to recent or not old enough

new instructions

python.exe -m pip install --upgrade pip

python -m venv myenv10myenv10\scripts\activate

try the newest versions but if that doesn't work these versions will work.pip install tensorflow==2.13.1pip install tensorflow-decision-forests==1.4.0pip install tensorflowjs==4.19.0 --no-deps

pip install tensorflow-decision-forests==1.8.0 --no-depspip install tensorflow-decision-forests==1.5.0

--ignore-installed tensorflow_decision_forests tensorflow tensorflow-io-gcs-filesystem tensorstore

tflite_convert --helptensorflowjs_converter --help

pip install tensorflowjs --no-deps

pip install tensorflowjs==4.19.0

pip install tensorflow==2.13.1pip install tensorflowjs==4.19.0

tflite_convert --helptensorflowjs_converter --help

#!/bin/bash

tensorflowjs_converter --input_format=tfjs_layers_model --output_format=keras_saved_model ./model.json ./tflite_convert --keras_model_file ./ --output_file ./model.tflitexxd -i model.tflite model.h

python.exe -m pip install --upgrade pippip3 install --upgrade pip

python -m venv myenv2myenv2\scripts\activate

pip3 install tensorflowjspip3 install tensorflow==2.15.0pip3 install tensorflow-hubpip3 install netron "dask[delayed]"

$env:TF_ENABLE_ONEDNN_OPTS=0

tflite_convert --helptensorflowjs_converter --help

xxd --help

https://sourceforge.net/projects/xxd-for-windows/

in power shell try
Format-Hex '.\your-file-name'

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp