---
tags: course, Deep learning
---
# MIT Intro to Deep Learning: Lecture 3 CNN
[Course link](https://www.youtube.com/watch?v=iaSUYvmCekI&list=PLtBw6njQRU-rwp5__7C0oIVt26ZgjG9NI&index=3)
## Deep Computer Vision
* Vision is one of the most important senses that human possess
* EX: recognize object, recognize complex human emotion and behaviors...
### Example of AI in CV
* 人臉辨識
* 受到DL影響最大的領域之一
* 令人類不需要再為不同的task設計不同演算法,而是丟資料給DL讓他自己學習如何解決task

* 醫療
* 可以用來偵測視網膜是否有病
* 也可以用來分類病的種類,有助於醫生開藥方

* 自駕車
* 輸入圖片讓模型學出一個車子的自動控制系統

---
## What Computer "See"?
* How does computer process image or video?
* 對電腦來說圖片就只是數字
* 灰階圖片的數字代表那個區域的灰度 (1080x1080x1)
* 彩色圖片就會有RGB三個維度 (1080x1080x3)

* Task in CV
* 回歸問題 & 分類問題
* 一個可以分辨輸入的圖片是哪位總統的分類模型 (輸出可能的機率)
* 為了做到這件事情,模型需要能夠找出總統圖片之間的差異
* 也就是找出這些有助於分類的**特徵**

* 另一個想法是讓模型去偵測圖片擁有哪些特徵
* 直接利用這些特徵來為圖片做分類

---
* 所以我們究竟該如何**擷取特徵**?
* 可以利用人類的知識(domain knowledge)來教模型 (Expert system)
* 以辨識人臉來說,我們可以指定模型先去偵測眼睛、鼻子、耳朵、嘴巴
* 那模型就可以根據有沒有偵測到這些特徵來知道輸入的圖片是不是一個人臉

* 問題是我們該如何偵測這些特徵呢?
* 更何況現實中的圖片更加的複雜,有更多的特徵和變化

* Goals
* invariant to all of these variations
* sensitive to inter class variations and between class variations
* 偵測特徵這個任務非常的困難......
* 但NN可以處理這個任務
* NN可以直接從圖片中學習到這些特徵和特徵之間的階層性

## Learning Visual Features
* 先複習了一下Fully Connected Network (Dense Network)
* Every input densely connect to every output

* 若只使用FCNN來做,圖片特徵會全部消失
* 因為二維的圖片會被強制壓縮成一維

* 那我們要如何抓取並利用這些spatial structure呢?
---
* a neuron connect to patches of input

* 用sliding patches windows就可以對整張圖片做這樣的事情
* 下例是每次slide都會移動兩個neuron

* 但單純將neuron與input pixel連接起來並沒有用
* 為了學習到特徵,我們需要將它們之間的連接做Weight
* Convolution指的就是這個Patchy Weight的方法

## Feature extraction and convolution : A case study
* 一個分類X的Task

* 為了能夠處理不同X的變化
* model need to compare these image of axes **piece by piece** or **patch by patch**

* 特徵就像是一個小型的圖片,一樣也是二維的數據
* 我們會利用**Filter**去對原始圖片做特徵擷取
* Filter中的數字就代表他的Weight

* Convolution Operation
* element-wise multiply between filter and image
* sum up the result

* More closely steps
* Input a 5 x 5 image and set a 3 x 3 filter

* 總之就是細講了filter和input image之間的運算並產出feature map



* Filter的選擇影響很大,不同的Filter會擷取到完全不一樣的特徵

* 有了Conv就可以讓模型偵測並擷取到不同的特徵 (用多個Filters)

## Convolution Neural Networks (CNNs)
* a simple example of CNN
* **3 steps : Conv, non-linearity, pooling**
* output可以透過FC layer得到

* Convolution Step
* Each neuron in that hidden layter is only seeing a patch from that origin input

* 在一層Conv layer中我們可以有很多個不同的filters,也就能抓取很多不同的features
* Conv layer的輸出並不是一張圖片,而是**a volume of image**,裡面有許多不同filter所擷取出來的feature maps
* **Receptive Field** (感知域)代表的是一個neuron對patch的連接

* Element wise non-linearity
* ReLU

* Pooling的目的在於讓我們可以處理不同大小、解析度的圖片
* 用來降低輸入圖片的維度
* can be done on any layer after the conv layer
* max pooling對每個patch取出其中最大的值

---
* CNN可以分為兩個部分:Feature learning & classification
* Feature learning重複上述的三個步驟從圖片中擷取出特徵

* classification的目標是利用這些特徵來分類圖片

## CNN code example

## Applications
* 我們可以將classification part作為一個feature extractor,直接插入其他的網路架構中

* Example 1: 乳癌掃描

* Example 2: Semantic Segmentation
* 對輸入圖片的每一個pixel做分類

* 同樣可以運用在腦瘤偵測上

* Example 3: Self-driving car
* 然後秀一下自己的自駕車


## Summary
