林嶔 (Lin, Chin)
Lesson 23
上週的課程已帶大家實作最基本的卷積神經網路-LeNet,這週開始我們要帶著大家了解卷積神經網路後續在圖像辨識上的爆炸性發展。
ImageNet是2007年由史丹福大學教授李飛飛創辦,其收集大量帶有標註信息的圖片數據供電腦視覺模型訓練,而每年將會利用其資料進行ILSVRC圖像識別競賽。
– AlexNet -> VGGNet -> GoogLeNet -> ResNet
使用ReLU做為非線性變換的激活函數
使用Dropout技術
使用overlap的max pooling
數據增強
使用GPU加速深度卷積網絡的訓練
– VGGNet論文中全部使用了3x3的卷積核和2x2的池化核,通過不斷加深網絡結構來提升性能。
他的核心概念是透過2個3x3的卷積核取代5x5的卷積核,從而減少參數並探討其效益。
這篇研究透過比較了上述6個神經網路,告訴了我們幾個鐵則:
越深的網絡效果越好
1x1的卷積核也顯著提升效能
– 除此之外,他引入了Network In Network的概念,在卷積層內使用大量的1x1的卷積核。
– 假設有一個比較淺的網絡達到了飽和的準確率,那麼後面再加上幾個的全等映射層,起碼誤差不會增加,因此設計出了Residual unit:
– 們可以下載該模型進行預測
library(mxnet)
library(imager)
library(magrittr)
#Load a pre-training residual network model
res_model = mx.model.load("model/resnet-18", 0)
res_sym = mx.symbol.load("model/resnet-18-symbol.json")
#Define image processing functions
preproc.image <- function(im, mean.image = NULL) {
# crop the image
shape <- dim(im)
if (shape[1] != shape[2]) {
short.edge <- min(shape[1:2])
xx <- floor((shape[1] - short.edge) / 2)
yy <- floor((shape[2] - short.edge) / 2)
cropped <- crop.borders(im, xx, yy)
} else {
cropped <- array(im, dim = c(shape, 1, 1))
cropped <- cropped/max(cropped)
}
# resize to 224 x 224, needed by input of the model.
resized <- resize(cropped, 224, 224)
# convert to array (x, y, channel)
arr <- as.array(resized) * 255
dim(arr) <- dim(arr)[-3]
# subtract the mean
if (is.null(mean.image)) {mean.image = mean(arr)}
normed <- arr - mean.image
# Reshape to format needed by mxnet (width, height, channel, num)
dim(normed) <- c(dim(normed), 1)
return(normed)
}
#Read image and display
img <- load.image(system.file("extdata/parrots.png", package="imager"))
par(mar=rep(0,4))
plot(NA, xlim = 0:1, ylim = 0:1, xaxt = "n", yaxt = "n", bty = "n")
rasterImage(img, -0.04, -0.04, 1.04, 1.04, interpolate=FALSE)