Upload 58 files
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +23 -0
- models/README.md +5 -0
- models/char-clas/cz/Bi-RNN/checkpoint +2 -0
- models/char-clas/cz/Bi-RNN/model_2.data-00000-of-00001 +3 -0
- models/char-clas/cz/Bi-RNN/model_2.index +0 -0
- models/char-clas/cz/Bi-RNN/model_2.meta +3 -0
- models/char-clas/cz/CharClassifier.data-00000-of-00001 +3 -0
- models/char-clas/cz/CharClassifier.index +0 -0
- models/char-clas/cz/CharClassifier.meta +0 -0
- models/char-clas/cz/checkpoint +2 -0
- models/char-clas/en/Bi-RNN/checkpoint +2 -0
- models/char-clas/en/Bi-RNN/model_1.data-00000-of-00001 +3 -0
- models/char-clas/en/Bi-RNN/model_1.index +0 -0
- models/char-clas/en/Bi-RNN/model_1.meta +3 -0
- models/char-clas/en/CharClassifier.data-00000-of-00001 +3 -0
- models/char-clas/en/CharClassifier.index +0 -0
- models/char-clas/en/CharClassifier.meta +0 -0
- models/char-clas/en/checkpoint +2 -0
- models/freeze_graph.py +263 -0
- models/gap-clas/A-RNN/checkpoint +2 -0
- models/gap-clas/A-RNN/model.data-00000-of-00001 +3 -0
- models/gap-clas/A-RNN/model.index +0 -0
- models/gap-clas/A-RNN/model.meta +3 -0
- models/gap-clas/Bi-RNN.data-00000-of-00001 +3 -0
- models/gap-clas/Bi-RNN.index +0 -0
- models/gap-clas/Bi-RNN.meta +0 -0
- models/gap-clas/CNN-CG.data-00000-of-00001 +3 -0
- models/gap-clas/CNN-CG.index +0 -0
- models/gap-clas/CNN-CG.meta +0 -0
- models/gap-clas/RNN-A/Bi-RNN.data-00000-of-00001 +3 -0
- models/gap-clas/RNN-A/Bi-RNN.index +0 -0
- models/gap-clas/RNN-A/Bi-RNN.meta +3 -0
- models/gap-clas/RNN-A/checkpoint +2 -0
- models/gap-clas/RNN/Bi-RNN-new.data-00000-of-00001 +3 -0
- models/gap-clas/RNN/Bi-RNN-new.index +0 -0
- models/gap-clas/RNN/Bi-RNN-new.meta +3 -0
- models/gap-clas/RNN/checkpoint +2 -0
- models/gap-clas/checkpoint +2 -0
- models/gap-clas/large/CNN-CG.data-00000-of-00001 +3 -0
- models/gap-clas/large/CNN-CG.index +0 -0
- models/gap-clas/large/CNN-CG.meta +0 -0
- models/gap-clas/large/checkpoint +2 -0
- models/graph_optimizer.py +87 -0
- models/word-clas/CTC/Classifier1.data-00000-of-00001 +3 -0
- models/word-clas/CTC/Classifier1.index +0 -0
- models/word-clas/CTC/Classifier1.meta +3 -0
- models/word-clas/CTC/checkpoint +6 -0
- models/word-clas/en/CTC/Classifier2.data-00000-of-00001 +3 -0
- models/word-clas/en/CTC/Classifier2.index +0 -0
- models/word-clas/en/CTC/Classifier2.meta +3 -0
.gitattributes
CHANGED
|
@@ -40,3 +40,26 @@ output.mp3 filter=lfs diff=lfs merge=lfs -text
|
|
| 40 |
requirements.txt filter=lfs diff=lfs merge=lfs -text
|
| 41 |
sample.mp3 filter=lfs diff=lfs merge=lfs -text
|
| 42 |
text2speech.mp3 filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
requirements.txt filter=lfs diff=lfs merge=lfs -text
|
| 41 |
sample.mp3 filter=lfs diff=lfs merge=lfs -text
|
| 42 |
text2speech.mp3 filter=lfs diff=lfs merge=lfs -text
|
| 43 |
+
models/char-clas/cz/Bi-RNN/model_2.data-00000-of-00001 filter=lfs diff=lfs merge=lfs -text
|
| 44 |
+
models/char-clas/cz/Bi-RNN/model_2.meta filter=lfs diff=lfs merge=lfs -text
|
| 45 |
+
models/char-clas/cz/CharClassifier.data-00000-of-00001 filter=lfs diff=lfs merge=lfs -text
|
| 46 |
+
models/char-clas/en/Bi-RNN/model_1.data-00000-of-00001 filter=lfs diff=lfs merge=lfs -text
|
| 47 |
+
models/char-clas/en/Bi-RNN/model_1.meta filter=lfs diff=lfs merge=lfs -text
|
| 48 |
+
models/char-clas/en/CharClassifier.data-00000-of-00001 filter=lfs diff=lfs merge=lfs -text
|
| 49 |
+
models/gap-clas/A-RNN/model.data-00000-of-00001 filter=lfs diff=lfs merge=lfs -text
|
| 50 |
+
models/gap-clas/A-RNN/model.meta filter=lfs diff=lfs merge=lfs -text
|
| 51 |
+
models/gap-clas/Bi-RNN.data-00000-of-00001 filter=lfs diff=lfs merge=lfs -text
|
| 52 |
+
models/gap-clas/CNN-CG.data-00000-of-00001 filter=lfs diff=lfs merge=lfs -text
|
| 53 |
+
models/gap-clas/large/CNN-CG.data-00000-of-00001 filter=lfs diff=lfs merge=lfs -text
|
| 54 |
+
models/gap-clas/RNN-A/Bi-RNN.data-00000-of-00001 filter=lfs diff=lfs merge=lfs -text
|
| 55 |
+
models/gap-clas/RNN-A/Bi-RNN.meta filter=lfs diff=lfs merge=lfs -text
|
| 56 |
+
models/gap-clas/RNN/Bi-RNN-new.data-00000-of-00001 filter=lfs diff=lfs merge=lfs -text
|
| 57 |
+
models/gap-clas/RNN/Bi-RNN-new.meta filter=lfs diff=lfs merge=lfs -text
|
| 58 |
+
models/word-clas/CTC/Classifier1.data-00000-of-00001 filter=lfs diff=lfs merge=lfs -text
|
| 59 |
+
models/word-clas/CTC/Classifier1.meta filter=lfs diff=lfs merge=lfs -text
|
| 60 |
+
models/word-clas/en/CTC/Classifier2.data-00000-of-00001 filter=lfs diff=lfs merge=lfs -text
|
| 61 |
+
models/word-clas/en/CTC/Classifier2.meta filter=lfs diff=lfs merge=lfs -text
|
| 62 |
+
models/word-clas/en/SeqRNN/Classifier.data-00000-of-00001 filter=lfs diff=lfs merge=lfs -text
|
| 63 |
+
models/word-clas/en/SeqRNN/Classifier.meta filter=lfs diff=lfs merge=lfs -text
|
| 64 |
+
models/word-clas/en/WordClassifier2.data-00000-of-00001 filter=lfs diff=lfs merge=lfs -text
|
| 65 |
+
models/word-clas/en/WordClassifier2.meta filter=lfs diff=lfs merge=lfs -text
|
models/README.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Machine Learning Models
|
| 2 |
+
You have to donwload pre-trained ML models before using some of the notebooks.
|
| 3 |
+
|
| 4 |
+
Download and extract the models in this folder:
|
| 5 |
+
<https://drive.google.com/file/d/1YbmsiJK3Wclfm6K8PrJuz-QROEKX1qis/view?usp=sharing>
|
models/char-clas/cz/Bi-RNN/checkpoint
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
model_checkpoint_path: "model_2"
|
| 2 |
+
all_model_checkpoint_paths: "model_2"
|
models/char-clas/cz/Bi-RNN/model_2.data-00000-of-00001
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c54a4b4c8d925bee557917ffa2d1f43befdc21035e8fe0b482caf2aa9051bf20
|
| 3 |
+
size 145353836
|
models/char-clas/cz/Bi-RNN/model_2.index
ADDED
|
Binary file (2.64 kB). View file
|
|
|
models/char-clas/cz/Bi-RNN/model_2.meta
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cae04a4752de5f50f2928d8eadb1fc0a68a6bd4b26dd936a94d5f4852b02532e
|
| 3 |
+
size 1864590
|
models/char-clas/cz/CharClassifier.data-00000-of-00001
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:921c2981f453c8bd09a278142d10fe0b0ec54b34f00b6b99527bd7990e04ee0f
|
| 3 |
+
size 6745052
|
models/char-clas/cz/CharClassifier.index
ADDED
|
Binary file (1.86 kB). View file
|
|
|
models/char-clas/cz/CharClassifier.meta
ADDED
|
Binary file (174 kB). View file
|
|
|
models/char-clas/cz/checkpoint
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
model_checkpoint_path: "CharClassifier"
|
| 2 |
+
all_model_checkpoint_paths: "CharClassifier"
|
models/char-clas/en/Bi-RNN/checkpoint
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
model_checkpoint_path: "model_1"
|
| 2 |
+
all_model_checkpoint_paths: "model_1"
|
models/char-clas/en/Bi-RNN/model_1.data-00000-of-00001
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fd3a4cb72afd75b88dafacf6de6e53086724b3bbdcc19a6f68f073a35952b1ed
|
| 3 |
+
size 145169156
|
models/char-clas/en/Bi-RNN/model_1.index
ADDED
|
Binary file (2.64 kB). View file
|
|
|
models/char-clas/en/Bi-RNN/model_1.meta
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7d7924276bbfa6a042d76638152276aa05d4a15061a9a28aab4e89bf231c8e89
|
| 3 |
+
size 1861142
|
models/char-clas/en/CharClassifier.data-00000-of-00001
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:79e8d85a7810fe30bfea4c9a474787ada5988a8b85202b5b1542b93e6de4159c
|
| 3 |
+
size 4440692
|
models/char-clas/en/CharClassifier.index
ADDED
|
Binary file (1.86 kB). View file
|
|
|
models/char-clas/en/CharClassifier.meta
ADDED
|
Binary file (177 kB). View file
|
|
|
models/char-clas/en/checkpoint
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
model_checkpoint_path: "CharClassifier"
|
| 2 |
+
all_model_checkpoint_paths: "CharClassifier"
|
models/freeze_graph.py
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# EDITED on 10. 9. 2017 for meta graph freezing
|
| 2 |
+
#
|
| 3 |
+
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
|
| 4 |
+
#
|
| 5 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 6 |
+
# you may not use this file except in compliance with the License.
|
| 7 |
+
# You may obtain a copy of the License at
|
| 8 |
+
#
|
| 9 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
#
|
| 11 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
# See the License for the specific language governing permissions and
|
| 15 |
+
# limitations under the License.
|
| 16 |
+
# ==============================================================================
|
| 17 |
+
"""Converts checkpoint variables into Const ops in a standalone GraphDef file.
|
| 18 |
+
|
| 19 |
+
This script is designed to take a GraphDef proto, a SaverDef proto, and a set of
|
| 20 |
+
variable values stored in a checkpoint file, and output a GraphDef with all of
|
| 21 |
+
the variable ops converted into const ops containing the values of the
|
| 22 |
+
variables.
|
| 23 |
+
|
| 24 |
+
It's useful to do this when we need to load a single file in C++, especially in
|
| 25 |
+
environments like mobile or embedded where we may not have access to the
|
| 26 |
+
RestoreTensor ops and file loading calls that they rely on.
|
| 27 |
+
|
| 28 |
+
An example of command-line usage is:
|
| 29 |
+
bazel build tensorflow/python/tools:freeze_graph && \
|
| 30 |
+
bazel-bin/tensorflow/python/tools/freeze_graph \
|
| 31 |
+
--input_graph=some_graph_def.pb \
|
| 32 |
+
--input_checkpoint=model.ckpt-8361242 \
|
| 33 |
+
--output_graph=/tmp/frozen_graph.pb --output_node_names=softmax
|
| 34 |
+
|
| 35 |
+
You can also look at freeze_graph_test.py for an example of how to use it.
|
| 36 |
+
|
| 37 |
+
"""
|
| 38 |
+
from __future__ import absolute_import
|
| 39 |
+
from __future__ import division
|
| 40 |
+
from __future__ import print_function
|
| 41 |
+
|
| 42 |
+
import argparse
|
| 43 |
+
import sys
|
| 44 |
+
|
| 45 |
+
from google.protobuf import text_format
|
| 46 |
+
|
| 47 |
+
from tensorflow.contrib.saved_model.python.saved_model import reader
|
| 48 |
+
from tensorflow.core.framework import graph_pb2
|
| 49 |
+
from tensorflow.core.protobuf import saver_pb2
|
| 50 |
+
from tensorflow.core.protobuf.meta_graph_pb2 import MetaGraphDef
|
| 51 |
+
from tensorflow.python import pywrap_tensorflow
|
| 52 |
+
from tensorflow.python.client import session
|
| 53 |
+
from tensorflow.python.framework import graph_util
|
| 54 |
+
from tensorflow.python.framework import importer
|
| 55 |
+
from tensorflow.python.platform import app
|
| 56 |
+
from tensorflow.python.platform import gfile
|
| 57 |
+
from tensorflow.python.saved_model import loader
|
| 58 |
+
from tensorflow.python.saved_model import tag_constants
|
| 59 |
+
from tensorflow.python.training import saver as saver_lib
|
| 60 |
+
|
| 61 |
+
FLAGS = None
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def freeze_graph_with_def_protos(input_graph_def,
|
| 65 |
+
input_saver_def,
|
| 66 |
+
input_checkpoint,
|
| 67 |
+
output_node_names,
|
| 68 |
+
restore_op_name,
|
| 69 |
+
filename_tensor_name,
|
| 70 |
+
output_graph,
|
| 71 |
+
clear_devices,
|
| 72 |
+
initializer_nodes,
|
| 73 |
+
variable_names_blacklist="",
|
| 74 |
+
input_meta_graph_def=None,
|
| 75 |
+
input_saved_model_dir=None,
|
| 76 |
+
saved_model_tags=None):
|
| 77 |
+
"""Converts all variables in a graph and checkpoint into constants."""
|
| 78 |
+
del restore_op_name, filename_tensor_name # Unused by updated loading code.
|
| 79 |
+
|
| 80 |
+
# 'input_checkpoint' may be a prefix if we're using Saver V2 format
|
| 81 |
+
if (not input_saved_model_dir and
|
| 82 |
+
not saver_lib.checkpoint_exists(input_checkpoint)):
|
| 83 |
+
print("Input checkpoint '" + input_checkpoint + "' doesn't exist!")
|
| 84 |
+
return -1
|
| 85 |
+
|
| 86 |
+
if not output_node_names:
|
| 87 |
+
print("You need to supply the name of a node to --output_node_names.")
|
| 88 |
+
return -1
|
| 89 |
+
|
| 90 |
+
# Remove all the explicit device specifications for this node. This helps to
|
| 91 |
+
# make the graph more portable.
|
| 92 |
+
if clear_devices:
|
| 93 |
+
if input_meta_graph_def:
|
| 94 |
+
for node in input_meta_graph_def.graph_def.node:
|
| 95 |
+
node.device = ""
|
| 96 |
+
elif input_graph_def:
|
| 97 |
+
for node in input_graph_def.node:
|
| 98 |
+
node.device = ""
|
| 99 |
+
|
| 100 |
+
if input_graph_def:
|
| 101 |
+
_ = importer.import_graph_def(input_graph_def, name="")
|
| 102 |
+
with session.Session() as sess:
|
| 103 |
+
if input_saver_def:
|
| 104 |
+
saver = saver_lib.Saver(saver_def=input_saver_def)
|
| 105 |
+
saver.restore(sess, input_checkpoint)
|
| 106 |
+
elif input_meta_graph_def:
|
| 107 |
+
restorer = saver_lib.import_meta_graph(
|
| 108 |
+
input_meta_graph_def, clear_devices=True)
|
| 109 |
+
restorer.restore(sess, input_checkpoint)
|
| 110 |
+
if initializer_nodes:
|
| 111 |
+
sess.run(initializer_nodes.split(","))
|
| 112 |
+
elif input_saved_model_dir:
|
| 113 |
+
if saved_model_tags is None:
|
| 114 |
+
saved_model_tags = []
|
| 115 |
+
loader.load(sess, saved_model_tags, input_saved_model_dir)
|
| 116 |
+
else:
|
| 117 |
+
var_list = {}
|
| 118 |
+
reader = pywrap_tensorflow.NewCheckpointReader(input_checkpoint)
|
| 119 |
+
var_to_shape_map = reader.get_variable_to_shape_map()
|
| 120 |
+
for key in var_to_shape_map:
|
| 121 |
+
try:
|
| 122 |
+
tensor = sess.graph.get_tensor_by_name(key + ":0")
|
| 123 |
+
except KeyError:
|
| 124 |
+
# This tensor doesn't exist in the graph (for example it's
|
| 125 |
+
# 'global_step' or a similar housekeeping element) so skip it.
|
| 126 |
+
continue
|
| 127 |
+
var_list[key] = tensor
|
| 128 |
+
saver = saver_lib.Saver(var_list=var_list)
|
| 129 |
+
saver.restore(sess, input_checkpoint)
|
| 130 |
+
if initializer_nodes:
|
| 131 |
+
sess.run(initializer_nodes.split(","))
|
| 132 |
+
|
| 133 |
+
variable_names_blacklist = (variable_names_blacklist.split(",")
|
| 134 |
+
if variable_names_blacklist else None)
|
| 135 |
+
|
| 136 |
+
if input_meta_graph_def:
|
| 137 |
+
output_graph_def = graph_util.convert_variables_to_constants(
|
| 138 |
+
sess,
|
| 139 |
+
input_meta_graph_def.graph_def,
|
| 140 |
+
output_node_names.split(","),
|
| 141 |
+
variable_names_blacklist=variable_names_blacklist)
|
| 142 |
+
else:
|
| 143 |
+
output_graph_def = graph_util.convert_variables_to_constants(
|
| 144 |
+
sess,
|
| 145 |
+
input_graph_def,
|
| 146 |
+
output_node_names.split(","),
|
| 147 |
+
variable_names_blacklist=variable_names_blacklist)
|
| 148 |
+
|
| 149 |
+
# Write GraphDef to file if output path has been given.
|
| 150 |
+
if output_graph:
|
| 151 |
+
with gfile.GFile(output_graph, "wb") as f:
|
| 152 |
+
f.write(output_graph_def.SerializeToString())
|
| 153 |
+
|
| 154 |
+
return output_graph_def
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
def _parse_input_graph_proto(input_graph, input_binary):
|
| 158 |
+
"""Parser input tensorflow graph into GraphDef proto."""
|
| 159 |
+
if not gfile.Exists(input_graph):
|
| 160 |
+
print("Input graph file '" + input_graph + "' does not exist!")
|
| 161 |
+
return -1
|
| 162 |
+
input_graph_def = graph_pb2.GraphDef()
|
| 163 |
+
mode = "rb" if input_binary else "r"
|
| 164 |
+
with gfile.FastGFile(input_graph, mode) as f:
|
| 165 |
+
if input_binary:
|
| 166 |
+
input_graph_def.ParseFromString(f.read())
|
| 167 |
+
else:
|
| 168 |
+
text_format.Merge(f.read(), input_graph_def)
|
| 169 |
+
return input_graph_def
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
def _parse_input_meta_graph_proto(input_graph, input_binary):
|
| 173 |
+
"""Parser input tensorflow graph into MetaGraphDef proto."""
|
| 174 |
+
if not gfile.Exists(input_graph):
|
| 175 |
+
print("Input meta graph file '" + input_graph + "' does not exist!")
|
| 176 |
+
return -1
|
| 177 |
+
input_meta_graph_def = MetaGraphDef()
|
| 178 |
+
mode = "rb" if input_binary else "r"
|
| 179 |
+
with gfile.FastGFile(input_graph, mode) as f:
|
| 180 |
+
if input_binary:
|
| 181 |
+
input_meta_graph_def.ParseFromString(f.read())
|
| 182 |
+
else:
|
| 183 |
+
text_format.Merge(f.read(), input_meta_graph_def)
|
| 184 |
+
print("Loaded meta graph file '" + input_graph)
|
| 185 |
+
return input_meta_graph_def
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
def _parse_input_saver_proto(input_saver, input_binary):
|
| 189 |
+
"""Parser input tensorflow Saver into SaverDef proto."""
|
| 190 |
+
if not gfile.Exists(input_saver):
|
| 191 |
+
print("Input saver file '" + input_saver + "' does not exist!")
|
| 192 |
+
return -1
|
| 193 |
+
mode = "rb" if input_binary else "r"
|
| 194 |
+
with gfile.FastGFile(input_saver, mode) as f:
|
| 195 |
+
saver_def = saver_pb2.SaverDef()
|
| 196 |
+
if input_binary:
|
| 197 |
+
saver_def.ParseFromString(f.read())
|
| 198 |
+
else:
|
| 199 |
+
text_format.Merge(f.read(), saver_def)
|
| 200 |
+
return saver_def
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
def get_meta_graph_def(saved_model_dir, tag_set):
|
| 204 |
+
"""Gets MetaGraphDef from SavedModel.
|
| 205 |
+
|
| 206 |
+
Returns the MetaGraphDef for the given tag-set and SavedModel directory.
|
| 207 |
+
|
| 208 |
+
Args:
|
| 209 |
+
saved_model_dir: Directory containing the SavedModel to inspect or execute.
|
| 210 |
+
tag_set: Group of tag(s) of the MetaGraphDef to load, in string format,
|
| 211 |
+
separated by ','. For tag-set contains multiple tags, all tags must be
|
| 212 |
+
passed in.
|
| 213 |
+
|
| 214 |
+
Raises:
|
| 215 |
+
RuntimeError: An error when the given tag-set does not exist in the
|
| 216 |
+
SavedModel.
|
| 217 |
+
|
| 218 |
+
Returns:
|
| 219 |
+
A MetaGraphDef corresponding to the tag-set.
|
| 220 |
+
"""
|
| 221 |
+
saved_model = reader.read_saved_model(saved_model_dir)
|
| 222 |
+
set_of_tags = set(tag_set.split(','))
|
| 223 |
+
for meta_graph_def in saved_model.meta_graphs:
|
| 224 |
+
if set(meta_graph_def.meta_info_def.tags) == set_of_tags:
|
| 225 |
+
return meta_graph_def
|
| 226 |
+
|
| 227 |
+
raise RuntimeError('MetaGraphDef associated with tag-set ' + tag_set +
|
| 228 |
+
' could not be found in SavedModel')
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
def freeze_graph(input_graph,
|
| 232 |
+
input_saver,
|
| 233 |
+
input_binary,
|
| 234 |
+
input_checkpoint,
|
| 235 |
+
output_node_names,
|
| 236 |
+
restore_op_name,
|
| 237 |
+
filename_tensor_name,
|
| 238 |
+
output_graph,
|
| 239 |
+
clear_devices,
|
| 240 |
+
initializer_nodes,
|
| 241 |
+
variable_names_blacklist="",
|
| 242 |
+
input_meta_graph=None,
|
| 243 |
+
input_saved_model_dir=None,
|
| 244 |
+
saved_model_tags=tag_constants.SERVING):
|
| 245 |
+
"""Converts all variables in a graph and checkpoint into constants."""
|
| 246 |
+
input_graph_def = None
|
| 247 |
+
if input_saved_model_dir:
|
| 248 |
+
input_graph_def = get_meta_graph_def(
|
| 249 |
+
input_saved_model_dir, saved_model_tags).graph_def
|
| 250 |
+
elif input_graph:
|
| 251 |
+
input_graph_def = _parse_input_graph_proto(input_graph, input_binary)
|
| 252 |
+
input_meta_graph_def = None
|
| 253 |
+
if input_meta_graph:
|
| 254 |
+
input_meta_graph_def = _parse_input_meta_graph_proto(
|
| 255 |
+
input_meta_graph, input_binary)
|
| 256 |
+
input_saver_def = None
|
| 257 |
+
if input_saver:
|
| 258 |
+
input_saver_def = _parse_input_saver_proto(input_saver, input_binary)
|
| 259 |
+
freeze_graph_with_def_protos(
|
| 260 |
+
input_graph_def, input_saver_def, input_checkpoint, output_node_names,
|
| 261 |
+
restore_op_name, filename_tensor_name, output_graph, clear_devices,
|
| 262 |
+
initializer_nodes, variable_names_blacklist, input_meta_graph_def,
|
| 263 |
+
input_saved_model_dir, saved_model_tags.split(","))
|
models/gap-clas/A-RNN/checkpoint
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
model_checkpoint_path: "model"
|
| 2 |
+
all_model_checkpoint_paths: "model"
|
models/gap-clas/A-RNN/model.data-00000-of-00001
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bb9340ba3f9156f671ba3e78d61f280d32195f31d287e2cb4b2e8121a39ef3f2
|
| 3 |
+
size 20459744
|
models/gap-clas/A-RNN/model.index
ADDED
|
Binary file (2.82 kB). View file
|
|
|
models/gap-clas/A-RNN/model.meta
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:87cd2cb0b4e89914887127c607bb3240f272feb966afa7635647945c45a73f54
|
| 3 |
+
size 2161008
|
models/gap-clas/Bi-RNN.data-00000-of-00001
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0e3e67304611c52f34efd64d27ace70ddfa8ea094be4b9e0a95754afcc050029
|
| 3 |
+
size 63168532
|
models/gap-clas/Bi-RNN.index
ADDED
|
Binary file (1.29 kB). View file
|
|
|
models/gap-clas/Bi-RNN.meta
ADDED
|
Binary file (970 kB). View file
|
|
|
models/gap-clas/CNN-CG.data-00000-of-00001
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9d753209958f41092716721614ad07f29a8bab2957d23efdf30b8d5cae792c55
|
| 3 |
+
size 36324872
|
models/gap-clas/CNN-CG.index
ADDED
|
Binary file (921 Bytes). View file
|
|
|
models/gap-clas/CNN-CG.meta
ADDED
|
Binary file (99.6 kB). View file
|
|
|
models/gap-clas/RNN-A/Bi-RNN.data-00000-of-00001
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:840283cecc2cd25a4285cd2146852bdb91f44a8f5676c6cec2ef9dc2e038bc45
|
| 3 |
+
size 35047968
|
models/gap-clas/RNN-A/Bi-RNN.index
ADDED
|
Binary file (2.44 kB). View file
|
|
|
models/gap-clas/RNN-A/Bi-RNN.meta
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e4f61f67c5ff6ed1888228d204539626c75cf4422b14ddf543f46ec57a43b352
|
| 3 |
+
size 1946207
|
models/gap-clas/RNN-A/checkpoint
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
model_checkpoint_path: "Bi-RNN"
|
| 2 |
+
all_model_checkpoint_paths: "Bi-RNN"
|
models/gap-clas/RNN/Bi-RNN-new.data-00000-of-00001
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:01cebebe4e81fc511b6224b2a003d35968aa25179e2095cf5412dd7f8df416d4
|
| 3 |
+
size 66272288
|
models/gap-clas/RNN/Bi-RNN-new.index
ADDED
|
Binary file (2.62 kB). View file
|
|
|
models/gap-clas/RNN/Bi-RNN-new.meta
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:43da4e220fb7e11b9c244167acd975611c771c645c006943a2f4241448608867
|
| 3 |
+
size 1812295
|
models/gap-clas/RNN/checkpoint
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
model_checkpoint_path: "Bi-RNN-new"
|
| 2 |
+
all_model_checkpoint_paths: "Bi-RNN-new"
|
models/gap-clas/checkpoint
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
model_checkpoint_path: "CNN-CG"
|
| 2 |
+
all_model_checkpoint_paths: "CNN-CG"
|
models/gap-clas/large/CNN-CG.data-00000-of-00001
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d1ba8a17b60e3155406ea2a06d0dfcf13b3a51e4b219cf94258d41ba8ba6446b
|
| 3 |
+
size 108104072
|
models/gap-clas/large/CNN-CG.index
ADDED
|
Binary file (918 Bytes). View file
|
|
|
models/gap-clas/large/CNN-CG.meta
ADDED
|
Binary file (193 kB). View file
|
|
|
models/gap-clas/large/checkpoint
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
model_checkpoint_path: "CNN-CG"
|
| 2 |
+
all_model_checkpoint_paths: "CNN-CG"
|
models/graph_optimizer.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Usage:
|
| 3 |
+
python graph_optimizer.py \
|
| 4 |
+
--tf_path ../../tensorflow/ \
|
| 5 |
+
--model_folder "path_to_the_model_folder" \
|
| 6 |
+
--output_names "activation, accuracy" \
|
| 7 |
+
--input_names "x"
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
import os, argparse
|
| 11 |
+
from subprocess import call
|
| 12 |
+
|
| 13 |
+
import freeze_graph
|
| 14 |
+
import tensorflow as tf
|
| 15 |
+
|
| 16 |
+
dir = os.path.dirname(os.path.realpath(__file__))
|
| 17 |
+
|
| 18 |
+
fr_name = "_frozen.pb"
|
| 19 |
+
op_name = "_optimized.pb"
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def graph_freez(model_folder, output_names):
|
| 23 |
+
print("Model folder", model_folder)
|
| 24 |
+
checkpoint = tf.train.get_checkpoint_state(model_folder)
|
| 25 |
+
print(checkpoint)
|
| 26 |
+
checkpoint_path = checkpoint.model_checkpoint_path
|
| 27 |
+
output_graph_filename = checkpoint_path + fr_name
|
| 28 |
+
|
| 29 |
+
input_saver_def_path = ""
|
| 30 |
+
input_binary = True
|
| 31 |
+
output_node_names = output_names
|
| 32 |
+
restore_op_name = "save/restore_all"
|
| 33 |
+
filename_tensor_name = "save/Const:0"
|
| 34 |
+
clear_devices = False
|
| 35 |
+
input_meta_graph = checkpoint_path + ".meta"
|
| 36 |
+
|
| 37 |
+
freeze_graph.freeze_graph(
|
| 38 |
+
"", input_saver_def_path, input_binary, checkpoint_path,
|
| 39 |
+
output_node_names, restore_op_name, filename_tensor_name,
|
| 40 |
+
output_graph_filename, clear_devices, "", "", input_meta_graph)
|
| 41 |
+
|
| 42 |
+
return output_graph_filename
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def graph_optimization(tf_path, graph_file, input_names, output_names):
|
| 46 |
+
output_file = graph_file[:-len(fr_name)] + op_name
|
| 47 |
+
tf_path += "bazel-bin/tensorflow/tools/graph_transforms/transform_graph"
|
| 48 |
+
|
| 49 |
+
call([tf_path,
|
| 50 |
+
"--in_graph=" + graph_file,
|
| 51 |
+
"--out_graph=" + output_file,
|
| 52 |
+
"--inputs=" + input_names,
|
| 53 |
+
"--outputs=" + output_names,
|
| 54 |
+
"""--transforms=
|
| 55 |
+
strip_unused_nodes(type=float, shape="1,299,299,3")
|
| 56 |
+
fold_constants(ignore_errors=true)
|
| 57 |
+
fold_batch_norms
|
| 58 |
+
fold_old_batch_norms"""])
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
if __name__ == '__main__':
|
| 62 |
+
parser = argparse.ArgumentParser(
|
| 63 |
+
"Script freezes graph and optimize it for mobile usage")
|
| 64 |
+
parser.add_argument(
|
| 65 |
+
"--model",
|
| 66 |
+
type=str,
|
| 67 |
+
help="Path of folder + model name (folder_path/model_name)")
|
| 68 |
+
parser.add_argument(
|
| 69 |
+
"--input_names",
|
| 70 |
+
type=str,
|
| 71 |
+
default="",
|
| 72 |
+
help="Input node names, comma separated.")
|
| 73 |
+
parser.add_argument(
|
| 74 |
+
"--output_names",
|
| 75 |
+
type=str,
|
| 76 |
+
default="",
|
| 77 |
+
help="Output node names, comma separated.")
|
| 78 |
+
parser.add_argument(
|
| 79 |
+
"--tf_path",
|
| 80 |
+
type=str,
|
| 81 |
+
default="../../tensorflow/",
|
| 82 |
+
help="Path to the folder with tensorflow (requires bazel build of graph_transforms)")
|
| 83 |
+
|
| 84 |
+
args = parser.parse_args()
|
| 85 |
+
|
| 86 |
+
graph = graph_freez(args.model, args.output_names)
|
| 87 |
+
graph_optimization(args.tf_path, graph, args.input_names, args.output_names)
|
models/word-clas/CTC/Classifier1.data-00000-of-00001
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e8257c216932dd878023da0a28719f3aa09ba5cf1ff6d9187fe09a9488f0f784
|
| 3 |
+
size 304709420
|
models/word-clas/CTC/Classifier1.index
ADDED
|
Binary file (4.19 kB). View file
|
|
|
models/word-clas/CTC/Classifier1.meta
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:64a0626ed8bb9aab20faf54b1b8a697ddd932c3ce0dd9d7428d0455c7a784350
|
| 3 |
+
size 1844874
|
models/word-clas/CTC/checkpoint
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
model_checkpoint_path: "Classifier2-16500"
|
| 2 |
+
all_model_checkpoint_paths: "Classifier2-14500"
|
| 3 |
+
all_model_checkpoint_paths: "Classifier2-15000"
|
| 4 |
+
all_model_checkpoint_paths: "Classifier2-15500"
|
| 5 |
+
all_model_checkpoint_paths: "Classifier2-16000"
|
| 6 |
+
all_model_checkpoint_paths: "Classifier2-16500"
|
models/word-clas/en/CTC/Classifier2.data-00000-of-00001
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6f40c80e41ea158725a366ebbed70ddd31d367eabee3334792d71c434e2518f7
|
| 3 |
+
size 180905808
|
models/word-clas/en/CTC/Classifier2.index
ADDED
|
Binary file (2.82 kB). View file
|
|
|
models/word-clas/en/CTC/Classifier2.meta
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:89c4a6dfd6ed2eed76259a9b162e7b75cb45a397447c449185bb98e37d6c06b7
|
| 3 |
+
size 1165772
|