Currently, Tensorflow library is undergoing changes since the launch of the largest. TensorFLow 2.0 has launched a beta version, compared with TensorFlow 1.x version it brought a lot of change. The biggest problem is not compatible with a lot of TensorFlow 1.x version of the API.
How to do?
Select versions
Although version 2.0 of TensorFlow, added a lot of new features groomed. But TensorFlow 1.x currently relatively stable, it is recommended to use TensorFlow 1.x version of the actual project development, and follow-up technical 2.x version update. Wait until more stable versions 2.x when we come to consider the actual project will switch to 2.x.
Response options
TensorFlow version 1.x and 2.x versions of the framework quite different. Recommended 1.x and 2.x versions coexist way to solve.
Anaconda create a virtual environment
-
View current virtual environment
Use
conda info --envs
to view the current environmental informationbase * /anaconda3
Showing results can be seen, the current name of the virtual environment is the "base", is the Anaconda default Python environment.
-
Use
python --version
to see the version of PythonPython 3.7.3
You may know, the current Python version 3.7.3.
-
Create a virtual Python environment
conda create --name tf2 python=3.7.3
The following packages will be downloaded: package | build ---------------------------|----------------- ca-certificates-2019.5.15 | 0 133 KB certifi-2019.6.16 | py37_0 154 KB openssl-1.1.1c | h1de35cc_1 3.4 MB pip-19.1.1 | py37_0 1.8 MB setuptools-41.0.1 | py37_0 635 KB sqlite-3.29.0 | ha441bb4_0 2.4 MB wheel-0.33.4 | py37_0 39 KB ------------------------------------------------------------ Total: 8.5 MB The following NEW packages will be INSTALLED: ca-certificates pkgs/main/osx-64::ca-certificates-2019.5.15-0 certifi pkgs/main/osx-64::certifi-2019.6.16-py37_0 libcxx pkgs/main/osx-64::libcxx-4.0.1-hcfea43d_1 libcxxabi pkgs/main/osx-64::libcxxabi-4.0.1-hcfea43d_1 libedit pkgs/main/osx-64::libedit-3.1.20181209-hb402a30_0 libffi pkgs/main/osx-64::libffi-3.2.1-h475c297_4 ncurses pkgs/main/osx-64::ncurses-6.1-h0a44026_1 openssl pkgs/main/osx-64::openssl-1.1.1c-h1de35cc_1 pip pkgs/main/osx-64::pip-19.1.1-py37_0 python pkgs/main/osx-64::python-3.7.3-h359304d_0 readline pkgs/main/osx-64::readline-7.0-h1de35cc_5 setuptools pkgs/main/osx-64::setuptools-41.0.1-py37_0 sqlite pkgs/main/osx-64::sqlite-3.29.0-ha441bb4_0 tk pkgs/main/osx-64::tk-8.6.8-ha441bb4_0 wheel pkgs/main/osx-64::wheel-0.33.4-py37_0 xz pkgs/main/osx-64::xz-5.2.4-h1de35cc_4 zlib pkgs/main/osx-64::zlib-1.2.11-h1de35cc_3
Proceed ([y]/n)?
Creation process will be prompted to install the software packages, enter "Y", then download and install the package.
Downloading and Extracting Packages wheel-0.33.4 | 39 KB | ############################################################ | 100% openssl-1.1.1c | 3.4 MB | ############################################################ | 100% certifi-2019.6.16 | 154 KB | ############################################################ | 100% setuptools-41.0.1 | 635 KB | ############################################################ | 100% pip-19.1.1 | 1.8 MB | ############################################################ | 100% sqlite-3.29.0 | 2.4 MB | ############################################################ | 100% ca-certificates-2019 | 133 KB | ############################################################ | 100% Preparing transaction: done Verifying transaction: done Executing transaction: done # # To activate this environment, use # # $ conda activate tf2 # # To deactivate an active environment, use # # $ conda deactivate
Virtual environment
tf2
created successfully.conda activate tf2 #将虚拟环境tf2作为当前的Python环境 conda deactivate #使用默认的Python环境
If you are using Windows, activate and deactivate the virtual environment of the command is as follows:
activate tf2 deactivate
-
Check the Python virtual environment is created successfully
conda info --envs
display:
# conda environments: # base * /anaconda3 tf2 /anaconda3/envs/tf2
It can be seen in the virtual environment more than a "tf2", it means creating success.
-
Delete Python virtual environment
conda remove --name tf2 --all
Run the above command to delete the
tf2
virtual environment, there will be no display. It can be usedconda info --envs
to check the virtual environment situation again. -
Python installed in the virtual environment TensorFlow 2.0
conda activate tf2 #激活tf2虚拟环境 pip install tensorflow==2.0.0-alpha0 #安装TensorFlow 2.0版
-
Code upgrade tool
In TensorFlow 2.x version, it provides a tool to upgrade TensorFlow 1.x version of the code --tf_upgrade_v2. This tool can be very easy to write the code TensorFlow 1.x version ported to TensorFlow 2.x in.
tf_upgrade_v2 --infile "1.x代码文档" -outfile "2.x代码文档"
tf_upgrade_v2 document conversion tools support single and multiple document batch conversion in two ways.
-
Upgrading a single code
tf_upgrade_v2 --infile foo_v1.py --outfile foo_v2.py
-
Batch code upgrades
tf_upgrade_v2 -intree foo_v1 -outtree foo_v2
Here
foo_v1
refers to the 1.x code documentation directory,foo_v2
refers to the upgraded 2.x code documentation storage directory.Note that tf_upgrade_v2 tools are not a panacea, it can only achieve the basic API upgrade. After the conversion is completed generally have to manually modify secondary.
-
-
The impact 2.x version for TF-Hub, T2T and other library
No effect. Both libraries support both 1.x and 2.x.
Original link large column https://www.dazhuanlan.com/2019/08/17/5d576c490a0cc/