This tutorial is based on TensorFlow 2.0 + Keras Crash Course, and has been appropriately summarized and adapted on the basis of the original text, so as to adapt to the understanding and use of domestic developers, the level is limited, if written wrong, welcome to comment on it. If you think the article is useful, please click the “like” button. If you want to see the original article, you can click the link kX to visit the Internet.
The zero sequence
After four years of development, TensorFlow has emerged as the dominant deep learning and machine learning framework, with market share and users far ahead of its competitors. The figure below is a survey of the use of machine learning frameworks in 2018 by KDnuggets website. It can be seen that TensorFlow was already far ahead of the competition (Keras was an upper-layer package and TensorFlow was called at the bottom), establishing its position as the king of deep learning.
If you want to know the history of TensorFlow, you can check out my CSDN article: “The Road to Hegemony” from 0.1 to 2.0 to see the history of TensorFlow
Both TensorFlow and Keras were released four years ago (March 2015 for Keras, November 2015 for TensorFlow). That’s a long time in the age of deep learning!
In the past, TensorFlow 1.x + Keras had a number of known problems:
- Working with TensorFlow means dealing with static computation diagrams, which can be awkward and difficult for programmers used to imperative coding.
- While the TensorFlow API is very powerful and flexible, it lacks refinement and is often confusing or difficult to use.
- Although Keras is productive and easy to use, it is often inflexible for research use cases.
TensorFlow 2.0 is built on the following key ideas:
- Let users run their calculations as eagerly as they would in Numpy. This makes TensorFlow 2.0 programming intuitive compared to Pythonic.
- Retain the significant benefits of compiled graphics (for performance, distribution, and deployment). This makes TensorFlow fast, scalable, and production-ready.
- Using Keras as its advanced deep learning API makes TensorFlow easy to learn and efficient.
- Extend Keras to a range of workflows from very advanced (easier to use, less flexible) to very low-level (requiring more expertise, but providing great flexibility).
This series of tutorials combines the flexibility of ****TensorFlow 2.0 with the simplicity of Keras to enable developers to master TensorFlow 2.0 and Keras in just a few days. However, in order to truly master and understand the deep learning technology and develop interesting and fun applications, the learning of the concept of deep learning is indispensable and requires readers to spend a lot of time to learn and understand. Finally, we hope that we should not be superficial in the development of deep learning, but should understand the meaning and characteristics of algorithms, rather than simply call interfaces. That’s the difference between a deep learning engineer and a programmer.
This tutorial series consists of three parts:
- Environment to prepare
- TensorFlow Usage Guide
- Use of the Keras interface
This course will be launched on my Planet of Knowledge: AI Deep learning application road · The price of a few cups of milk tea learning master deep learning, welcome to click visit.
1 Environment Preparation
For the installation of TensorFlow2.0, please refer to the author’s detailed installation tutorial: “TensorFlow2.0 official version” simple installation of TF2.0 official version (CPU&GPU) tutorial. For the demonstration, only the installation of TF2.0 CPU is shown here.
I am currently on Windows10, using a python environment managed by conda, installing cuda and cudnn via conda (GPU support), and tensorflow2.0 via PIP. After trying only the simplest way to install, do not need to configure complex environment.
(The installation of Ubuntu and MAC versions can follow this method, because Conda supports multiple platforms, there should be no problem, if you have more questions, please feel free to comment, I will update the Ubuntu installation tutorial later)
1.0 ConDA Environment Preparation
Conda is a great Python management tool that makes it easy to set up and manage multiple Python environments. I will also introduce some common conda directives in the following installation steps.
Conda I recommend installing Miniconda, which can be understood as a stripped-down version of Anaconda, with only the necessary components, so it will be much faster to install, and it will also be able to manage our Python environment. (Anaconda typically takes a few gigabytes of memory and takes 1-2 hours to install on a SOLID state drive. Miniconda typically takes a few hundred megabytes and can be installed in 10 minutes.)
Miniconda recommended source download: tsinghua mirrors.tuna.tsinghua.edu.cn/anaconda/mi…
Just pick the version that works for you,
- Windows recommend address: mirrors.tuna.tsinghua.edu.cn/anaconda/mi…
- Ubuntu recommended address: mirrors.tuna.tsinghua.edu.cn/anaconda/mi…
- Mac OS recommended address: mirrors.tuna.tsinghua.edu.cn/anaconda/mi…
Install Miniconda for Windows as a demonstration. Download the appropriate version from above, open it as administrator and click Install.
Note that both are checked, one is to allow us to use the conda directive directly in CMD, and the other is to use Miniconda’s python3.7 as system Python.
After the installation, you can use the conda command in CMD, CMD to open the way, Windows key +R key, pop up the input box, enter CMD to enter. You can also directly search for CMD in Windows and hit Run.
Here are some CMD conda directives:
- Check the conda environment: conda env list
- To create a conda environment (env_name is the name of the created environment and can be customized) : conda create -n env_name
- Activate the conda environment (Ubuntu and Macos replace conda with source) : conda activate env_name
- Exit the conda environment: conda deactivate
- Conda install numpy # conda uninstall numpy
- To view the list of installed Python, run the conda list -n env_name command
Knowing these instructions, you can start using Conda to create a new environment to install TF2.0.
1.1 TF2.0 CPU version Installation
TF CPU installation is relatively easy, because there is no need to configure GPU, so Windows Ubuntu macOS installation method is similar, the disadvantage is that the running speed is slow, but it can be used for daily learning.
The following is a demonstration of the Windows version: All operations are performed on the command line
1.1.0 Create TF2.0 CPU environment (use conda python=3.6 to indicate python3.6 at the same time)
Conda create -n TF_2C python=3.6Copy the code
Proceed ([y]/n)? Type y enter
When you’re done, you can enter the environment
1.1.1 Entering the TF_2C Environment
conda activate TF_2C
Copy the code
After entering, we can find :(TF_2C) before the previous path, indicating entering the environment.
1.1.2 Installing TF2.0 CPU version (the -i after means download from Domestic Tsinghua source, which is much faster than the default source)
PIP install tensorflow = = 2.0.0 -i https://pypi.tuna.tsinghua.edu.cn/simpleCopy the code
If the network is bad, perform several times. And then it’s all set up after a while. So let’s do a simple test.
1.1.3 Test the TF2.0 CPU version (save the following code to demo.py and run it using TF_2C Python)
import tensorflow as tf
version = tf.__version__
gpu_ok = tf.test.is_gpu_available()
print("tf version:",version,"\nuse GPU",gpu_ok)
Copy the code
If there is no problem, the output is as follows: tf version 2.0.0 is CPU version, so GPU is False
Tf version: 2.0.0 use GPU FalseCopy the code