機器學習5-深度學習網路發展史及實作

林嶔 (Lin, Chin)

Lesson 23

深度學習網路發展史(1)

F24_1

– AlexNet -> VGGNet -> GoogLeNet -> ResNet

F24_2

深度學習網路發展史(2)

F24_3

  1. 使用ReLU做為非線性變換的激活函數

  2. 使用Dropout技術

  3. 使用overlap的max pooling

  4. 數據增強

  5. 使用GPU加速深度卷積網絡的訓練

深度學習網路發展史(3)

– VGGNet論文中全部使用了3x3的卷積核和2x2的池化核,通過不斷加深網絡結構來提升性能。

F24_4

  1. 越深的網絡效果越好

  2. 1x1的卷積核也顯著提升效能

深度學習網路發展史(4)

– 除此之外,他引入了Network In Network的概念,在卷積層內使用大量的1x1的卷積核。

F24_5

深度學習網路發展史(5)

F24_6

深度學習網路發展史(6)

– 假設有一個比較淺的網絡達到了飽和的準確率,那麼後面再加上幾個的全等映射層,起碼誤差不會增加,因此設計出了Residual unit:

F24_7

F24_8

利用Pre-training的model進行Feature extraCtion(1)

– 們可以下載該模型進行預測

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)