天天看點

李宏毅 DeepLearning -2017-Hello world of deep learning (keras)and Demo

李宏毅 DeepLearning -2017-Hello world of deep learning (keras)and Demo

第一步:搭積木:設定神經網絡架構(k re a s)新版的keras2.0将output_dim改成了unit,最後選擇輸出的activation為softmax保證輸出介于(0~1)之間

李宏毅 DeepLearning -2017-Hello world of deep learning (keras)and Demo

第二步:設定loss function來衡量model的優越性和學習走向

李宏毅 DeepLearning -2017-Hello world of deep learning (keras)and Demo

第三步:Train部分,設定優化方法opt(都是gradient 的方法),batchSize:實際中是把訓練資料分成随機的等分塊進行訓練,batchSize指的是這個塊的大小,在這裡指100張圖檔,把100個example放到一個batch當中。把所有的batch都做一次叫做一個epoch,一次疊代。

李宏毅 DeepLearning -2017-Hello world of deep learning (keras)and Demo
李宏毅 DeepLearning -2017-Hello world of deep learning (keras)and Demo

**資料處理,把訓練資料放入numpy arrray中:x_train輸入10000張2828圖檔,那麼資料維數是10000784,屬于二維的matrix

y_train輸入10000張圖檔的标簽,每一列代表一個标簽,圖中第一個标簽是{0,0,0,0,0,1,0,0,0,0},代表數字“5”**

李宏毅 DeepLearning -2017-Hello world of deep learning (keras)and Demo

****第4步:自己調節Min-batch,會影響運算時間和運算結果batch_size的大小設定有所講究,對于GPU來說,設定太小的話,batch數量就多,就要分很多次計算,運算時間會比較長,設定太大的話,每個batch裡面一次調整很多參數可能會出錯。

李宏毅 DeepLearning -2017-Hello world of deep learning (keras)and Demo
李宏毅 DeepLearning -2017-Hello world of deep learning (keras)and Demo

加入gpu的計算方法:

李宏毅 DeepLearning -2017-Hello world of deep learning (keras)and Demo

第五步:模型的儲存和測試

李宏毅 DeepLearning -2017-Hello world of deep learning (keras)and Demo

第六步:調參數

模型需要調整Loss Function,梯度下降方法以及層數獲得最好的效果

繼續閱讀