From 8ac174e9e7dd95ae49900d6042e5ba5fec661e4b Mon Sep 17 00:00:00 2001 From: Alexandre Date: Wed, 12 Jun 2019 14:59:28 +0200 Subject: [PATCH] Package TensorFlow and TFLite models and checkpoints --- DeepSpeech/Dockerfile.train.fr | 3 ++- DeepSpeech/package.sh | 30 ++++++++++++++++++++++++++++++ DeepSpeech/run.sh | 2 ++ DeepSpeech/train_fr.sh | 4 +++- 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100755 DeepSpeech/package.sh diff --git a/DeepSpeech/Dockerfile.train.fr b/DeepSpeech/Dockerfile.train.fr index 389c84bf..723aa0e8 100644 --- a/DeepSpeech/Dockerfile.train.fr +++ b/DeepSpeech/Dockerfile.train.fr @@ -69,7 +69,8 @@ RUN apt-get -qq update && apt-get -qq install -y --no-install-recommends \ pixz \ sox \ libsox-fmt-all \ - locales locales-all + locales locales-all \ + zip RUN groupadd -g 999 trainer && \ adduser --system --uid 999 --group trainer diff --git a/DeepSpeech/package.sh b/DeepSpeech/package.sh new file mode 100755 index 00000000..03d25065 --- /dev/null +++ b/DeepSpeech/package.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +set -xe + +pushd /mnt + zip -r9 --junk-paths \ + model_tensorflow_fr.zip \ + models/output_graph.pbmm \ + models/alphabet.txt \ + lm/lm.binary \ + lm/trie + + zip -r9 --junk-paths \ + model_tflite_fr.zip \ + models/output_graph.tflite \ + models/alphabet.txt \ + lm/lm.binary \ + lm/trie + + all_checkpoint_path="" + for ckpt in $(grep 'all_model_checkpoint_paths' checkpoints/checkpoint | cut -d'"' -f2); + do + all_checkpoint_path="${all_checkpoint_path} ${ckpt}.*" + done; + + zip -r9 --junk-paths \ + checkpoint_fr.zip \ + checkpoints/checkpoint \ + ${all_checkpoint_path} +popd diff --git a/DeepSpeech/run.sh b/DeepSpeech/run.sh index 0d9eb93a..37a351e6 100755 --- a/DeepSpeech/run.sh +++ b/DeepSpeech/run.sh @@ -22,3 +22,5 @@ generate_alphabet.sh build_lm.sh train_fr.sh + +package.sh diff --git a/DeepSpeech/train_fr.sh b/DeepSpeech/train_fr.sh index 1e069ea4..d92cb62b 100755 --- a/DeepSpeech/train_fr.sh +++ b/DeepSpeech/train_fr.sh @@ -9,7 +9,9 @@ pushd $HOME/ds/ mkdir -p /mnt/sources/feature_cache || true - if [ -f "/transfer-checkpoint/checkpoint" ]; then + # Do not overwrite checkpoint file if model already exist: we will likely + # only package + if [ -f "/transfer-checkpoint/checkpoint" -a ! -f "/mnt/models/output_graph.pb" ]; then echo "Using checkpoint from ${TRANSFER_CHECKPOINT}" cp -a /transfer-checkpoint/* /mnt/checkpoints/ fi;