स्वचालित रूप से TF 1.x और compat.v1 API प्रतीकों को फिर से लिखें

TensorFlow.org पर देखें Google Colab में चलाएं GitHub पर स्रोत देखें नोटबुक डाउनलोड करें

TensorFlow 2.x में TF 1.x और tf.compat.v1 API से कई API परिवर्तन शामिल हैं, जैसे कि तर्कों को फिर से व्यवस्थित करना, प्रतीकों का नाम बदलना और पैरामीटर के लिए डिफ़ॉल्ट मान बदलना। इन सभी संशोधनों को मैन्युअल रूप से करना थकाऊ और त्रुटि की संभावना वाला होगा। परिवर्तनों को सुव्यवस्थित करने के लिए, और TF 2.x में आपके संक्रमण को यथासंभव सहज बनाने के लिए, TensorFlow टीम ने नए API में लीगेसी कोड को बदलने में मदद करने के लिए tf_upgrade_v2 उपयोगिता बनाई है।

विशिष्ट उपयोग इस प्रकार है:

tf_upgrade_v2 \
  --intree my_project/ \
  --outtree my_project_v2/ \
  --reportfile report.txt

यह मौजूदा TensorFlow 1.x Python स्क्रिप्ट को TensorFlow 2.x में परिवर्तित करके आपकी अपग्रेड प्रक्रिया को गति देगा।

रूपांतरण स्क्रिप्ट कई यांत्रिक एपीआई परिवर्तनों को स्वचालित करती है, हालांकि कई एपीआई स्वचालित रूप से माइग्रेट नहीं किए जा सकते हैं। यह आपके कोड को TF2 व्यवहार और API के साथ पूरी तरह से संगत बनाने में भी सक्षम नहीं है। तो, यह आपकी प्रवास यात्रा का केवल एक हिस्सा है।

संगतता मॉड्यूल

कुछ एपीआई प्रतीकों को केवल एक स्ट्रिंग प्रतिस्थापन का उपयोग करके अपग्रेड नहीं किया जा सकता है। जिन्हें स्वचालित रूप से अपग्रेड नहीं किया जा सकता है, उन्हें उनके स्थान के लिए compat.v1 मॉड्यूल में मैप किया जाएगा। यह मॉड्यूल TF 1.x प्रतीकों जैसे tf.foo को समकक्ष tf.compat.v1.foo संदर्भ के साथ बदल देता है। यदि आप पहले से ही import tensorflow.compat.v1 as tf माध्यम से TF आयात करके compat.v1 API का उपयोग कर रहे हैं, तो tf_upgrade_v2 स्क्रिप्ट इन उपयोगों को गैर-संगत API में बदलने का प्रयास करेगी जहां संभव हो। ध्यान दें कि जबकि कुछ compat.v1 API TF2.x व्यवहार के साथ संगत हैं, कई नहीं हैं। इसलिए, हम अनुशंसा करते हैं कि आप प्रतिस्थापनों को मैन्युअल रूप से प्रूफरीड करें और उन्हें tf.compat.v1 नाम स्थान के बजाय tf.* नाम स्थान में जितनी जल्दी हो सके नए API में माइग्रेट करें।

TensorFlow 2.x मॉड्यूल बहिष्करण (उदाहरण के लिए, tf.flags और tf.contrib ) के कारण, कुछ परिवर्तनों को compat.v1 पर स्विच करके काम नहीं किया जा सकता है। इस कोड को अपग्रेड करने के लिए एक अतिरिक्त लाइब्रेरी (उदाहरण के लिए, absl.flags ) का उपयोग करने या tensorflow/addons में पैकेज पर स्विच करने की आवश्यकता हो सकती है।

इस गाइड का बाकी हिस्सा दर्शाता है कि प्रतीक-पुनर्लेखन स्क्रिप्ट का उपयोग कैसे किया जाता है। जबकि स्क्रिप्ट का उपयोग करना आसान है, यह दृढ़ता से अनुशंसा की जाती है कि आप निम्न प्रक्रिया के भाग के रूप में स्क्रिप्ट का उपयोग करें:

  1. यूनिट टेस्ट : सुनिश्चित करें कि आप जिस कोड को अपग्रेड कर रहे हैं, उसमें उचित कवरेज वाला यूनिट टेस्ट सूट है। यह पायथन कोड है, इसलिए भाषा आपको कई तरह की गलतियों से नहीं बचाएगी। यह भी सुनिश्चित करें कि आपके द्वारा पहले से ही किसी भी निर्भरता को TensorFlow 2.x के साथ संगत होने के लिए अपग्रेड किया जा चुका है।

  2. TensorFlow 1.15 स्थापित करें : अपने TensorFlow को नवीनतम TensorFlow 1.x संस्करण में अपग्रेड करें, कम से कम 1.15। इसमें tf.compat.v2 में अंतिम tf.compat.v2 2.0 API शामिल है।

  3. 1.15 के साथ परीक्षण : सुनिश्चित करें कि इस बिंदु पर आपके यूनिट परीक्षण पास हो जाएं। अपग्रेड करते समय आप उन्हें बार-बार चलाएंगे, इसलिए हरे रंग से शुरू करना महत्वपूर्ण है।

  4. अपग्रेड स्क्रिप्ट चलाएँ: अपने संपूर्ण स्रोत ट्री पर tf_upgrade_v2 चलाएँ, परीक्षण शामिल हैं। यह आपके कोड को एक प्रारूप में अपग्रेड कर देगा जहां यह केवल TensorFlow 2.0 में उपलब्ध प्रतीकों का उपयोग करता है। पदावनत प्रतीकों को tf.compat.v1 के साथ एक्सेस किया जाएगा। इन्हें अंततः मैन्युअल ध्यान देने की आवश्यकता होगी, लेकिन तुरंत नहीं।

  5. TensorFlow 1.15 के साथ परिवर्तित परीक्षण चलाएँ : आपका कोड अभी भी TensorFlow 1.15 में ठीक चलना चाहिए। अपने यूनिट परीक्षण फिर से चलाएँ। यहां आपके परीक्षणों में किसी भी त्रुटि का मतलब है कि अपग्रेड स्क्रिप्ट में एक बग है। कृपया हमें बताएं

  6. चेतावनियों और त्रुटियों के लिए अपग्रेड रिपोर्ट की जांच करें : स्क्रिप्ट एक रिपोर्ट फ़ाइल लिखती है जो किसी भी रूपांतरण की व्याख्या करती है जिसे आपको दोबारा जांचना चाहिए, या कोई भी मैन्युअल कार्रवाई जो आपको करने की आवश्यकता है। उदाहरण के लिए: योगदान के किसी भी शेष उदाहरणों को निकालने के लिए मैन्युअल कार्रवाई की आवश्यकता होगी। अधिक निर्देशों के लिए कृपया RFC से परामर्श लें।

  7. TensorFlow 2.x स्थापित करें : इस समय TensorFlow 2.x बायनेरिज़ पर स्विच करना सुरक्षित होना चाहिए, भले ही आप विरासती व्यवहार के साथ चल रहे हों

  8. v1.disable_v2_behavior के साथ परीक्षण करें: परीक्षण के मुख्य कार्य में v1.disable_v2_behavior() के साथ अपने परीक्षणों को फिर से चलाना चाहिए, वही परिणाम देना चाहिए जो 1.15 के तहत चल रहा है।

  9. V2 व्यवहार सक्षम करें : अब जब आपके परीक्षण TF2 बायनेरिज़ का उपयोग करके काम करते हैं, तो अब आप tf.estimator s से बचने के लिए अपने कोड को माइग्रेट करना शुरू कर सकते हैं और केवल समर्थित TF2 व्यवहारों का उपयोग कर सकते हैं (बिना TF2 व्यवहार अक्षम किए)। विवरण के लिए प्रवासन मार्गदर्शिकाएँ देखें।

प्रतीक-पुनर्लेखन tf_upgrade_v2 स्क्रिप्ट का उपयोग करना

सेट अप

आरंभ करने से पहले सुनिश्चित करें कि TensorFlow 2.x स्थापित है।

import tensorflow as tf

print(tf.__version__)
2.6.0

टेंसरफ़्लो/मॉडल git रिपॉजिटरी को क्लोन करें ताकि आपके पास परीक्षण करने के लिए कुछ कोड हो:

git clone --branch r1.13.0 --depth 1 https://github.com/tensorflow/models
Cloning into 'models'...
remote: Enumerating objects: 2927, done.[K
remote: Counting objects: 100% (2927/2927), done.[K
remote: Compressing objects: 100% (2428/2428), done.[K
remote: Total 2927 (delta 504), reused 2113 (delta 424), pack-reused 0[K
Receiving objects: 100% (2927/2927), 369.04 MiB | 27.58 MiB/s, done.
Resolving deltas: 100% (504/504), done.
Checking out files: 100% (2768/2768), done.

मदद पढ़ें

स्क्रिप्ट को TensorFlow के साथ स्थापित किया जाना चाहिए। यहां बिल्टिन सहायता है:

tf_upgrade_v2 -h
usage: tf_upgrade_v2 [-h] [--infile INPUT_FILE] [--outfile OUTPUT_FILE]
                     [--intree INPUT_TREE] [--outtree OUTPUT_TREE]
                     [--copyotherfiles COPY_OTHER_FILES] [--inplace]
                     [--no_import_rename] [--no_upgrade_compat_v1_import]
                     [--reportfile REPORT_FILENAME] [--mode {DEFAULT,SAFETY}]
                     [--print_all]

Convert a TensorFlow Python file from 1.x to 2.0

Simple usage:
  tf_upgrade_v2.py --infile foo.py --outfile bar.py
  tf_upgrade_v2.py --infile foo.ipynb --outfile bar.ipynb
  tf_upgrade_v2.py --intree ~/code/old --outtree ~/code/new

optional arguments:
  -h, --help            show this help message and exit
  --infile INPUT_FILE   If converting a single file, the name of the file to
                        convert
  --outfile OUTPUT_FILE
                        If converting a single file, the output filename.
  --intree INPUT_TREE   If converting a whole tree of files, the directory to
                        read from (relative or absolute).
  --outtree OUTPUT_TREE
                        If converting a whole tree of files, the output
                        directory (relative or absolute).
  --copyotherfiles COPY_OTHER_FILES
                        If converting a whole tree of files, whether to copy
                        the other files.
  --inplace             If converting a set of files, whether to allow the
                        conversion to be performed on the input files.
  --no_import_rename    Not to rename import to compat.v2 explicitly.
  --no_upgrade_compat_v1_import
                        If specified, don't upgrade explicit imports of
                        `tensorflow.compat.v1 as tf` to the v2 APIs.
                        Otherwise, explicit imports of the form
                        `tensorflow.compat.v1 as tf` will be upgraded.
  --reportfile REPORT_FILENAME
                        The name of the file where the report log is
                        stored.(default: report.txt)
  --mode {DEFAULT,SAFETY}
                        Upgrade script mode. Supported modes: DEFAULT: Perform
                        only straightforward conversions to upgrade to 2.0. In
                        more difficult cases, switch to use compat.v1. SAFETY:
                        Keep 1.* code intact and import compat.v1 module.
  --print_all           Print full log to stdout instead of just printing
                        errors

उदाहरण TF1 कोड

यहाँ एक साधारण TensorFlow 1.0 स्क्रिप्ट है:

head -n 65 models/samples/cookbook/regression/custom_regression.py | tail -n 10
# Calculate loss using mean squared error
  average_loss = tf.losses.mean_squared_error(labels, predictions)

  # Pre-made estimators use the total_loss instead of the average,
  # so report total_loss for compatibility.
  batch_size = tf.shape(labels)[0]
  total_loss = tf.to_float(batch_size) * average_loss

  if mode == tf.estimator.ModeKeys.TRAIN:
    optimizer = params.get("optimizer", tf.train.AdamOptimizer)

TensorFlow 2.x स्थापित होने के साथ यह नहीं चलता है:

(cd models/samples/cookbook/regression && python custom_regression.py)
Traceback (most recent call last):
  File "custom_regression.py", line 162, in <module>
    tf.logging.set_verbosity(tf.logging.INFO)
AttributeError: module 'tensorflow' has no attribute 'logging'

एक दस्तावेज

स्क्रिप्ट को एकल पायथन फ़ाइल पर चलाया जा सकता है:

!tf_upgrade_v2 \
  --infile models/samples/cookbook/regression/custom_regression.py \
  --outfile /tmp/custom_regression_v2.py
INFO line 38:8: Renamed 'tf.feature_column.input_layer' to 'tf.compat.v1.feature_column.input_layer'
INFO line 43:10: Renamed 'tf.layers.dense' to 'tf.compat.v1.layers.dense'
INFO line 46:17: Renamed 'tf.layers.dense' to 'tf.compat.v1.layers.dense'
INFO line 57:17: tf.losses.mean_squared_error requires manual check. tf.losses have been replaced with object oriented versions in TF 2.0 and after. The loss function calls have been converted to compat.v1 for backward compatibility. Please update these calls to the TF 2.0 versions.
INFO line 57:17: Renamed 'tf.losses.mean_squared_error' to 'tf.compat.v1.losses.mean_squared_error'
INFO line 61:15: Added keywords to args of function 'tf.shape'
INFO line 62:15: Changed tf.to_float call to tf.cast(..., dtype=tf.float32).
INFO line 65:40: Renamed 'tf.train.AdamOptimizer' to 'tf.compat.v1.train.AdamOptimizer'
INFO line 68:39: Renamed 'tf.train.get_global_step' to 'tf.compat.v1.train.get_global_step'
INFO line 83:9: tf.metrics.root_mean_squared_error requires manual check. tf.metrics have been replaced with object oriented versions in TF 2.0 and after. The metric function calls have been converted to compat.v1 for backward compatibility. Please update these calls to the TF 2.0 versions.
INFO line 83:9: Renamed 'tf.metrics.root_mean_squared_error' to 'tf.compat.v1.metrics.root_mean_squared_error'
INFO line 142:23: Renamed 'tf.train.AdamOptimizer' to 'tf.compat.v1.train.AdamOptimizer'
INFO line 162:2: Renamed 'tf.logging.set_verbosity' to 'tf.compat.v1.logging.set_verbosity'
INFO line 162:27: Renamed 'tf.logging.INFO' to 'tf.compat.v1.logging.INFO'
INFO line 163:2: Renamed 'tf.app.run' to 'tf.compat.v1.app.run'
TensorFlow 2.0 Upgrade Script
-----------------------------
Converted 1 files
Detected 0 issues that require attention
--------------------------------------------------------------------------------


Make sure to read the detailed log 'report.txt'

यदि स्क्रिप्ट कोड के लिए कोई समाधान नहीं ढूंढ पाती है तो स्क्रिप्ट त्रुटियों को प्रिंट करेगी।

निर्देशिका वृक्ष

इस सरल उदाहरण सहित विशिष्ट परियोजनाएं, एक से अधिक फाइलों का उपयोग करेंगी। आमतौर पर एक संपूर्ण पैकेज को अपडेट करना चाहते हैं, इसलिए स्क्रिप्ट को डायरेक्टरी ट्री पर भी चलाया जा सकता है:

# update the .py files and copy all the other files to the outtree
!tf_upgrade_v2 \
    --intree models/samples/cookbook/regression/ \
    --outtree regression_v2/ \
    --reportfile tree_report.txt
INFO line 82:10: tf.estimator.LinearRegressor: Default value of loss_reduction has been changed to SUM_OVER_BATCH_SIZE; inserting old default value tf.keras.losses.Reduction.SUM.

INFO line 105:2: Renamed 'tf.logging.set_verbosity' to 'tf.compat.v1.logging.set_verbosity'
INFO line 105:27: Renamed 'tf.logging.INFO' to 'tf.compat.v1.logging.INFO'
INFO line 106:2: Renamed 'tf.app.run' to 'tf.compat.v1.app.run'
INFO line 38:8: Renamed 'tf.feature_column.input_layer' to 'tf.compat.v1.feature_column.input_layer'
INFO line 43:10: Renamed 'tf.layers.dense' to 'tf.compat.v1.layers.dense'
INFO line 46:17: Renamed 'tf.layers.dense' to 'tf.compat.v1.layers.dense'
INFO line 57:17: tf.losses.mean_squared_error requires manual check. tf.losses have been replaced with object oriented versions in TF 2.0 and after. The loss function calls have been converted to compat.v1 for backward compatibility. Please update these calls to the TF 2.0 versions.
INFO line 57:17: Renamed 'tf.losses.mean_squared_error' to 'tf.compat.v1.losses.mean_squared_error'
INFO line 61:15: Added keywords to args of function 'tf.shape'
INFO line 62:15: Changed tf.to_float call to tf.cast(..., dtype=tf.float32).
INFO line 65:40: Renamed 'tf.train.AdamOptimizer' to 'tf.compat.v1.train.AdamOptimizer'
INFO line 68:39: Renamed 'tf.train.get_global_step' to 'tf.compat.v1.train.get_global_step'
INFO line 83:9: tf.metrics.root_mean_squared_error requires manual check. tf.metrics have been replaced with object oriented versions in TF 2.0 and after. The metric function calls have been converted to compat.v1 for backward compatibility. Please update these calls to the TF 2.0 versions.
INFO line 83:9: Renamed 'tf.metrics.root_mean_squared_error' to 'tf.compat.v1.metrics.root_mean_squared_error'
INFO line 142:23: Renamed 'tf.train.AdamOptimizer' to 'tf.compat.v1.train.AdamOptimizer'
INFO line 162:2: Renamed 'tf.logging.set_verbosity' to 'tf.compat.v1.logging.set_verbosity'
INFO line 162:27: Renamed 'tf.logging.INFO' to 'tf.compat.v1.logging.INFO'
INFO line 163:2: Renamed 'tf.app.run' to 'tf.compat.v1.app.run'
INFO line 58:10: tf.estimator.LinearRegressor: Default value of loss_reduction has been changed to SUM_OVER_BATCH_SIZE; inserting old default value tf.keras.losses.Reduction.SUM.

INFO line 101:2: Renamed 'tf.logging.set_verbosity' to 'tf.compat.v1.logging.set_verbosity'
INFO line 101:27: Renamed 'tf.logging.INFO' to 'tf.compat.v1.logging.INFO'
INFO line 102:2: Renamed 'tf.app.run' to 'tf.compat.v1.app.run'
INFO line 72:10: tf.estimator.DNNRegressor: Default value of loss_reduction has been changed to SUM_OVER_BATCH_SIZE; inserting old default value tf.keras.losses.Reduction.SUM.

INFO line 96:2: Renamed 'tf.logging.set_verbosity' to 'tf.compat.v1.logging.set_verbosity'
INFO line 96:27: Renamed 'tf.logging.INFO' to 'tf.compat.v1.logging.INFO'
INFO line 97:2: Renamed 'tf.app.run' to 'tf.compat.v1.app.run'
WARNING line 125:15: Changing dataset.make_one_shot_iterator() to tf.compat.v1.data.make_one_shot_iterator(dataset). Please check this transformation.

INFO line 40:7: Renamed 'tf.test.mock' to 'tf.compat.v1.test.mock'
TensorFlow 2.0 Upgrade Script
-----------------------------
Converted 7 files
Detected 1 issues that require attention
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
File: models/samples/cookbook/regression/automobile_data.py
--------------------------------------------------------------------------------
models/samples/cookbook/regression/automobile_data.py:125:15: WARNING: Changing dataset.make_one_shot_iterator() to tf.compat.v1.data.make_one_shot_iterator(dataset). Please check this transformation.



Make sure to read the detailed log 'tree_report.txt'

डेटासेट के बारे में एक चेतावनी नोट करें। dataset.make_one_shot_iterator फ़ंक्शन।

अब स्क्रिप्ट TensorFlow 2.x के साथ काम करती है:

ध्यान दें कि क्योंकि tf.compat.v1 मॉड्यूल TF 1.15 में शामिल है, परिवर्तित स्क्रिप्ट TensorFlow 1.15 में भी चलेगी।

(cd regression_v2 && python custom_regression.py 2>&1) | tail
I0922 22:16:42.778216 140254758430528 estimator.py:2074] Saving dict for global step 1000: global_step = 1000, loss = 651.5428, rmse = 3.684265
INFO:tensorflow:Saving 'checkpoint_path' summary for global step 1000: /tmp/tmpk2_4r192/model.ckpt-1000
I0922 22:16:42.817190 140254758430528 estimator.py:2135] Saving 'checkpoint_path' summary for global step 1000: /tmp/tmpk2_4r192/model.ckpt-1000
Tensor("IteratorGetNext:25", shape=(None,), dtype=float64, device=/device:CPU:0)
Tensor("Squeeze:0", shape=(None,), dtype=float32)

********************************************************************************

RMS error for the test set: $3684
प्लेसहोल्डर17

चिट्ठा

स्क्रिप्ट विस्तृत परिवर्तनों की एक सूची भी रिपोर्ट करती है। इस उदाहरण में इसे एक संभावित रूप से असुरक्षित परिवर्तन मिला और इसमें फ़ाइल के शीर्ष पर एक चेतावनी शामिल थी:

head -n 20 tree_report.txt
TensorFlow 2.0 Upgrade Script
-----------------------------
Converted 7 files
Detected 1 issues that require attention
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
File: models/samples/cookbook/regression/automobile_data.py
--------------------------------------------------------------------------------
models/samples/cookbook/regression/automobile_data.py:125:15: WARNING: Changing dataset.make_one_shot_iterator() to tf.compat.v1.data.make_one_shot_iterator(dataset). Please check this transformation.

================================================================================
Detailed log follows:

================================================================================
================================================================================
Input tree: 'models/samples/cookbook/regression/'
================================================================================
--------------------------------------------------------------------------------
Processing file 'models/samples/cookbook/regression/__init__.py'
 outputting to 'regression_v2/__init__.py'

Dataset.make_one_shot_iterator function के बारे में एक चेतावनी फिर से नोट करें।

अन्य मामलों में आउटपुट गैर-तुच्छ परिवर्तनों के तर्क की व्याख्या करेगा:

%%writefile dropout.py
import tensorflow as tf

d = tf.nn.dropout(tf.range(10), 0.2)
z = tf.zeros_like(d, optimize=False)
Writing dropout.py
!tf_upgrade_v2 \
  --infile dropout.py \
  --outfile dropout_v2.py \
  --reportfile dropout_report.txt > /dev/null
cat dropout_report.txt
TensorFlow 2.0 Upgrade Script
-----------------------------
Converted 1 files
Detected 0 issues that require attention
--------------------------------------------------------------------------------
================================================================================
Detailed log follows:

================================================================================
--------------------------------------------------------------------------------
Processing file 'dropout.py'
 outputting to 'dropout_v2.py'
--------------------------------------------------------------------------------

3:4: INFO: Changing keep_prob arg of tf.nn.dropout to rate, and recomputing value.

4:4: INFO: Renaming tf.zeros_like to tf.compat.v1.zeros_like because argument optimize is present. tf.zeros_like no longer takes an optimize argument, and behaves as if optimize=True. This call site specifies something other than optimize=True, so it was converted to compat.v1.
--------------------------------------------------------------------------------

यहां संशोधित फ़ाइल सामग्री है, ध्यान दें कि कैसे स्क्रिप्ट स्थानांतरित और नामित तर्कों से निपटने के लिए तर्क नाम जोड़ती है:

cat dropout_v2.py
import tensorflow as tf

d = tf.nn.dropout(tf.range(10), rate=1 - (0.2))
z = tf.compat.v1.zeros_like(d, optimize=False)
प्लेसहोल्डर26

किसी बड़े प्रोजेक्ट में कुछ त्रुटियां हो सकती हैं। उदाहरण के लिए डीपलैब मॉडल को कन्वर्ट करें:

!tf_upgrade_v2 \
    --intree models/research/deeplab \
    --outtree deeplab_v2 \
    --reportfile deeplab_report.txt > /dev/null

इसने आउटपुट फाइलों का उत्पादन किया:

ls deeplab_v2
README.md   datasets        input_preprocess.py        train.py
__init__.py deeplab_demo.ipynb  local_test.sh          utils
common.py   eval.py         local_test_mobilenetv2.sh  vis.py
common_test.py  export_model.py     model.py
core        g3doc           model_test.py

लेकिन त्रुटियां थीं। रिपोर्ट आपको यह तय करने में मदद करेगी कि इसे चलाने से पहले आपको क्या ठीक करना होगा। यहां पहली तीन त्रुटियां हैं:

cat deeplab_report.txt | grep -i models/research/deeplab | grep -i error | head -n 3
models/research/deeplab/eval.py:28:7: ERROR: Using member tf.contrib.slim in deprecated module tf.contrib. tf.contrib.slim cannot be converted automatically. tf.contrib will not be distributed with TensorFlow 2.0, please consider an alternative in non-contrib TensorFlow, a community-maintained repository such as tensorflow/addons, or fork the required code.
models/research/deeplab/eval.py:146:8: ERROR: Using member tf.contrib.metrics.aggregate_metric_map in deprecated module tf.contrib. tf.contrib.metrics.aggregate_metric_map cannot be converted automatically. tf.contrib will not be distributed with TensorFlow 2.0, please consider an alternative in non-contrib TensorFlow, a community-maintained repository such as tensorflow/addons, or fork the required code.
models/research/deeplab/export_model.py:25:7: ERROR: Using member tf.contrib.slim in deprecated module tf.contrib. tf.contrib.slim cannot be converted automatically. tf.contrib will not be distributed with TensorFlow 2.0, please consider an alternative in non-contrib TensorFlow, a community-maintained repository such as tensorflow/addons, or fork the required code.

"सुरक्षा" मोड

रूपांतरण स्क्रिप्ट में एक कम आक्रामक SAFETY मोड भी है जो tensorflow.compat.v1 मॉड्यूल का उपयोग करने के लिए आयात को आसानी से बदल देता है:

cat dropout.py
import tensorflow as tf

d = tf.nn.dropout(tf.range(10), 0.2)
z = tf.zeros_like(d, optimize=False)
tf_upgrade_v2 --mode SAFETY --infile dropout.py --outfile dropout_v2_safe.py > /dev/null
प्लेसहोल्डर34
cat dropout_v2_safe.py
import tensorflow.compat.v1 as tf

d = tf.nn.dropout(tf.range(10), 0.2)
z = tf.zeros_like(d, optimize=False)

जैसा कि आप देख सकते हैं कि यह आपके कोड को अपग्रेड नहीं करता है, लेकिन TensorFlow 1 कोड को TensorFlow 2 बायनेरिज़ के विरुद्ध चलने देता है। ध्यान दें कि इसका मतलब यह नहीं है कि आपका कोड समर्थित TF 2.x व्यवहार चला रहा है!

चेतावनियां

  • इस स्क्रिप्ट को चलाने से पहले अपने कोड के कुछ हिस्सों को मैन्युअल रूप से अपडेट न करें। विशेष रूप से, फ़ंक्शन जिन्होंने tf.argmax या tf.batch_to_space जैसे तर्कों को पुन: व्यवस्थित किया है, स्क्रिप्ट को गलत तरीके से कीवर्ड तर्क जोड़ते हैं जो आपके मौजूदा कोड को गलत तरीके से जोड़ते हैं।

  • स्क्रिप्ट मानती है कि tensorflow को tf के import tensorflow as tf के import tensorflow.compat.v1 as tf

  • यह स्क्रिप्ट तर्कों को पुन: व्यवस्थित नहीं करती है। इसके बजाय, स्क्रिप्ट उन कार्यों में कीवर्ड तर्क जोड़ती है जिनके तर्कों को पुन: व्यवस्थित किया गया है।

  • GitHub रिपॉजिटरी में Jupyter नोटबुक और पायथन फ़ाइलों को अपग्रेड करने के लिए एक सुविधाजनक टूल के लिए tf2up.ml देखें।

अपग्रेड स्क्रिप्ट बग की रिपोर्ट करने या फीचर अनुरोध करने के लिए, कृपया GitHub पर एक समस्या दर्ज करें।