'I can't run tf_upgrade_v2 to migrate to tensorflow 2
I try to do the following steps to migrate from TensorFlow 1 to TensorFlow 2: https://www.tensorflow.org/guide/upgrade. I can do this in Google Colab but I can't do this on my laptop.
To do so, I first tried to run the following command in Powershell (I'm on Windows, also my working directory contains the project folder):
tf_upgrade_v2 --intree project/ --outtree project2/ --reportfile report.txt
It says that "The term 'tf_upgrade_v2' is not recognized ..."
Then, I downloaded file tf_upgrade_v2.py from the TensorFlow repository and tries to run the following command:
python tf_upgrade_v2.py --intree project/ --outtree project2/ --reportfile report.txt
It works for some time, then finishes, but there is no changes in the folder.
Finally, I tried this:
tf_upgrade_v2.py --intree project/ --outtree projects2/ --reportfile report.txt
It opens another terminal for some time, then finishes, but there is no changes.
I have TensorFlow 2.0 according to pip list
. I use conda
UPD:
conda list
doesn't contain tensorflow, only tensorboard, tensorflow-estimator, tensorflow-hub
Solution 1:[1]
I had the same issue, running python on windows using Visual Studio 2019. The short version, if you already know the location of the upgrade script, is instead of tf_upgrade_v2.py
I needed to run tf_upgrade_v2_main.py
as the former simply ran and did nothing.
Detailed steps:
The actual steps to running the upgrade script were more involved to figure out. TLDR; from the folder where you want to perform the upgrade run the following command:
"C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\python" "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\Lib\site-packages\tensorflow\tools\compatibility\tf_upgrade_v2_main.py" --infile NeuralTransfer-tf1.py --outfile NeuralTransfer-tf2.py
Be sure to replace C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\
with the path to your python install directory as needed. Also be sure to set the --infile and --outfile arguments accordingly.
To locate tf_upgrade_v2.py
, which per the documentation should be installed with TensorFlow 1.13 and later (including all TF 2.0 builds), simply search for the file in your python install directory in windows explorer.
In my case tf_upgrade_v2.py
was located (relative to the install directory) in Lib\site-packages\tensorflow\tools\compatibility\tf_upgrade_v2_main.py
as shown in the command line arguments above.
It can be also located under c:\users\user\appdata\roaming\python\python_xx\site-packages
(if pip is used pip show tensorflow
can be used)
Solution 2:[2]
For colab run this:
os.environ.get("tf_upgrade_v2")
And then this:
!tf_upgrade_v2 \
--intree xyz \
--outtree zyx \
--reportfile xyzyx
Solution 3:[3]
For me it is working by following line of code.
!tf_upgrade_v2 \
--intree models/xyz/cookbook/ROL/ \
--outtree Rol_v2/ \
--reportfile tree_report.txt
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | primus |
Solution 2 | ouflak |
Solution 3 | wish |