Tensorflow實作_阿拉伯手寫數字分類的實作_基本功常見操作
本篇實作 使用python3.11 tensorflow2.20 ->這個裝好通常會自動把numpy2.4.6、tensorboard2.20、h5py 也裝好 matplotlib3.11.1 numpy2.4.6 tensorboard2.20 第一次於專案裝會要等大概10~15分鐘,會要等好一陣子。 Phase1程式碼-載入mnist資料集 嘗試透過將像素值內容非0的統一轉為1,觀察圖像張量資料。 import tensorflow as tf mnist = tf.keras.datasets.mnist # 匯入 MNIST 阿拉伯數字訓練資料 (x_train, y_train),(x_test, y_test) = mnist.load_data() # 訓練/測試資料的 X/y 維度 print ( "訓練資料X維度:{0}" .format(x_train.shape)) print ( "訓練資料Y維度:{0}" .format(y_train.shape)) print ( "測試資料X維度:{0}" .format(x_test.shape)) print ( "測試資料X維度:{0}" .format(y_test.shape)) # 訓練資料前10筆圖片的數字標準答案 print (y_train[: 10 ]) print (x_train[ 0 ]) #打印第一張訓練圖的像素值矩陣 data = x_train[ 0 ].copy() data[data> 0 ]= 1 #把非0的數字轉為1,顯示第1張圖片 print ( "==========================================" ) #把轉換後二維矩陣內容印出來,可以隱約看出數字為5 text_image=[] for i in range (data.shape[ 0 ]): text_image.append( '' .join( str (data[i]))) for i, row in enumerate (text_image): if i < len (...