Skip to content
This repository was archived by the owner on Jun 14, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
696a366
add interactive cli for python converter
pyu10055 Apr 17, 2019
96fe586
Merge branch 'master' into interactive-cli
pyu10055 Jun 24, 2019
f0f6989
add auto looking up the saved model tags and signatures
pyu10055 Jun 25, 2019
e944f24
fixed pylint errors and added tests
pyu10055 Jun 28, 2019
7e93a4f
adding more docstrings
pyu10055 Jun 29, 2019
c9a63dc
fix typo
pyu10055 Jul 1, 2019
3d9d5ac
merged master
pyu10055 Jul 1, 2019
82a0648
update the cli workflow according to the design doc comments
pyu10055 Jul 3, 2019
91f781e
fix pylint
pyu10055 Jul 3, 2019
ea5ed07
show the dtype string instead of value
pyu10055 Jul 3, 2019
093c8aa
fix pylint error
pyu10055 Jul 3, 2019
3431a07
move to questionary pip to support prompt_toolkit 2
pyu10055 Jul 17, 2019
1d6382d
Merge branch 'master' into interactive-cli
pyu10055 Jul 29, 2019
0c7d70b
update the README and fixed the tests
pyu10055 Jul 29, 2019
9acd99a
addressed the comments and add dryrun arg to generate the raw convert…
pyu10055 Jul 30, 2019
d24ad9b
fixed bugs
pyu10055 Jul 30, 2019
a4ea88f
address comments
pyu10055 Jul 30, 2019
4512586
use tuple instead of list
pyu10055 Jul 30, 2019
066af81
address the comments
pyu10055 Jul 31, 2019
0cc44e6
update compression choices
pyu10055 Aug 1, 2019
e2135a4
fix pylint error
pyu10055 Aug 1, 2019
4cdcda8
more pylint error
pyu10055 Aug 1, 2019
c245c3a
Merge branch 'master' into interactive-cli
pyu10055 Aug 1, 2019
89d52a1
used listdir to support py2
pyu10055 Aug 2, 2019
4995679
update text
pyu10055 Aug 2, 2019
725ddd2
fix pylint error
pyu10055 Aug 6, 2019
a0ce222
Merge branch 'master' into interactive-cli
pyu10055 Aug 6, 2019
0193b61
addressed comments
pyu10055 Aug 6, 2019
bd76a7f
Merge branch 'master' into interactive-cli
pyu10055 Aug 6, 2019
fe61a3d
Merge branch 'interactive-cli' of github.com:tensorflow/web into inte…
pyu10055 Aug 6, 2019
d4bc566
Merge branch 'master' into interactive-cli
pyu10055 Aug 14, 2019
fc509d2
Merge branch 'master' into interactive-cli
pyu10055 Aug 14, 2019
9c1d0e4
fixed test error
pyu10055 Aug 14, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ __0. Please make sure that you run in a Docker container or a virtual environmen
The script pulls its own subset of TensorFlow, which might conflict with the
existing TensorFlow/Keras installation.

__Note__: *Check that [`tf-nightly-2.0-preview`](https://pypi.org/project/tf-nightly-2.0-preview/#files) is available for your platform.*

Most of the times, this means that you have to use Python 3.6.8 in your local
environment. To force Python 3.6.8 in your local project, you can install
[`pyenv`](https://github.com/pyenv/pyenv) and proceed as follows in the target
directory:
The converter supports both Python 2 and Python 3. But Python 3.6.8 is recommended
for your local environment. To force Python 3.6.8 in your local project, you can
install [`pyenv`](https://github.com/pyenv/pyenv) and proceed as follows in the
target directory:

```bash
pyenv install 3.6.8
Expand All @@ -52,7 +50,35 @@ __1. Install the TensorFlow.js pip package:__
pip install tensorflowjs
```

__2. Run the converter script provided by the pip package:__
__2. Run the conversion script provided by the pip package:__

There are two way to trigger the model conversion:

- The conversion wizard: tensorflowjs_wizard
- Regular conversion script: tensorflowjs_converter

To start the conversion wizard:
```bash
tensorflowjs_wizard
```

This tool will walk you through the conversion process and provide you with
details explanations for each choice you need to make. Behind the scene it calls
the converter script (`tensorflowjs_converter`) in pip package. This is the easier
way to convert a single model.

There is also dry run mode for the wizard, which will not perform the actual
conversion but only generate the command for `tensorflowjs_converter` command.
This command can be used in your own shell script.

```bash
tensorflowjs_wizard --dryrun
```

To convert a batch of models or integrate the conversion process into your own
script, you should look into using the tensorflowjs_converter script.

Here is detail information of parameters of the converter script.

The converter expects a __TensorFlow SavedModel__, __TensorFlow Hub module__,
__TensorFlow.js JSON__ format, __Keras HDF5 model__, or __tf.keras SavedModel__
Expand Down
1 change: 1 addition & 0 deletions python/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ numpy==1.16.4
six==1.11.0
tensorflow==1.14.0
tensorflow-hub==0.5.0
PyInquirer==1.0.3
2 changes: 2 additions & 0 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def _get_requirements(file):

CONSOLE_SCRIPTS = [
'tensorflowjs_converter = tensorflowjs.converters.converter:pip_main',
'tensorflowjs_wizard = tensorflowjs.wizard:main',
]

setuptools.setup(
Expand Down Expand Up @@ -57,6 +58,7 @@ def _get_requirements(file):
'tensorflowjs.version',
'tensorflowjs.quantization',
'tensorflowjs.read_weights',
'tensorflowjs.wizard',
'tensorflowjs.write_weights',
'tensorflowjs.converters',
'tensorflowjs.converters.common',
Expand Down
30 changes: 30 additions & 0 deletions python/tensorflowjs/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ py_library(
# `pip install tensorflow` or `pip install tensorflow-gpu`.
)

py_library(
name = "expect_PyInquirer_installed",
# This is a dummy rule used as a PyInquirer dependency in open-source.
# We expect PyInquirer to already be installed on the system, e.g. via
# `pip install PyInquirer`.
)

py_library(
name = "quantization",
srcs = ["quantization.py"],
Expand Down Expand Up @@ -116,6 +123,29 @@ py_test(
],
)

py_test(
name = "wizard_test",
srcs = ["wizard_test.py"],
srcs_version = "PY2AND3",
deps = [
":expect_numpy_installed",
":wizard",
],
)

py_binary(
name = "wizard",
srcs = ["wizard.py"],
srcs_version = "PY2AND3",
deps = [
":converters/common",
":converters/converter",
"//tensorflowjs:expect_h5py_installed",
"//tensorflowjs:expect_keras_installed",
"//tensorflowjs:expect_tensorflow_installed",
],
)

# A filegroup BUILD target that includes all the op list json files in the
# the op_list/ folder. The op_list folder itself is a symbolic link to the
# actual op_list folder under src/.
Expand Down
1 change: 1 addition & 0 deletions python/tensorflowjs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
from tensorflowjs import converters
from tensorflowjs import quantization
from tensorflowjs import version
from tensorflowjs import wizard

__version__ = version.version
1 change: 1 addition & 0 deletions python/tensorflowjs/converters/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ py_binary(
srcs = ["converter.py"],
srcs_version = "PY2AND3",
deps = [
":common",
":keras_h5_conversion",
":keras_tfjs_loader",
":tf_saved_model_conversion_v2",
Expand Down
21 changes: 21 additions & 0 deletions python/tensorflowjs/converters/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,27 @@
GENERATED_BY_KEY = 'generatedBy'
CONVERTED_BY_KEY = 'convertedBy'

# Model formats.
KERAS_SAVED_MODEL = 'keras_saved_model'
KERAS_MODEL = 'keras'
TF_SAVED_MODEL = 'tf_saved_model'
TF_HUB_MODEL = 'tf_hub'
TFJS_GRAPH_MODEL = 'tfjs_graph_model'
TFJS_LAYERS_MODEL = 'tfjs_layers_model'

# CLI argument strings.
INPUT_PATH = 'input_path'
OUTPUT_PATH = 'output_path'
INPUT_FORMAT = 'input_format'
OUTPUT_FORMAT = 'output_format'
SIGNATURE_NAME = 'signature_name'
SAVED_MODEL_TAGS = 'saved_model_tags'
QUANTIZATION_BYTES = 'quantization_bytes'
SPLIT_WEIGHTS_BY_LAYER = 'split_weights_by_layer'
VERSION = 'version'
SKIP_OP_CHECK = 'skip_op_check'
STRIP_DEBUG_OPS = 'strip_debug_ops'
WEIGHT_SHARD_SIZE_BYTES = 'weight_shard_size_bytes'

def get_converted_by():
"""Get the convertedBy string for storage in model artifacts."""
Expand Down
Loading