[MO] Deprecate TensorFlow 1.x environment support by MO (#8970)
* Remove tf1 requirements file and add deprecation message then tf1 used while compression * Added tf requirements file * Update docs and warning message * Update install scripts * return tf configuration * Add compat.v1 to code snippets in docs * fix typo * Moved back tf2 file * Apply review comments * Fix missed eol * Fix missed eol * Apply review comments in docs * Remove tf version and fix error in script tag * Remove tf version * Remove unused import * Add note about python and TF version
This commit is contained in:
1 parent
2870dc7d3f
commit
8dc7669156
13 files changed
+50
-58
No files matched your search
@@ -375,22 +375,14 @@ install_prerequisites_caffe.sh
|
||||
```
|
||||
install_prerequisites_caffe.bat
|
||||
```
|
||||
* For TensorFlow\* 1.x on Linux:
|
||||
* For TensorFlow\* on Linux:
|
||||
```
|
||||
install_prerequisites_tf.sh
|
||||
```
|
||||
* For TensorFlow 1.x on Windows:
|
||||
* For TensorFlow on Windows:
|
||||
```
|
||||
install_prerequisites_tf.bat
|
||||
```
|
||||
* For TensorFlow\* 2.x on Linux:
|
||||
```
|
||||
install_prerequisites_tf2.sh
|
||||
```
|
||||
* For TensorFlow 2.x on Windows:
|
||||
```
|
||||
install_prerequisites_tf2.bat
|
||||
```
|
||||
* For MXNet\* on Linux:
|
||||
```
|
||||
install_prerequisites_mxnet.sh
|
||||
@@ -453,19 +445,15 @@ virtualenv -p /usr/bin/python3.6 .env3/bin/activate
|
||||
```shell
|
||||
pip3 install -r requirements.txt
|
||||
```
|
||||
> **NOTE**: TensorFlow 1.x and 2.x are incompatible. Use separate virtual environments if you want to install multiple TensorFlow versions.
|
||||
> **NOTE**: Support of MO in TensorFlow 1.x environment is deprecated. Use TensorFlow 2.x environment to convert both TensorFlow 1.x and 2.x models. Use separate virtual environments if you want to install multiple TensorFlow versions.
|
||||
|
||||
* To install dependencies only for Caffe:
|
||||
```shell
|
||||
pip3 install -r requirements_caffe.txt
|
||||
```
|
||||
* To install dependencies only for TensorFlow 1.x:
|
||||
* To install dependencies only for TensorFlow:
|
||||
```shell
|
||||
pip3 install -r requirements_tf.txt
|
||||
```
|
||||
* To install dependencies only for TensorFlow 2.x:
|
||||
```shell
|
||||
pip3 install -r requirements_tf2.txt
|
||||
```
|
||||
* To install dependencies only for MXNet:
|
||||
```shell
|
||||
|
||||
@@ -256,7 +256,7 @@ The graph is frozen and dumped to a file with the following code:
|
||||
```python
|
||||
import tensorflow as tf
|
||||
from tensorflow.python.framework import graph_io
|
||||
frozen = tf.graph_util.convert_variables_to_constants(sess, sess.graph_def, ["name_of_the_output_node"])
|
||||
frozen = tf.compat.v1.graph_util.convert_variables_to_constants(sess, sess.graph_def, ["name_of_the_output_node"])
|
||||
graph_io.write_graph(frozen, './', 'inference_graph.pb', as_text=False)
|
||||
```
|
||||
|
||||
@@ -360,7 +360,7 @@ TensorFlow*-specific parameters:
|
||||
|
||||
## Convert TensorFlow* 2 Models <a name="Convert_From_TF2X"></a>
|
||||
|
||||
In order to convert TensorFlow* 2 models, installation of dependencies from `requirements_tf2.txt` is required.
|
||||
In order to convert TensorFlow* 2 models, installation of dependencies from `requirements_tf.txt` is required.
|
||||
TensorFlow* 2.X officially supports two model formats: SavedModel and Keras H5 (or HDF5).
|
||||
Below are the instructions on how to convert each of them.
|
||||
|
||||
|
||||
@@ -75,13 +75,14 @@ python3 download_glue_data.py --tasks MRPC
|
||||
8. Open the file `run_classifier.py` and insert the following code after the line 645:
|
||||
```python
|
||||
import os, sys
|
||||
import tensorflow as tf
|
||||
from tensorflow.python.framework import graph_io
|
||||
with tf.Session(graph=tf.get_default_graph()) as sess:
|
||||
with tf.compat.v1.Session(graph=tf.compat.v1.get_default_graph()) as sess:
|
||||
(assignment_map, initialized_variable_names) = \
|
||||
modeling.get_assignment_map_from_checkpoint(tf.trainable_variables(), init_checkpoint)
|
||||
tf.train.init_from_checkpoint(init_checkpoint, assignment_map)
|
||||
sess.run(tf.global_variables_initializer())
|
||||
frozen = tf.graph_util.convert_variables_to_constants(sess, sess.graph_def, ["bert/pooler/dense/Tanh"])
|
||||
modeling.get_assignment_map_from_checkpoint(tf.compat.v1.trainable_variables(), init_checkpoint)
|
||||
tf.compat.v1.train.init_from_checkpoint(init_checkpoint, assignment_map)
|
||||
sess.run(tf.compat.v1.global_variables_initializer())
|
||||
frozen = tf.compat.v1.graph_util.convert_variables_to_constants(sess, sess.graph_def, ["bert/pooler/dense/Tanh"])
|
||||
graph_io.write_graph(frozen, './', 'inference_graph.pb', as_text=False)
|
||||
print('BERT frozen model path {}'.format(os.path.join(os.path.dirname(__file__), 'inference_graph.pb')))
|
||||
sys.exit(0)
|
||||
|
||||
@@ -33,8 +33,9 @@ export PYTHONPATH="${PYTHONPATH}:/path/to/CRNN_Tensorflow/"
|
||||
* For Windows\* OS add `/path/to/CRNN_Tensorflow/` to the `PYTHONPATH` environment variable in settings.
|
||||
3. Open the `tools/test_shadownet.py` script. After `saver.restore(sess=sess, save_path=weights_path)` line, add the following code:
|
||||
```python
|
||||
import tensorflow as tf
|
||||
from tensorflow.python.framework import graph_io
|
||||
frozen = tf.graph_util.convert_variables_to_constants(sess, sess.graph_def, ['shadow/LSTMLayers/transpose_time_major'])
|
||||
frozen = tf.compat.v1.graph_util.convert_variables_to_constants(sess, sess.graph_def, ['shadow/LSTMLayers/transpose_time_major'])
|
||||
graph_io.write_graph(frozen, '.', 'frozen_graph.pb', as_text=False)
|
||||
```
|
||||
4. Run the demo with the following command:
|
||||
|
||||
@@ -12,11 +12,11 @@ Run the following commands:
|
||||
import tensorflow as tf
|
||||
from tensorflow.python.framework import graph_io
|
||||
|
||||
sess = tf.Session()
|
||||
saver = tf.train.import_meta_graph("/path/to/model/model.meta")
|
||||
sess = tf.compat.v1.Session()
|
||||
saver = tf.compat.v1.train.import_meta_graph("/path/to/model/model.meta")
|
||||
saver.restore(sess, tf.train.latest_checkpoint('/path/to/model/'))
|
||||
|
||||
frozen = tf.graph_util.convert_variables_to_constants(sess, sess.graph_def, \
|
||||
frozen = tf.compat.v1.graph_util.convert_variables_to_constants(sess, sess.graph_def, \
|
||||
["rating/BiasAdd"])
|
||||
graph_io.write_graph(frozen, './', 'inference_graph.pb', as_text=False)
|
||||
```
|
||||
|
||||
@@ -72,6 +72,7 @@ The [inception_preprocessing.py](https://github.com/tensorflow/models/blob/maste
|
||||
|
||||
```python3
|
||||
...
|
||||
import tensorflow as tf
|
||||
if image.dtype != tf.float32:
|
||||
image = tf.image.convert_image_dtype(image, dtype=tf.float32)
|
||||
...
|
||||
|
||||
+18
-16
@@ -37,6 +37,8 @@ To get pb-file from the archive contents, you need to do the following.
|
||||
|
||||
2. Save and run the following Python script in `~/XLNet-Base/xlnet`:
|
||||
|
||||
**Note** The original model repository has been tested with TensorFlow 1.13.1 under Python2.
|
||||
|
||||
```python
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -59,28 +61,28 @@ xlnet_config = xlnet.XLNetConfig(json_path=XLNET_CONFIG_PATH)
|
||||
run_config = xlnet.RunConfig(is_training=False, use_tpu=False, use_bfloat16=False, dropout=0.1, dropatt=0.1,)
|
||||
|
||||
|
||||
sentence_features_input_idx = tf.placeholder(tf.int32, shape=[LENGTHS, BATCH], name='input_ids')
|
||||
sentence_features_segment_ids = tf.placeholder(tf.int32, shape=[LENGTHS, BATCH], name='seg_ids')
|
||||
sentence_features_input_mask = tf.placeholder(tf.float32, shape=[LENGTHS, BATCH], name='input_mask')
|
||||
sentence_features_input_idx = tf.compat.v1.placeholder(tf.int32, shape=[LENGTHS, BATCH], name='input_ids')
|
||||
sentence_features_segment_ids = tf.compat.v1.placeholder(tf.int32, shape=[LENGTHS, BATCH], name='seg_ids')
|
||||
sentence_features_input_mask = tf.compat.v1.placeholder(tf.float32, shape=[LENGTHS, BATCH], name='input_mask')
|
||||
|
||||
with tf.Session() as sess:
|
||||
with tf.compat.v1.Session() as sess:
|
||||
xlnet_model = xlnet.XLNetModel(xlnet_config=xlnet_config, run_config=run_config,
|
||||
input_ids=sentence_features_input_idx,
|
||||
seg_ids=sentence_features_segment_ids,
|
||||
input_mask=sentence_features_input_mask)
|
||||
|
||||
sess.run(tf.global_variables_initializer())
|
||||
sess.run(tf.compat.v1.global_variables_initializer())
|
||||
model_utils.init_from_checkpoint(FLAGS, True)
|
||||
|
||||
# Save the variables to disk.
|
||||
saver = tf.train.Saver()
|
||||
saver = tf.compat.v1.train.Saver()
|
||||
|
||||
# Saving checkpoint
|
||||
save_path = saver.save(sess, OUTPUT_DIR + "model.ckpt")
|
||||
|
||||
# Freezing model
|
||||
outputs = ['model/transformer/dropout_2/Identity']
|
||||
graph_def_freezed = tf.graph_util.convert_variables_to_constants(sess, sess.graph.as_graph_def(), outputs)
|
||||
graph_def_freezed = tf.compat.v1.graph_util.convert_variables_to_constants(sess, sess.graph.as_graph_def(), outputs)
|
||||
|
||||
# Saving non-frozen and frozen model to pb
|
||||
graph_io.write_graph(sess.graph.as_graph_def(), OUTPUT_DIR, 'model.pb', as_text=False)
|
||||
@@ -88,7 +90,7 @@ with tf.Session() as sess:
|
||||
as_text=False)
|
||||
|
||||
# Write to tensorboard
|
||||
with tf.summary.FileWriter(logdir=OUTPUT_DIR, graph_def=graph_def_freezed) as writer:
|
||||
with tf.compat.v1.summary.FileWriter(logdir=OUTPUT_DIR, graph_def=graph_def_freezed) as writer:
|
||||
writer.flush()
|
||||
```
|
||||
|
||||
@@ -143,28 +145,28 @@ xlnet_config = xlnet.XLNetConfig(json_path=XLNET_CONFIG_PATH)
|
||||
run_config = xlnet.RunConfig(is_training=False, use_tpu=False, use_bfloat16=False, dropout=0.1, dropatt=0.1,)
|
||||
|
||||
|
||||
sentence_features_input_idx = tf.placeholder(tf.int32, shape=[LENGTHS, BATCH], name='input_ids')
|
||||
sentence_features_segment_ids = tf.placeholder(tf.int32, shape=[LENGTHS, BATCH], name='seg_ids')
|
||||
sentence_features_input_mask = tf.placeholder(tf.float32, shape=[LENGTHS, BATCH], name='input_mask')
|
||||
sentence_features_input_idx = tf.compat.v1.placeholder(tf.int32, shape=[LENGTHS, BATCH], name='input_ids')
|
||||
sentence_features_segment_ids = tf.compat.v1.placeholder(tf.int32, shape=[LENGTHS, BATCH], name='seg_ids')
|
||||
sentence_features_input_mask = tf.compat.v1.placeholder(tf.float32, shape=[LENGTHS, BATCH], name='input_mask')
|
||||
|
||||
with tf.Session() as sess:
|
||||
with tf.compat.v1.Session() as sess:
|
||||
xlnet_model = xlnet.XLNetModel(xlnet_config=xlnet_config, run_config=run_config,
|
||||
input_ids=sentence_features_input_idx,
|
||||
seg_ids=sentence_features_segment_ids,
|
||||
input_mask=sentence_features_input_mask)
|
||||
|
||||
sess.run(tf.global_variables_initializer())
|
||||
sess.run(tf.compat.v1.global_variables_initializer())
|
||||
model_utils.init_from_checkpoint(FLAGS, True)
|
||||
|
||||
# Save the variables to disk.
|
||||
saver = tf.train.Saver()
|
||||
saver = tf.compat.v1.train.Saver()
|
||||
|
||||
# Saving checkpoint
|
||||
save_path = saver.save(sess, OUTPUT_DIR + "model.ckpt")
|
||||
|
||||
# Freezing model
|
||||
outputs = ['model/transformer/dropout_2/Identity']
|
||||
graph_def_freezed = tf.graph_util.convert_variables_to_constants(sess, sess.graph.as_graph_def(), outputs)
|
||||
graph_def_freezed = tf.compat.v1.graph_util.convert_variables_to_constants(sess, sess.graph.as_graph_def(), outputs)
|
||||
|
||||
# Saving non-frozen and frozen model to pb
|
||||
graph_io.write_graph(sess.graph.as_graph_def(), OUTPUT_DIR, 'model.pb', as_text=False)
|
||||
@@ -172,7 +174,7 @@ with tf.Session() as sess:
|
||||
as_text=False)
|
||||
|
||||
# Write to tensorboard
|
||||
with tf.summary.FileWriter(logdir=OUTPUT_DIR, graph_def=graph_def_freezed) as writer:
|
||||
with tf.compat.v1.summary.FileWriter(logdir=OUTPUT_DIR, graph_def=graph_def_freezed) as writer:
|
||||
writer.flush()
|
||||
```
|
||||
|
||||
|
||||
@@ -202,12 +202,12 @@ For more information about the Model Optimizer, refer to the [Model Optimizer De
|
||||
cd /opt/intel/openvino_2022/tools/model_optimizer/install_prerequisites
|
||||
```
|
||||
|
||||
2. Run the script to configure the Model Optimizer for Caffe, TensorFlow 2.x, MXNet, Kaldi, and ONNX:
|
||||
2. Run the script to configure the Model Optimizer for Caffe, TensorFlow, MXNet, Kaldi, and ONNX:
|
||||
```sh
|
||||
sudo ./install_prerequisites.sh
|
||||
```
|
||||
|
||||
3. **Optional:** You can choose to install Model Optimizer support for only certain frameworks. In the same directory are individual scripts for Caffe, TensorFlow 1.x, TensorFlow 2.x, MXNet, Kaldi, and ONNX (`install_prerequisites_caffe.sh`, etc.). If you see error messages, make sure you installed all dependencies.
|
||||
3. **Optional:** You can choose to install Model Optimizer support for only certain frameworks. In the same directory are individual scripts for Caffe, TensorFlow, MXNet, Kaldi, and ONNX (`install_prerequisites_caffe.sh`, etc.). If you see error messages, make sure you installed all dependencies.
|
||||
|
||||
The Model Optimizer is configured for one or more frameworks.
|
||||
|
||||
|
||||
@@ -154,12 +154,12 @@ If you see error messages, verify that you installed all dependencies listed und
|
||||
cd /opt/intel/openvino_2022/tools/model_optimizer/install_prerequisites
|
||||
```
|
||||
|
||||
2. Run the script to configure the Model Optimizer for Caffe, TensorFlow 2.x, MXNet, Kaldi\*, and ONNX:
|
||||
2. Run the script to configure the Model Optimizer for Caffe, TensorFlow, MXNet, Kaldi\*, and ONNX:
|
||||
```sh
|
||||
sudo ./install_prerequisites.sh
|
||||
```
|
||||
|
||||
3. **Optional:** You can choose to install Model Optimizer support for only certain frameworks. In the same directory are individual scripts for Caffe, TensorFlow 1.x, TensorFlow 2.x, MXNet, Kaldi, and ONNX (`install_prerequisites_caffe.sh`, etc.). If you see error messages, make sure you installed all dependencies.
|
||||
3. **Optional:** You can choose to install Model Optimizer support for only certain frameworks. In the same directory are individual scripts for Caffe, TensorFlow, MXNet, Kaldi, and ONNX (`install_prerequisites_caffe.sh`, etc.). If you see error messages, make sure you installed all dependencies.
|
||||
|
||||
The Model Optimizer is configured for one or more frameworks.
|
||||
|
||||
|
||||
@@ -139,12 +139,12 @@ Type commands in the opened window:
|
||||
cd C:\Program Files (x86)\Intel\openvino_2022\tools\model_optimizer\install_prerequisites
|
||||
```
|
||||
|
||||
3. Run this batch file to configure the Model Optimizer for Caffe, TensorFlow 2.x, MXNet, Kaldi\*, and ONNX:<br>
|
||||
3. Run this batch file to configure the Model Optimizer for Caffe, TensorFlow, MXNet, Kaldi\*, and ONNX:<br>
|
||||
```sh
|
||||
install_prerequisites.bat
|
||||
```
|
||||
|
||||
3. **Optional:** You can choose to install Model Optimizer support for only certain frameworks. In the same directory are individual batch files for Caffe, TensorFlow 1.x, TensorFlow 2.x, MXNet, Kaldi, and ONNX (`install_prerequisites_caffe.bat`, etc.). If you see error messages, make sure you installed all dependencies.
|
||||
3. **Optional:** You can choose to install Model Optimizer support for only certain frameworks. In the same directory are individual batch files for Caffe, TensorFlow, MXNet, Kaldi, and ONNX (`install_prerequisites_caffe.bat`, etc.). If you see error messages, make sure you installed all dependencies.
|
||||
|
||||
The Model Optimizer is configured for one or more frameworks.
|
||||
|
||||
|
||||
@@ -97,6 +97,7 @@ For example, to install and configure the components for working with TensorFlow
|
||||
```sh
|
||||
pip install openvino-dev[tensorflow2,mxnet,caffe]
|
||||
```
|
||||
**NOTE**: Support of MO in TensorFlow 1.x environment is deprecated. Use TensorFlow 2.x environment to convert both TensorFlow 1.x and 2.x models
|
||||
|
||||
### Step 5. Verify that the Package Is Installed
|
||||
|
||||
|
||||
@@ -251,16 +251,15 @@ def check_requirements(framework=None):
|
||||
:param framework: framework name
|
||||
:return: exit code (0 - execution successful, 1 - error)
|
||||
"""
|
||||
framework_suffix = "_{}".format(framework)
|
||||
env_setup = get_environment_setup(framework)
|
||||
if framework is None:
|
||||
framework_suffix = ""
|
||||
elif framework == "tf":
|
||||
if "tensorflow" in env_setup and env_setup["tensorflow"] >= LooseVersion("2.0.0"):
|
||||
framework_suffix = "_tf2"
|
||||
else:
|
||||
framework_suffix = "_tf"
|
||||
else:
|
||||
framework_suffix = "_{}".format(framework)
|
||||
if "tensorflow" in env_setup and env_setup["tensorflow"] < LooseVersion("2.0.0"):
|
||||
log.error('\t\nSupport of the Model Optimizer tool in TensorFlow 1.x environment is deprecated.'
|
||||
'It is highly recommended to use TensorFlow 2.x.\n',
|
||||
extra={'is_warning': True})
|
||||
|
||||
file_name = "requirements{}.txt".format(framework_suffix)
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# TensorFlow 1.x and 2.x are incompatible, use separate virtual environments for each version
|
||||
tensorflow~=1.15.5
|
||||
tensorflow~=2.5.0
|
||||
networkx~=2.5
|
||||
numpy>=1.16.6,<1.19
|
||||
numpy>=1.16.6,<1.20
|
||||
defusedxml>=0.7.1
|
||||
requests>=2.25.1
|
||||
fastjsonschema~=2.15.1
|
||||
Reference in new issue
Block a user