熱線電話:13121318867

登錄
首頁精彩閱讀Python深度學習之圖像識別
Python深度學習之圖像識別
2019-11-19
收藏
Python<a href='/map/shenduxuexi/' style='color:#000;font-size:inherit;'>深度學習</a>之圖像識別

作者 | 周偉能

來源 | 小叮當講SAS和Python

Python在機器學習(人工智能,AI)方面有著很大的優勢。談到人工智能,一般也會談到其實現的語言Python。前面有幾講也是關于機器學習在圖像識別中的應用。今天再來講一個關于運用google的深度學習框架tensorflow和keras進行訓練深度神經網絡,并對未知圖像進行預測。

導入python模塊

Python<a href='/map/shenduxuexi/' style='color:#000;font-size:inherit;'>深度學習</a>之圖像識別

導入圖像數據

Python<a href='/map/shenduxuexi/' style='color:#000;font-size:inherit;'>深度學習</a>之圖像識別
Python<a href='/map/shenduxuexi/' style='color:#000;font-size:inherit;'>深度學習</a>之圖像識別

合并列表數據

Python<a href='/map/shenduxuexi/' style='color:#000;font-size:inherit;'>深度學習</a>之圖像識別

將圖片數據轉化為數組

Python<a href='/map/shenduxuexi/' style='color:#000;font-size:inherit;'>深度學習</a>之圖像識別

顯示一張圖片

Python<a href='/map/shenduxuexi/' style='color:#000;font-size:inherit;'>深度學習</a>之圖像識別
Python<a href='/map/shenduxuexi/' style='color:#000;font-size:inherit;'>深度學習</a>之圖像識別
Python<a href='/map/shenduxuexi/' style='color:#000;font-size:inherit;'>深度學習</a>之圖像識別
Python<a href='/map/shenduxuexi/' style='color:#000;font-size:inherit;'>深度學習</a>之圖像識別

訓練神經網絡

Python<a href='/map/shenduxuexi/' style='color:#000;font-size:inherit;'>深度學習</a>之圖像識別
Python<a href='/map/shenduxuexi/' style='color:#000;font-size:inherit;'>深度學習</a>之圖像識別

我們可以看到測試集的準確率達到99.67%

預測一個圖像

Python<a href='/map/shenduxuexi/' style='color:#000;font-size:inherit;'>深度學習</a>之圖像識別
Python<a href='/map/shenduxuexi/' style='color:#000;font-size:inherit;'>深度學習</a>之圖像識別
Python<a href='/map/shenduxuexi/' style='color:#000;font-size:inherit;'>深度學習</a>之圖像識別
Python<a href='/map/shenduxuexi/' style='color:#000;font-size:inherit;'>深度學習</a>之圖像識別
Python<a href='/map/shenduxuexi/' style='color:#000;font-size:inherit;'>深度學習</a>之圖像識別

預測為汽車的概率為100%。(括號內為真實標簽)

Python<a href='/map/shenduxuexi/' style='color:#000;font-size:inherit;'>深度學習</a>之圖像識別
Python<a href='/map/shenduxuexi/' style='color:#000;font-size:inherit;'>深度學習</a>之圖像識別

預測為美女的概率為100%。(括號內為真實標簽)

Python<a href='/map/shenduxuexi/' style='color:#000;font-size:inherit;'>深度學習</a>之圖像識別
Python<a href='/map/shenduxuexi/' style='color:#000;font-size:inherit;'>深度學習</a>之圖像識別

測試集中前15個圖像預測完全正確。Nice!

最后我們來識別單張圖片。

Python<a href='/map/shenduxuexi/' style='color:#000;font-size:inherit;'>深度學習</a>之圖像識別
Python<a href='/map/shenduxuexi/' style='color:#000;font-size:inherit;'>深度學習</a>之圖像識別
Python<a href='/map/shenduxuexi/' style='color:#000;font-size:inherit;'>深度學習</a>之圖像識別

結果預測為汽車。Nice!

最后來預測一下外部隨便下載的汽車或美女圖片

Python<a href='/map/shenduxuexi/' style='color:#000;font-size:inherit;'>深度學習</a>之圖像識別
Python<a href='/map/shenduxuexi/' style='color:#000;font-size:inherit;'>深度學習</a>之圖像識別
Python<a href='/map/shenduxuexi/' style='color:#000;font-size:inherit;'>深度學習</a>之圖像識別
Python<a href='/map/shenduxuexi/' style='color:#000;font-size:inherit;'>深度學習</a>之圖像識別

預測為汽車,不錯!

小編這里有10張圖片,前5張為汽車圖片,后五張為美女圖片。

下面進行批量預測:

Python<a href='/map/shenduxuexi/' style='color:#000;font-size:inherit;'>深度學習</a>之圖像識別
Python<a href='/map/shenduxuexi/' style='color:#000;font-size:inherit;'>深度學習</a>之圖像識別

結果也是完全正確。

看到這里,感覺神經網絡是不是很神奇,要想讓神經網絡預測得準確,我們就必須給予大量的數據進行訓練模型,優化模型,以至于達到準確識別圖像的目的,圖像識別作為人工智能的一部分,現在已經慢慢走向成熟,雖然機器也有出錯的時候,但是進過不斷優化,錯誤率將會越來越小,相信機器智能或者人工智能時代能夠創造出更多智能而美好的東西。為社會,為人類的自由做出更大的貢獻。

數據分析咨詢請掃描二維碼

若不方便掃碼,搜微信號:CDAshujufenxi

數據分析師資訊
更多

OK
客服在線
立即咨詢
日韩人妻系列无码专区视频,先锋高清无码,无码免费视欧非,国精产品一区一区三区无码
客服在線
立即咨詢