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

Upgrades to TF 2.2. Compat with TFLite. #141

Open
wants to merge 21 commits into
base: dev
Choose a base branch
from

Conversation

andreselizondo-adestech
Copy link

This is related to issue #66

Changes and notes:

  • Removed all pocketsphynx dependencies and scripts.
  • TF 2.x doesn't expose graphs/sessions (only if using tf.compat.v1). This fork makes things work without explicitly sharing sessions between TF and Keras.
  • TF 2.1 doesn't support GRU layers correctly for tflite. TF 2.2 is minimum requirement.
  • The only scripts I tested for compatibility are the ones I use:
    • precise-train (train keras model)
    • precise-convert (convert keras model to tflite)
    • precise-test (test keras or tflite models)
    • precise-listen (listen on keras or tflite models)
  • Added a TFLiteRunner that allows using tflite models with the previous scripts.
  • Added my custom training parameters for my model on scripts/train.py
  • I couldn't get TF 2.x to support TensorBoard. Decided it was not important.

Cleanup is still necessary.

Copy link
Collaborator

@forslund forslund left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting this, I'll flag this for @MatthewScholefield and @joshua-montgomery who knows more about precise.

You might want to sign the Mycroft CLA to make sure everything is alright (https://mycroft.ai/cla).

I also noticed the scripts with sh-bangs that could be executed lost the execution flag. Is that intended?

setup.sh Outdated Show resolved Hide resolved
setup.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@MatthewScholefield MatthewScholefield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great additions! Here's my view on the specific things you mentioned:

  • If TensorBoard doesn't work for now, we can just remove it like you've done
  • Unless there's a specific conflict, I don't see a reason to remove Pocketsphinx scripts. Removing the line in setup.sh is fine though. Since all imports are local, having the pocketsphinx scripts won't require any additional dependencies as long as the scripts aren't used.
  • Since it sounds like we would use TF 2.2.0+ regardless, the few comments at the locations I've tagged can probably be removed.

The only remaining part to be worked out would be testing things on a raspberry pi, like if the package installation works alright (and I suppose someone testing on their machine since I haven't done that yet).

precise/scripts/convert.py Outdated Show resolved Hide resolved
precise/scripts/train.py Outdated Show resolved Hide resolved
precise/scripts/train.py Outdated Show resolved Hide resolved
setup.py Outdated Show resolved Hide resolved
@andreselizondo-adestech
Copy link
Author

Thanks for submitting this, I'll flag this for @MatthewScholefield and @joshua-montgomery who knows more about precise.

You might want to sign the Mycroft CLA to make sure everything is alright (https://mycroft.ai/cla).

I also noticed the scripts with sh-bangs that could be executed lost the execution flag. Is that intended?

I have now signed the Mycroft CLA.

@krisgesling krisgesling added the CLA: Yes Contributor License Agreement exists (see https://github.com/MycroftAI/contributors) label Apr 15, 2020
@Tony763
Copy link

Tony763 commented Apr 18, 2020

Hello, I tried this from original repo.
When I run precise-convert hey-computer.net > it will generate just hey-computer.pb - hey-computer.pb.params is missing. Do I something wrong or it is bug.

@andreselizondo-adestech
Copy link
Author

Hello, I tried this from original repo.
When I run precise-convert hey-computer.net > it will generate just hey-computer.pb - hey-computer.pb.params is missing. Do I something wrong or it is bug.

When you run precise-convert hey-computer.net, the only output should be the file hey-computer.tflite. You should see in the execution logs Converting hey-computer.net to hey-computer.tflite...

@Tony763
Copy link

Tony763 commented Apr 18, 2020

Nope, started with fresh copy from andreselizondo-adestech:dev

precise-convert hey-mycroft_cz.net
Converting hey-mycroft_cz.net to hey-mycroft_cz.pb ...

@andreselizondo-adestech
Copy link
Author

Nope, started with fresh copy from andreselizondo-adestech:dev

precise-convert hey-mycroft_cz.net
Converting hey-mycroft_cz.net to hey-mycroft_cz.pb ...

I see what you're saying. We only need to change the default output file extension from pb to tflite.
However, the 'hey-mycroft_cz.pb' file you get as a result is really a '.tflite' model.
Try using precise-convert hey-mycroft_cz.net -o hey-mycroft_cz.tflite.

@Tony763
Copy link

Tony763 commented Apr 20, 2020

Another fresh copy from git:
precise-train-incremental subaru.net subaru/

Loading from subaru.net...
2020-04-20 20:57:50.799362: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory
2020-04-20 20:57:50.799384: E tensorflow/stream_executor/cuda/cuda_driver.cc:313] failed call to cuInit: UNKNOWN ERROR (303)
2020-04-20 20:57:50.799403: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (htpc-imon): /proc/driver/nvidia/version does not exist
2020-04-20 20:57:50.799567: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2020-04-20 20:57:50.823475: I tensorflow/core/platform/profile_utils/cpu_utils.cc:102] CPU Frequency: 3699850000 Hz
2020-04-20 20:57:50.823785: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7f8bd8000b60 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-04-20 20:57:50.823819: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
Loading wake-word...
Loading not-wake-word...
Loading wake-word...
Loading not-wake-word...
Loading from subaru.net...
Starting file data/random/boilinglentils.wav...
100%
Starting file data/random/pencil sharpening.wav...
70.6896551724138%%%
Saved to: subaru/not-wake-word/generated/pencil sharpening-123.wav
89.08045977011494%
Saved to: subaru/not-wake-word/generated/pencil sharpening-155.wav
89.65517241379311%
Saved to: subaru/not-wake-word/generated/pencil sharpening-156.wav
100%
Starting file data/random/plattenknistern.wav...
100%
Starting file data/random/helicopter.wav...
100%
Starting file data/random/motorbike-1.wav...
100%
Starting file data/random/train_doors_closing.wav...
100%
Starting file data/random/sunday-afternoon2.wav...
100%
Starting file data/random/shoulder_cracking.wav...
100%
Starting file data/random/july-rain08.wav...
100%
Starting file data/random/ursula.wav...
0.0%
Saved to: subaru/not-wake-word/generated/ursula-0.wav
0.29069767441860467%
Saved to: subaru/not-wake-word/generated/ursula-1.wav
0.5813953488372093%
Saved to: subaru/not-wake-word/generated/ursula-2.wav
0.872093023255814%
Saved to: subaru/not-wake-word/generated/ursula-3.wav
100%
Starting file data/random/babyrattle.wav...
1.6339869281045751%%
Saved to: subaru/not-wake-word/generated/babyrattle-10.wav
1.7973856209150327%
Saved to: subaru/not-wake-word/generated/babyrattle-11.wav
1.9607843137254901%
Saved to: subaru/not-wake-word/generated/babyrattle-12.wav
Loading wake-word...
Loading not-wake-word...
Loading wake-word...
Loading not-wake-word...

Train on 145 samples, validate on 8 samples
Epoch 2001/2001
145/145 [==============================] - 0s 3ms/step - loss: 0.1923 - accuracy: 0.9586 - val_loss: 0.0086 - val_accuracy: 1.0000
Traceback (most recent call last):
  File "/srv/mycroft-precise/.venv/bin/precise-train-incremental", line 11, in <module>
    load_entry_point('mycroft-precise', 'console_scripts', 'precise-train-incremental')()
  File "/srv/mycroft-precise/precise/scripts/base_script.py", line 49, in run_main
    script.run()
  File "/srv/mycroft-precise/precise/scripts/train_incremental.py", line 149, in run
    self.train_on_audio(fn)
  File "/srv/mycroft-precise/precise/scripts/train_incremental.py", line 136, in train_on_audio
    self.retrain()
  File "/srv/mycroft-precise/precise/scripts/train_incremental.py", line 110, in retrain
    self.listener.runner.model.save(self.args.model,save_format='h5')
TypeError: save() got an unexpected keyword argument 'save_format'

@andreselizondo-adestech
Copy link
Author

Another fresh copy from git:
precise-train-incremental subaru.net subaru/

Loading from subaru.net...
2020-04-20 20:57:50.799362: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory
2020-04-20 20:57:50.799384: E tensorflow/stream_executor/cuda/cuda_driver.cc:313] failed call to cuInit: UNKNOWN ERROR (303)
2020-04-20 20:57:50.799403: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (htpc-imon): /proc/driver/nvidia/version does not exist
2020-04-20 20:57:50.799567: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2020-04-20 20:57:50.823475: I tensorflow/core/platform/profile_utils/cpu_utils.cc:102] CPU Frequency: 3699850000 Hz
2020-04-20 20:57:50.823785: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7f8bd8000b60 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-04-20 20:57:50.823819: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
Loading wake-word...
Loading not-wake-word...
Loading wake-word...
Loading not-wake-word...
Loading from subaru.net...
Starting file data/random/boilinglentils.wav...
100%
Starting file data/random/pencil sharpening.wav...
70.6896551724138%%%
Saved to: subaru/not-wake-word/generated/pencil sharpening-123.wav
89.08045977011494%
Saved to: subaru/not-wake-word/generated/pencil sharpening-155.wav
89.65517241379311%
Saved to: subaru/not-wake-word/generated/pencil sharpening-156.wav
100%
Starting file data/random/plattenknistern.wav...
100%
Starting file data/random/helicopter.wav...
100%
Starting file data/random/motorbike-1.wav...
100%
Starting file data/random/train_doors_closing.wav...
100%
Starting file data/random/sunday-afternoon2.wav...
100%
Starting file data/random/shoulder_cracking.wav...
100%
Starting file data/random/july-rain08.wav...
100%
Starting file data/random/ursula.wav...
0.0%
Saved to: subaru/not-wake-word/generated/ursula-0.wav
0.29069767441860467%
Saved to: subaru/not-wake-word/generated/ursula-1.wav
0.5813953488372093%
Saved to: subaru/not-wake-word/generated/ursula-2.wav
0.872093023255814%
Saved to: subaru/not-wake-word/generated/ursula-3.wav
100%
Starting file data/random/babyrattle.wav...
1.6339869281045751%%
Saved to: subaru/not-wake-word/generated/babyrattle-10.wav
1.7973856209150327%
Saved to: subaru/not-wake-word/generated/babyrattle-11.wav
1.9607843137254901%
Saved to: subaru/not-wake-word/generated/babyrattle-12.wav
Loading wake-word...
Loading not-wake-word...
Loading wake-word...
Loading not-wake-word...

Train on 145 samples, validate on 8 samples
Epoch 2001/2001
145/145 [==============================] - 0s 3ms/step - loss: 0.1923 - accuracy: 0.9586 - val_loss: 0.0086 - val_accuracy: 1.0000
Traceback (most recent call last):
  File "/srv/mycroft-precise/.venv/bin/precise-train-incremental", line 11, in <module>
    load_entry_point('mycroft-precise', 'console_scripts', 'precise-train-incremental')()
  File "/srv/mycroft-precise/precise/scripts/base_script.py", line 49, in run_main
    script.run()
  File "/srv/mycroft-precise/precise/scripts/train_incremental.py", line 149, in run
    self.train_on_audio(fn)
  File "/srv/mycroft-precise/precise/scripts/train_incremental.py", line 136, in train_on_audio
    self.retrain()
  File "/srv/mycroft-precise/precise/scripts/train_incremental.py", line 110, in retrain
    self.listener.runner.model.save(self.args.model,save_format='h5')
TypeError: save() got an unexpected keyword argument 'save_format'

Hello @Tony763!
As mentioned in the initial description, the only scripts that I validated were working are:
precise-train (train keras model)
precise-convert (convert keras model to tflite)
precise-test (test keras or tflite models)
precise-listen (listen on keras or tflite models)

However I think I know what the error is, I'll take a look when I get a chance.

@Tony763
Copy link

Tony763 commented Apr 20, 2020

Yes, I did read before posting. I am just curious if you can do something with it.

Edit: I also tried to inject it to mycroft core with:
mycroft-pip install /srv/mycroft-precise
mycroft-pip install /srv/mycroft-precise/runner

Settings:

"listener": {
    "wake_word": "subaru"
  },
  "hotwords": {
    "subaru": {
        "module": "precise",
        "local_model_file": "/srv/mycroft-word/subaru.tflite"
    }
  },
~~~~23336 | mycroft.client.speech.hotword_factory:load_module:386 | Loading "wake up" wake word via pocketsphinx
 21:23:33.150 | INFO     | 23336 | mycroft.messagebus.client.client:on_open:67 | Connected
[23493] Failed to execute script engine
Traceback (most recent call last):
  File "precise/scripts/engine.py", line 64, in <module>
  File "precise/scripts/engine.py", line 52, in main
  File "precise/network_runner.py", line 90, in __init__
  File "precise/network_runner.py", line 102, in find_runner
ValueError: File extension of /srv/mycroft-word/subaru.tflite must be: ['.pb', '.net']

@andreselizondo-adestech
Copy link
Author

andreselizondo-adestech commented Apr 20, 2020

Yes, I did read before posting. I am just curious if you can do something with it.

Edit: I also tried to inject it to mycroft core with:
mycroft-pip install /srv/mycroft-precise
mycroft-pip install /srv/mycroft-precise/runner

Settings:

"listener": {
    "wake_word": "subaru"
  },
  "hotwords": {
    "subaru": {
        "module": "precise",
        "local_model_file": "/srv/mycroft-word/subaru.tflite"
    }
  },
~~~~23336 | mycroft.client.speech.hotword_factory:load_module:386 | Loading "wake up" wake word via pocketsphinx
 21:23:33.150 | INFO     | 23336 | mycroft.messagebus.client.client:on_open:67 | Connected
[23493] Failed to execute script engine
Traceback (most recent call last):
  File "precise/scripts/engine.py", line 64, in <module>
  File "precise/scripts/engine.py", line 52, in main
  File "precise/network_runner.py", line 90, in __init__
  File "precise/network_runner.py", line 102, in find_runner
ValueError: File extension of /srv/mycroft-word/subaru.tflite must be: ['.pb', '.net']

That must be because network_runner.py on Mycroft-Core doesn't have a TFLite Runner.
See the implementation on my version of network_runner.py. Also keep in mind that when it imports tensorflow, it's expecting tensorflow-runtime (tflite, 2.1.0 works well for me).
https://github.com/MycroftAI/mycroft-precise/pull/141/files#diff-fb894f744595c4e66870830a2942eb66R86-R115

@Tony763
Copy link

Tony763 commented Apr 20, 2020

Only network_runner.py I can find in mycroft-core is your, but still if I edit it change is not visible in mycroft core.

Edit:
Found it, mycroft load precise not from .venv but from home dir:

['/home/tony/.mycroft/precise/precise-engine/precise-engine', '/srv/mycroft-word/subaru.tflite', '2048']

Precise runner is taken from .venv

Edit 2: Not found it: I run sudo find / -name "network_runner.py"
It found 3 occurrences but none of them is actually used.

@andreselizondo-adestech
Copy link
Author

Only network_runner.py I can find in mycroft-core is your, but still if I edit it change is not visible in mycroft core.

Edit:
Found it, mycroft load precise not from .venv but from home dir:

['/home/tony/.mycroft/precise/precise-engine/precise-engine', '/srv/mycroft-word/subaru.tflite', '2048']

Precise runner is taken from .venv

Edit 2: Not found it: I run sudo find / -name "network_runner.py"
It found 3 occurrences but none of them is actually used.

Did you run the build.sh script? If so, you might be running the precise-engine binary from before you changed network_runner.py. If you're using precise-engine.py, the script itself should be importing precise.network_runner (the file network_runner.py, inside the folder 'precise'). From there, Listener should have a find_runner function that needs to have a registered TFLiteRunner runner.

Please delete the folders dist and .venv After this, run setup.sh. Then run precise-listen /srv/mycroft-word/subaru.tflite

Note: I didn't actually run these commands but rather wrote them from memory. Please tell me if something goes wrong.

@emphasize
Copy link

emphasize commented Jul 18, 2020

***** EDITED; reason below

Anyhow, for my ArchLinux VM (tf2.2): It throws an error running
./precise-train-incremental samira.net /media/sf_share/samira/

AttributeError: 'list' object has no attribute 'items'

Edited because this is clearly a matter of wanting to train an old (1.13.2 in this case) model
This issue is known and further discussed here

@MatthewScholefield
Copy link
Collaborator

@emphasize There's 2.2.0 for armv7l on python 3.5. For Python 3.7 (what my pi 3 had), you can use custom builds:

pip3 install https://github.com/lhelontra/tensorflow-on-arm/releases/download/v2.2.0/tensorflow-2.2.0-cp37-none-linux_armv7l.whl

@tadly This is fixed in my PR-to-the-PR

@emphasize
Copy link

emphasize commented Jul 19, 2020

@MatthewScholefield

I got my pi going with some custom wheel from here

It is a 2.2 without GPU support (I see that lhelontras' is also no _gpu). Is that relevant in our use case?

@MatthewScholefield
Copy link
Collaborator

MatthewScholefield commented Jul 19, 2020

Not sure why anyone would want gpu support on a pi, so I'd assume both are fine :)

@Tony763
Copy link

Tony763 commented Jul 19, 2020

Not sure why anyone would want gpu support on a pi, so I'd assume both are fine :)

For NVIDIA Jetson Nano Developer Kit, verze B01 gpu support would be interesting.

@emphasize
Copy link

emphasize commented Jul 19, 2020

_gpu-2.2.0 is default by now. Once the pi guys come up to speed architecture-specific dependencies will be the way to go.
(oh, i totally spaced that the jetson nano is running on arm)

@emphasize
Copy link

emphasize commented Jul 20, 2020

@andreselizondo-adestech @MatthewScholefield

Encoutered a problem with ./precise-train-incremental , respectivly the model itself. (New 2.2 trained model)

using: ./precise-train-incremental -r /media/sf_share/samira/data/random/ samira/ /media/sf_share/samira/

the new precise-train [args] _destination_ _source_ creates a new folder structure and dropping the model in the destination folder. In the process it also converts it to pb. Although precise-train-incremental is looking for a pb at the right places** it throws

Warning: Unknown model type,  samira/
usage: precise-train-incremental [-h] [-e EPOCHS] [-ds DELAY_SAMPLES] [-c CHUNK_SIZE] [-r RANDOM_DATA_FOLDER] [-th THRESHOLD] [-sf SAMPLES_FILE] [-is]
                                 [-s SENSITIVITY] [-b BATCH_SIZE] [-sb] [-nv] [-mm METRIC_MONITOR] [-em] [-f FREEZE_TILL] [-tf TAGS_FOLDER] [-tg TAGS_FILE]
                                 model folder

precise-train-incremental: error: Error parsing args: Unknown loss function:weighted_log_loss 

sounds like #

** Purposely passed the wrong destination arg samira/saved_model.pb with the output SavedModel file does not exist at: samira/saved_model.pb/{saved_model.pbtxt|saved_model.pb}

(Additionally: Is the [-r RANDOM_DATA_FOLDER] flag even necessary to point out ?)

@emphasize
Copy link

emphasize commented Jul 20, 2020

@MatthewScholefield

To feedback using your PR-to-the-PR code regarding #660991718 partially engages the problem, but the save process has to be adjusted to the new folder structure (<- also the cause of "Warning: unknown modeltype, samira/", besides if not model_name.endswith('.net') (#) and beyond that a few things with model_name involved.

folder structure

(further clarification: Model trained with /.precise-train samira /media/sf_share/samira/ ; samira.epoch, samira.params and samira.trained.txt are stored in the basedirectory

Loading wake-word...
Loading not-wake-word...
Loading wake-word...
Loading not-wake-word...
Warning: Unknown model type, samira/
Warning: Unknown model type, samira/

Starting file /media/sf_share/samira/data/random/samira-211.wav...
22.22222222222222%%
Saved to: /media/sf_share/samira/not-wake-word/generated/samira-211-4.wav
33.333333333333336%
...
Loading wake-word...
Loading not-wake-word...
Loading wake-word...
Loading not-wake-word...

1/1 [==============================] - ETA: 0s - loss: 0.1472 - accuracy: 0.94412020-07-20 17:09:59.168948: W tensorflow/python/util/util.cc:329] Sets are not currently considered sequences, but this may change in the future, so consider avoiding using them.
WARNING:tensorflow:From /home/swen/mycroft-precise/.venv/lib/python3.8/site-packages/tensorflow/python/ops/resource_variable_ops.py:1813: calling BaseResourceVariable.init (from tensorflow.python.ops.resource_variable_ops) with constraint is deprecated and will be removed in a future version.
Instructions for updating:
If using Keras pass *_constraint arguments to layers.
1/1 [==============================] - 2s 2s/step - loss: 0.1472 - accuracy: 0.9441 - val_loss: 0.0206 - val_accuracy: 1.0000
Traceback (most recent call last):
File "./precise-train-incremental", line 33, in
sys.exit(load_entry_point('mycroft-precise', 'console_scripts', 'precise-train-incremental')())
File "/home/swen/mycroft-precise/precise/scripts/base_script.py", line 49, in run_main
script.run()
File "/home/swen/mycroft-precise/precise/scripts/train_incremental.py", line 149, in run
self.train_on_audio(fn)
File "/home/swen/mycroft-precise/precise/scripts/train_incremental.py", line 136, in train_on_audio
self.retrain()
File "/home/swen/mycroft-precise/precise/scripts/train_incremental.py", line 110, in retrain
self.listener.runner.model.save(self.args.model,save_format='h5')
File "/home/swen/mycroft-precise/.venv/lib/python3.8/site-packages/tensorflow/python/keras/engine/network.py", line 1051, in save
save.save_model(self, filepath, overwrite, include_optimizer, save_format,
File "/home/swen/mycroft-precise/.venv/lib/python3.8/site-packages/tensorflow/python/keras/saving/save.py", line 134, in save_model
hdf5_format.save_model_to_hdf5(
File "/home/swen/mycroft-precise/.venv/lib/python3.8/site-packages/tensorflow/python/keras/saving/hdf5_format.py", line 102, in save_model_to_hdf5
f = h5py.File(filepath, mode='w')
File "/home/swen/mycroft-precise/.venv/lib/python3.8/site-packages/h5py/_hl/files.py", line 406, in init
fid = make_fid(name, mode, userblock_size,
File "/home/swen/mycroft-precise/.venv/lib/python3.8/site-packages/h5py/_hl/files.py", line 179, in make_fid
fid = h5f.create(name, h5f.ACC_TRUNC, fapl=fapl, fcpl=fcpl)
File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
File "h5py/h5f.pyx", line 108, in h5py.h5f.create
OSError: Unable to create file (unable to open file: name = 'samira/', errno = 21, error message = 'Is a directory', flags = 13, o_flags = 242)

@emphasize
Copy link

emphasize commented Jul 20, 2020

For PB Models it seems like you can resolve this by changing

self.listener.runner.model.save(self.args.model)
to
self.listener.runner.model.save(self.args.model+'/')
(train_incremental.py)

training models with
./precise-train [params] modelname path/to/modelname-files
resp. (re)training against random files with
./precise-train-incremental [params] modelname path/to/modelname-files

I've jet run several passes against random data, but not tested if the pb is usable.

@andreselizondo-adestech
Copy link
Author

@emphasize
Sorry for the delay.
Indeed, adding a '/' solves the problem for .pb models, but that's not the case for Keras models.
The solution to this would be to provide input path to the model as a directory. This is because '.pb' models are stored in directories and to be read, the directory should be passed as argument.

In your example, use: precise-train samira/ /media/sf_share/samira/
The difference being that the model name now includes '/'

@andreselizondo-adestech
Copy link
Author

@MatthewScholefield
I think I've finished the things that were pending. What's missing? How can I help?

@el-tocino
Copy link

el-tocino commented Sep 11, 2020

During precise-convert, the model.net.params could also be copied to model.tflite.params to avoid the warning about the missing params file.

@sushipan
Copy link

sushipan commented Nov 9, 2020

Great job ! Will you plan to support multiple wake words on tf2.x version @andreselizondo-adestech

@Waarbubble
Copy link

Waarbubble commented Mar 1, 2021

The numpy dependency needs to be fixed at 1.18.2 as 1.20 has some low level changes that doesn't play nicely with tensorflow 2.2. resulting in a

NotImplementedError: Cannot convert a symbolic Tensor (lstm_2/strided_slice:0) to a numpy array.

when running precise-train

@el-tocino
Copy link

TF2.2 is also now out of date, 2.4.1 is current. Might need a bump in other versions to go with for things to all play nice again.

@dumblob
Copy link

dumblob commented Oct 22, 2021

This would be great addition as deploying & using mycroft-precise is getting rather difficult on current systems. Anyone from @MycroftAI who would pick up the gauntlet (@andreselizondo-adestech did a lot of work here, so it seems it's more about upstream).

@JarbasAl
Copy link

Recently the OVOS team did a bunch of work for tflite, tflite can be used in any mycroft install already, these links might be useful

@krisgesling
Copy link
Contributor

Hey there, I've allocated this to a team member as they've also been doing work on it so I'm hoping we'll be able to merge this in to be the new Precise standard.

Very much appreciate all the work you put into it @andreselizondo-adestech!
And also to @JarbasAl for their TFlite versions of repo's.

The difference in resource usage is nothing short of remarkable 👏

@krisgesling
Copy link
Contributor

I should also note that there has been an official TFlite plugin in the works:
https://github.com/MycroftAI/plugin-wake-word-precise-lite

But I wouldn't use it just yet, there's a resource leakage issue that slowly consumes more resources until the service crashes.

@ShamoX
Copy link

ShamoX commented Jul 21, 2022

Hello,

Since I need that project, I decided to fork and advance. Sorry for the inconvenience but it can be reversed if Mycroft wants of course).

You will find your PR already integrated to the fork here. Sadly I had to do it while I was working on making gitlab-ci works...

Again, sorry for the inconvenient. I created a thread on Mycroft community forum to discuss this.

@tystuyfzand
Copy link

tystuyfzand commented Dec 5, 2022

@JarbasAl

Precise-Lite is a great improvement, though it still has issues.

One is the "fix" to save it as h5, it saves it as a file then attempts to rename it to a folder, which doesn't work. Perhaps we should just swap to use h5 instead of a directory for the initial un-converted model?

Edit: h5 is old and deprecated, I guess just make it work as a folder.

It also fails on utf-8 file names sadly, so any datasets that have a file containing special characters will fail due to numpy's caching on the filenames.

@rbrisita
Copy link

Anyone reading this that wants to build from source, try these steps:

  1. git clone https://github.com/MycroftAI/mycroft-precise.git
  2. cd mycroft-precise
  3. python3 -m venv .venv
  4. source .venv/bin/activate
  5. python3 -m pip install --upgrade pip
  6. pip install wheel
  7. git fetch origin pull/141/head:tf
  8. git checkout tf
  9. edit setup.py and change tensorflow-gpu to tensorflow with no pinning.
  10. ./setup.sh

@JarbasAl
Copy link

in OVOS we are using this https://github.com/OpenVoiceOS/precise-lite-trainer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA: Yes Contributor License Agreement exists (see https://github.com/MycroftAI/contributors)
Projects
No open projects
Status: High priority
Development

Successfully merging this pull request may close these issues.