lesson two

這節(jié)課我們會(huì)用Jeremy's的方法來做貓狗識(shí)別的競(jìng)賽。我們會(huì)研究神經(jīng)網(wǎng)絡(luò)的結(jié)構(gòu),如何初始化參數(shù)并且提高結(jié)果的準(zhǔn)確率,然后我們會(huì)研究如何用keras來構(gòu)造線性模型,最后我們將討論激活層的作用并且學(xué)習(xí)怎樣訓(xùn)練一個(gè)vgg模型來分類貓和狗

教學(xué)方法

在學(xué)習(xí)這節(jié)課之前,我們想先介紹這門課的學(xué)習(xí)方法:
先花30分鐘自己鉆研
然后你可以尋求幫助
如果你有問題,詳細(xì)描述他們來加速解決問題的過程
用wiki上提供的資源

Jeremy's 的方案

計(jì)劃

首先是下載數(shù)據(jù),然后創(chuàng)造驗(yàn)證集,然后將圖片移動(dòng)到合適的目錄文件下,然后進(jìn)行訓(xùn)練并且提交。
jupyter的一些命令:可以用%開始來選擇一些命令然后看他們的說明
可以有那個(gè)!開始一些bash命令

數(shù)據(jù)準(zhǔn)備

創(chuàng)建一個(gè)有效的文件夾并從列車文件夾中移動(dòng)2000個(gè)隨機(jī)樣本進(jìn)入它。
創(chuàng)建一個(gè)示例文件夾。
在你的樣本文件夾中,創(chuàng)建一個(gè)訓(xùn)練文件夾并從火車上復(fù)制200個(gè)隨機(jī)樣本。
再次,在您的示例文件夾中,創(chuàng)建一個(gè)有效的文件夾并從訓(xùn)練文件上復(fù)制50個(gè)隨機(jī)樣本。
為您的有效樣本和訓(xùn)練文件夾創(chuàng)建一個(gè)貓文件夾和一個(gè)狗文件夾
將所有的貓樣本移動(dòng)到貓文件夾中,把你所有的狗樣品移到狗夾里
以上的操作都可以在terminal里面用ls,mv,cp,shuf,head等等完成

Finetune and Train

vgg.model.save_weights(path+'results/ft1.h5')

我們?cè)谶@里所做的就是保存我們?cè)谖⒄{(diào)后學(xué)習(xí)的權(quán)重,并將我們的模型擬合到這個(gè)數(shù)據(jù)集。這有明顯的優(yōu)勢(shì),它允許我們?cè)诿看问褂迷撃P蜁r(shí)跳過這一步。它還允許我們跟蹤我們的模型的不同版本:當(dāng)我們繼續(xù)訓(xùn)練它時(shí),我們可能會(huì)過度擬合或者結(jié)束一個(gè)比前一次迭代不那么理想的模型。因此,在每個(gè)獨(dú)特的擬合過程之后保存模型權(quán)重是有好處的。

from IPython.display import FileLink
FileLink('data/redux/subm98.csv')

Jeremy's Findings

logloss的公式如下:


\begin{align}-\frac1N\sum_{n=1}^N\ \bigg[y_n \log \hat y_n + (1 - y_n) \log (1 - \hat y_n)\bigg],,\end{align}

In Keras, we also call this "binary entropy", and it is a particular subset of "categorical cross-entropy" (particularly in Keras).
可以嘗試用更多的epochs來提升模型的準(zhǔn)確率
如果你用了多個(gè)epochs,你可以選擇分開來檢測(cè)預(yù)測(cè)的結(jié)果
如果你的準(zhǔn)確率不是那么合適,嘗試降低學(xué)習(xí)率

vgg.model.optimizer.lr = 0.01

可視化結(jié)果

在可視化的時(shí)候我們需要以下幾類: 一些隨機(jī)的正確的樣本,一些隨機(jī)的錯(cuò)誤的樣本,每一類中最正確的標(biāo)簽,每一類中最不正確的,最不確定的標(biāo)簽

image.png
image.png
image.png
image.png
image.png
image.png
image.png

然后我們可以畫出它的confusion matrix

cm = confusion_matrix(val_classes, preds)
plot_confusion_matrix(cm, val_batches.class_indices)

神經(jīng)網(wǎng)絡(luò)


Looking at the spreadsheet before we begin.


The values in the purple circle belong to our input vector, and the values in the yellow circle belong to our target vector y. We want to perform a series of matrix products to get as close to the target vector y as possible.


(1) Matrix multiplication between the input vector and the first weights matrix, 1st column. Resulting in the first activation vector's 1st value.

[圖片上傳中。。。(4)]
(2) Matrix multiplication between the input vector and the first weights matrix, 2nd column. Resulting in the first activation vector's 2nd activation value.

[圖片上傳中。。。(5)]
(3) Matrix multiplication between the first activations vector and the second weights matrix, 1st column. Resulting in the second activation vector's 1st value.


(4) Matrix multiplication between the first activations vector and the second weights matrix, 2nd column. Resulting in the second activation vector's 2nd value.


Observing the matrix multiplication of the first column in each weight matrix. How can we get the final activation vector to contain the same values as our target vector y?

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容