--- 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 ![](https://i.imgur.com/5Inf6qZ.jpg) * 醫療 * 可以用來偵測視網膜是否有病 * 也可以用來分類病的種類,有助於醫生開藥方 ![](https://i.imgur.com/RDFrFcx.jpg) * 自駕車 * 輸入圖片讓模型學出一個車子的自動控制系統 ![](https://i.imgur.com/spiAAx4.jpg) --- ## What Computer "See"? * How does computer process image or video? * 對電腦來說圖片就只是數字 * 灰階圖片的數字代表那個區域的灰度 (1080x1080x1) * 彩色圖片就會有RGB三個維度 (1080x1080x3) ![](https://i.imgur.com/PRZFS1Z.jpg) * Task in CV * 回歸問題 & 分類問題 * 一個可以分辨輸入的圖片是哪位總統的分類模型 (輸出可能的機率) * 為了做到這件事情,模型需要能夠找出總統圖片之間的差異 * 也就是找出這些有助於分類的**特徵** ![](https://i.imgur.com/FnMvqbh.jpg) * 另一個想法是讓模型去偵測圖片擁有哪些特徵 * 直接利用這些特徵來為圖片做分類 ![](https://i.imgur.com/0RaJh31.jpg) --- * 所以我們究竟該如何**擷取特徵**? * 可以利用人類的知識(domain knowledge)來教模型 (Expert system) * 以辨識人臉來說,我們可以指定模型先去偵測眼睛、鼻子、耳朵、嘴巴 * 那模型就可以根據有沒有偵測到這些特徵來知道輸入的圖片是不是一個人臉 ![](https://i.imgur.com/4G4Enll.jpg) * 問題是我們該如何偵測這些特徵呢? * 更何況現實中的圖片更加的複雜,有更多的特徵和變化 ![](https://i.imgur.com/QlocXcy.jpg) * Goals * invariant to all of these variations * sensitive to inter class variations and between class variations * 偵測特徵這個任務非常的困難...... * 但NN可以處理這個任務 * NN可以直接從圖片中學習到這些特徵和特徵之間的階層性 ![](https://i.imgur.com/VRVorqD.jpg) ## Learning Visual Features * 先複習了一下Fully Connected Network (Dense Network) * Every input densely connect to every output ![](https://i.imgur.com/1Y7zWEB.jpg) * 若只使用FCNN來做,圖片特徵會全部消失 * 因為二維的圖片會被強制壓縮成一維 ![](https://i.imgur.com/GHOHRJM.jpg) * 那我們要如何抓取並利用這些spatial structure呢? --- * a neuron connect to patches of input ![](https://i.imgur.com/pP8nEiw.jpg) * 用sliding patches windows就可以對整張圖片做這樣的事情 * 下例是每次slide都會移動兩個neuron ![](https://i.imgur.com/sQzRajf.jpg) * 但單純將neuron與input pixel連接起來並沒有用 * 為了學習到特徵,我們需要將它們之間的連接做Weight * Convolution指的就是這個Patchy Weight的方法 ![](https://i.imgur.com/163Q1K4.jpg) ## Feature extraction and convolution : A case study * 一個分類X的Task ![](https://i.imgur.com/mHKvYWL.jpg) * 為了能夠處理不同X的變化 * model need to compare these image of axes **piece by piece** or **patch by patch** ![](https://i.imgur.com/TZATPjg.jpg) * 特徵就像是一個小型的圖片,一樣也是二維的數據 * 我們會利用**Filter**去對原始圖片做特徵擷取 * Filter中的數字就代表他的Weight ![](https://i.imgur.com/fqj6aAk.jpg) * Convolution Operation * element-wise multiply between filter and image * sum up the result ![](https://i.imgur.com/QTDOhyV.jpg) * More closely steps * Input a 5 x 5 image and set a 3 x 3 filter ![](https://i.imgur.com/T2tqUmj.jpg) * 總之就是細講了filter和input image之間的運算並產出feature map ![](https://i.imgur.com/1TcqLSH.jpg) ![](https://i.imgur.com/x41P6YJ.jpg) ![](https://i.imgur.com/u6HcqnX.jpg) * Filter的選擇影響很大,不同的Filter會擷取到完全不一樣的特徵 ![](https://i.imgur.com/LG0NoJz.jpg) * 有了Conv就可以讓模型偵測並擷取到不同的特徵 (用多個Filters) ![](https://i.imgur.com/am5njtJ.jpg) ## Convolution Neural Networks (CNNs) * a simple example of CNN * **3 steps : Conv, non-linearity, pooling** * output可以透過FC layer得到 ![](https://i.imgur.com/GdjzScR.jpg) * Convolution Step * Each neuron in that hidden layter is only seeing a patch from that origin input ![](https://i.imgur.com/heO3SIp.jpg) * 在一層Conv layer中我們可以有很多個不同的filters,也就能抓取很多不同的features * Conv layer的輸出並不是一張圖片,而是**a volume of image**,裡面有許多不同filter所擷取出來的feature maps * **Receptive Field** (感知域)代表的是一個neuron對patch的連接 ![](https://i.imgur.com/twrZZ3q.jpg) * Element wise non-linearity * ReLU ![](https://i.imgur.com/l0u1Trp.jpg) * Pooling的目的在於讓我們可以處理不同大小、解析度的圖片 * 用來降低輸入圖片的維度 * can be done on any layer after the conv layer * max pooling對每個patch取出其中最大的值 ![](https://i.imgur.com/gpWasHW.jpg) --- * CNN可以分為兩個部分:Feature learning & classification * Feature learning重複上述的三個步驟從圖片中擷取出特徵 ![](https://i.imgur.com/C9TNp01.jpg) * classification的目標是利用這些特徵來分類圖片 ![](https://i.imgur.com/oFv0ndz.jpg) ## CNN code example ![](https://i.imgur.com/uEwbkUk.jpg) ## Applications * 我們可以將classification part作為一個feature extractor,直接插入其他的網路架構中 ![](https://i.imgur.com/XQhmAaX.jpg) * Example 1: 乳癌掃描 ![](https://i.imgur.com/88SZuPm.jpg) * Example 2: Semantic Segmentation * 對輸入圖片的每一個pixel做分類 ![](https://i.imgur.com/rxxu44j.jpg) * 同樣可以運用在腦瘤偵測上 ![](https://i.imgur.com/8ZzVsiD.jpg) * Example 3: Self-driving car * 然後秀一下自己的自駕車 ![](https://i.imgur.com/O6dle5v.jpg) ![](https://i.imgur.com/d78axtP.jpg) ## Summary ![](https://i.imgur.com/YWrJtQJ.jpg)