iT邦幫忙

2021 iThome 鐵人賽

DAY 22
0
AI & Data

我比機器更需要學習系列 第 22

Day22 影像辨識實作

教電腦判斷是圈圈還是叉叉

我們先來看看我們的資料集(下圖),看黃色的部分就好,因為像素低的關係,所以圈圈比較不圈;叉叉也比較不叉,但還是看的出來吧。
https://ithelp.ithome.com.tw/upload/images/20210926/20137546marLZ0bkLU.png

再來我們將圖片轉換成特徵值,透過flatten()或reshape()函示,可以看到二維的資料變成一維的。

https://ithelp.ithome.com.tw/upload/images/20210926/20137546PZcCmv9wWL.png

接著建立神經網路,再將資料丟到進去訓練,最後得出準確率、預計及實際結果。

score: [0.47942981123924255, 1.0]
Ans: 0 1
predict_classes: [0 1]
y_test [0 1]

好像只辨識圈叉太無趣了,所以拿MNIST手寫庫的資料來玩玩,總共有60000筆訓練資料特徵(X)及標籤答案(Y),每一筆X的大小為28(長) * 28(寬),用來存放灰階資料,數值介於0~255。

Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz
11493376/11490434 [==============================] - 4s 0us/step
x_train = (60000, 28, 28)
y_train = (60000,)

我再導入函式時,出現以下問題,後來用 import tensorflow_datasets就解決了。

ModuleNotFoundError: No module named 'tensorflow.examples'

我們可以看到第0筆資料如下:

https://ithelp.ithome.com.tw/upload/images/20210926/20137546KV54pNkWiU.png

再匯入更多資料看看。

https://ithelp.ithome.com.tw/upload/images/20210926/20137546jFuZVVh6AW.png

最後得出準確率、預計及實際結果。有點小誤差沒關係啦/images/emoticon/emoticon01.gif

score: [0.2194502204656601, 0.9416000247001648]
Ans: 7 2 1 0
predict_classes: [7 2 1 0 4 1 4 9 6 9]
y_test [7 2 1 0 4 1 4 9 5 9]

Reference:TensorFlow 2.x人工智慧、機器學習超炫範例200+


上一篇
Day21 TensorFlow&OpenCV簡介
下一篇
Day23 爬取IG照片
系列文
我比機器更需要學習23
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言