tensorflow2在去年剛剛發布了,大號時機正是學習tensorflow2的寶貴之時,這裡使用tensorflow2實現乙個入門級別的任務:計算a+b的結果
import tensorflow as tf
import os
os.environ[
"tf_cpp_min_log_level"]=
"3"a = tf.constant(2.
)b = tf.constant(4.
)print
('a+b='
,a+b)
這裡的os.environ[「tf_cpp_min_log_level」] = "3"實現了對於waring警告的遮蔽,從而簡化了輸出的介面
列印對應的helloworld語句
import tensorflow as tf
import os
os.environ[
"tf_cpp_min_log_level"]=
"3"#列印'hello world'對應的語句
hello = tf.constant(
'hello world'
)print
(hello.numpy(
))
tensorflow2的資料載入
對於一些小型常用的資料集,tensorflow有相關的api可以呼叫 keras.datasets 經典資料集 1 boston housing 波士頓房價 2 mnist fasion mnist 手寫數字集 時髦品集 3 cifar10 100 物象分類 4 imdb 電影評價 使用 tf.da...
Tensorflow2 自動求導機制
tensorflow 引入了 tf.gradienttape 這個 求導記錄器 來實現自動求導 如何使用 tf.gradienttape 計算函式 y x x 2 在 x 3 時的導數 import tensorflow as tf x tf.variable initial value 3.初始化...
tensorflow2建立卷積核Conv2D函式
使用conv2d可以建立乙個卷積核來對輸入資料進行卷積計算,然後輸出結果,其建立的卷積核可以處理二維資料。依次類推,conv1d可以用於處理一維資料,conv3d可以用於處理三維資料。在進行神經層級整合時,如果使用該層作為第一層級,則需要配置input shape引數。在使用conv2d時,需要配置...