- Mastering TensorFlow 1.x
- Armando Fandango
- 275字
- 2021-06-25 22:50:54
Code warm-up - Hello TensorFlow
As a customary tradition when learning any new programming language, library, or platform, let's write the simple Hello TensorFlow code as a warm-up exercise before we pe deeper.
We assume that you have already installed TensorFlow. If you have not, refer to the TensorFlow installation guide at https://www.tensorflow.org/install/ for detailed instructions to install TensorFlow.
Open the file ch-01_TensorFlow_101.ipynb in Jupyter Notebook to follow and run the code as you study the text.
- Import the TensorFlow Library with the following code:
import tensorflow as tf
- Get a TensorFlow session. TensorFlow offers two kinds of sessions: Session() and InteractiveSession(). We will create an interactive session with the following code:
tfs = tf.InteractiveSession()
The only difference between Session() and InteractiveSession() is that the session created with InteractiveSession() becomes the default session. Thus, we do not need to specify the session context to execute the session-related command later. For example, say that we have a session object, tfs, and a constant object, hello. If tfs is an InteractiveSession() object, then we can evaluate hello with the code hello.eval(). If tfs is a Session() object, then we have to use either tfs.hello.eval() or a with block. The most common practice is to use the with block, which will be shown later in this chapter.
- Define a TensorFlow constant, hello:
hello = tf.constant("Hello TensorFlow !!")
- Execute the constant in a TensorFlow session and print the output:
print(tfs.run(hello))
- You will get the following output:
'Hello TensorFlow !!'
Now that you have written and executed the first two lines of code with TensorFlow, let's look at the basic ingredients of TensorFlow.
- 網(wǎng)絡(luò)服務(wù)器配置與管理(第3版)
- SDL Game Development
- 電腦維護(hù)365問(wèn)
- 筆記本電腦維修不是事兒(第2版)
- Large Scale Machine Learning with Python
- Machine Learning Solutions
- 3D Printing Blueprints
- 基于網(wǎng)絡(luò)化教學(xué)的項(xiàng)目化單片機(jī)應(yīng)用技術(shù)
- The Applied Artificial Intelligence Workshop
- 零基礎(chǔ)輕松學(xué)修電腦主板
- Exceptional C++:47個(gè)C++工程難題、編程問(wèn)題和解決方案(中文版)
- 計(jì)算機(jī)組裝與維護(hù)教程
- 超炫的35個(gè)Arduino制作項(xiàng)目
- 電腦組裝與維修實(shí)戰(zhàn)
- Arduino項(xiàng)目開(kāi)發(fā):智能控制