<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>

新聞中心

EEPW首頁(yè) > 嵌入式系統 > 設計應用 > 教程詳解:用卷積神經(jīng)網(wǎng)絡(luò )檢測臉部關(guān)鍵點(diǎn)(一)

教程詳解:用卷積神經(jīng)網(wǎng)絡(luò )檢測臉部關(guān)鍵點(diǎn)(一)

作者: 時(shí)間:2018-08-03 來(lái)源:網(wǎng)絡(luò ) 收藏

本文引用地址:http://dyxdggzs.com/article/201808/385311.htm

”’ optimization method: ””

update=nesterov_momentum,

update_learning_rate=0.01,

update_momentum=0.9,

update_learning_rate定義了梯度下降更新權重的步長(cháng)。我們稍后討論學(xué)習率和momentum參數,現在的話(huà),這種健全的默認值已經(jīng)足夠了。

上圖是不同的最優(yōu)化方法的對比(animation by?Alec Radford)。星標位置為全局最優(yōu)值。注意到不添加動(dòng)量的隨機梯度下降是收斂最慢的,我們在教程中從頭到尾都是用Nesterov加速過(guò)的梯度下降。

在我們的NeuralNet的定義中,我們沒(méi)有指定一個(gè)目標函數來(lái)實(shí)現最小化。這里使用的還有一個(gè)默認值:對于回歸問(wèn)題,它是均方誤差(MSE)。

最后一組參數聲明我們正在處理一個(gè)回歸問(wèn)題(而不是分類(lèi)),400是我們愿意訓練的時(shí)期數,并且我們想在訓練期間通過(guò)設置verbose = 1:

regression=True, # flag to indicate we're dealing with regression problem

max_epochs=400, # we want to train this many epochs

verbose=1,

最后兩行加載了數據,然后用數據訓練了我們的第一個(gè)神經(jīng)。

X, y = load()

net1.fit(X, y)

運行這兩行會(huì )輸出一個(gè)表格,每次完成一代就輸出一行。每一行里,我們可以看到當前的訓練損失和驗證損失(最小二乘損失),以及兩者的比率。NeuroNet將會(huì )自動(dòng)把輸入數據X分成訓練集和測試集,用20%的數據作驗證。(比率可以通過(guò)參數eval_size=0.2調整)

$ python kfkd.py

...

InputLayer (None, 9216) produces 9216 outputs

DenseLayer (None, 100) produces 100 outputs

DenseLayer (None, 30) produces 30 outputs

Epoch | Train loss | Valid loss | Train / Val

--------|--------------|--------------|----------------

1 | 0.105418 | 0.031085 | 3.391261

2 | 0.020353 | 0.019294 | 1.054894

3 | 0.016118 | 0.016918 | 0.952734

4 | 0.014187 | 0.015550 | 0.912363

5 | 0.013329 | 0.014791 | 0.901199

...

200 | 0.003250 | 0.004150 | 0.783282

201 | 0.003242 | 0.004141 | 0.782850

202 | 0.003234 | 0.004133 | 0.782305

203 | 0.003225 | 0.004126 | 0.781746

204 | 0.003217 | 0.004118 | 0.781239

205 | 0.003209 | 0.004110 | 0.780738

...

395 | 0.002259 | 0.003269 | 0.690925

396 | 0.002256 | 0.003264 | 0.691164

397 | 0.002254 | 0.003264 | 0.690485

398 | 0.002249 | 0.003259 | 0.690303

399 | 0.002247 | 0.003260 | 0.689252

400 | 0.002244 | 0.003255 | 0.689606

在相對較快的上訓練,我們能夠在1分鐘之內完成400個(gè)epoch的訓練。注意測試損失會(huì )一直減小。(如果你訓練得足夠長(cháng)時(shí)間,它將會(huì )有很小很小的改進(jìn))

現在我們有了一個(gè)很好的結果了么?我們看到測試誤差是0.0032,和競賽基準比試一下。記住我們將目標除以了48以將其縮放到-1到1之間,也就是說(shuō),要是想計算均方誤差和排行榜的結果比較,必須把我們上面得到的0.003255還原到原來(lái)的尺度。

>>> import numpy as np

>>> np.sqrt(0.003255) * 48

2.7385251505144153

這個(gè)值應該可以代表我們的成績(jì)了。當然,這得假設測試集合的數據和訓練集合的數據符合相同的分布,但事實(shí)卻并非如此。

測試

我們剛剛訓練的net1對象已經(jīng)保存了訓練時(shí)打印在控制臺桌面中的記錄,我們可以獲取這個(gè)記錄通過(guò)train_history_相關(guān)屬性,讓我們畫(huà)出這兩個(gè)曲線(xiàn)。

train_loss = np.array([i[train_loss] for i in net1.train_history_])

valid_loss = np.array([i[valid_loss] for i in net1.train_history_])

pyplot.plot(train_loss, linewidth=3, label=train)

pyplot.plot(valid_loss, linewidth=3, label=valid)

pyplot.grid()

pyplot.legend()

pyplot.xlabel(epoch)

pyplot.ylabel(loss)

pyplot.ylim(1e-3, 1e-2)

pyplot.yscale(log)

pyplot.show()

我們能夠看到我們的過(guò)擬合了,但是結果還不錯。事實(shí)上,我們找不到驗證錯誤開(kāi)始上升的點(diǎn),所以那種通常用來(lái)避免過(guò)擬合的early stopping方法在現在還沒(méi)有什么用處。注意我們沒(méi)有采用任何正則化手段,除了選擇節點(diǎn)比較少的隱層——這可以讓過(guò)擬合保持在可控范圍內。

那么網(wǎng)絡(luò )的預測結果是什么樣的呢?讓我們選擇一些樣例來(lái)看一看。

def plot_sample(x, y, axis):

img = x.reshape(96, 96)

axis.imshow(img, cmap='gray')

axis.scatter(y[0::2] * 48 + 48, y[1::2] * 48 + 48, marker='x', s=10)

X, _ = load(test=True)

y_pred = net1.predict(X)

fig = pyplot.figure(figsize=(6, 6))

fig.subplots_adjust(

left=0, right=1, bottom=0, top=1, hspace=0.05, wspace=0.05)

for i in range(16):

ax = fig.add_subplot(4, 4, i + 1, xticks=[], yticks=[])

plot_sample(X[i], y_pred[i], ax)

pyplot.show()

第一個(gè)模型預測的結果(從測試集抽出了16個(gè)樣例)

預測結果看起來(lái)還不錯,但是有點(diǎn)時(shí)候還是有一點(diǎn)偏。讓我們試著(zhù)做的更好一些。


上一頁(yè) 1 2 3 下一頁(yè)

評論


相關(guān)推薦

技術(shù)專(zhuān)區

關(guān)閉
国产精品自在自线亚洲|国产精品无圣光一区二区|国产日产欧洲无码视频|久久久一本精品99久久K精品66|欧美人与动牲交片免费播放
<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>