【CV10】經典CNN模型中圖像數據增強方法簡介

1. Top ILSVRC Models

在將卷積神經網絡應用於圖像分類時,要確切地知道如何準備用於建模的圖像可能會非常困難,例如縮放(scaling)或歸一化(normalizing)像素值。此外,圖像數據增強(image data augmentation)可改善模型性能並減少泛化誤差,而測試時間增強(test-time augmentation)可改善擬合模型的預測性能

最好的做法是仔細研究文獻中描述的性能最高的模型上使用的數據準備,訓練時間增強(train-time augmentation)和測試時間增強(test-time augmentation)的類型,而不是盲目猜測可能有效的方法。

2010年至2017年間,ImageNet Large Scale Visual Recognition Challenge(ILSVRC)產生了一系列用於圖像分類的最先進的深度學習卷積神經網絡模型,其結構和配置已成爲該領域的啓發式方法和最佳實踐。

可以回顧在該年度競賽中表現出色的模型的論文,以發現圖像增強所使用的方法類型。在爲自己的圖像分類任務準備圖像數據時,這些可用作建議和最佳實踐。在以下各節中,將回顧四個頂級模型中使用的數據準備和圖像增強:SuperVision / AlexNet,GoogLeNet / Inception,VGG和ResNet。


2. SuperVision (AlexNet) Data Preparation

論文《ImageNet Classification with Deep Convolutional Neural Networks》中提出的AlexNet網絡在ILSVRC-2010和ILSVRC-2012圖像分類任務上取得了最佳成績,這些結果激發了人們對計算機視覺深度學習的興趣。他們稱其模型爲SuperVision,但此後被稱爲AlexNet。

2.1 Data Preparation

訓練數據集中的圖像大小不同,因此在用作模型輸入之前必須調整圖像大小,將正方形圖像調整爲256×256像素的形狀。將矩形圖像的最短邊調整爲256像素,然後從圖像中裁剪出中間的256×256正方形。注意:網絡期望輸入圖像具有通過訓練增強獲得的224×224形狀。

然後從每個像素中減去平均像素值,稱爲居中(centering)。這是按通道執行的,也就是說,平均像素值是從訓練數據集中估算出來的,彩色圖像的紅色,綠色和藍色通道中的每一個均對應一個像素值。

2.2 Train-Time Augmentation

具體來說,增強是在內存中執行的,結果沒有保存。**即時增強( just-in-time augmentation)**現在是使用該方法的標準方法。

進行的第一類增強是將較小的裁剪正方形圖像進行水平翻轉,然後使用圖像內的水平反射將其擴展到所需的一側。

The first form of data augmentation consists of generating image translations and horizontal reflections. We do this by extracting random 224×224 patches (and their horizontal reflections) from the 256×256 images and training our network on these extracted patches.

進行的第二種增強是對圖像的亮度進行隨機更改。

The second form of data augmentation consists of altering the intensities of the RGB channels in training images. Specifically, we perform PCA on the set of RGB pixel values throughout the ImageNet training set. To each training image, we add multiples of the found principal components, with magnitudes proportional to the corresponding eigenvalues times a random variable drawn from a Gaussian with mean zero and standard deviation 0.1.

2.3 Test-Time Augmentation

進行測試時間擴充是爲了使擬合模型有充分的機會進行可靠的預測。

這涉及創建輸入圖像的五個裁剪版本和圖像的水平翻轉版本的五個裁剪版本,然後對預測取平均

At test time, the network makes a prediction by extracting five 224×224 patches (the four corner patches and the center patch) as well as their horizontal reflections (hence ten patches in all), and averaging the predictions made by the network’s softmax layer on the ten patches.


3. GoogLeNet (Inception) Data Preparation

2014年的論文《 Going Deeper with Convolutions 》 中提出了GoogLeNet,在目標檢測方面取得了最佳成績。

3.1 Data Preparation

數據準備爲減去平均像素值,與AlexNet一樣,可能是每個通道居中。

第一篇論文中提出的網絡通常稱爲Inception v1。2015年的後續論文《Rethinking the Inception Architecture for Computer Vision》提出了Inception v2和v3。Keras中提供了Inception v3模型和模型權重。在此實現中,基於TensorFlow實現,圖像不居中;取而代之的是,將每個圖像的像素值縮放到 [-1,1] 範圍,圖像輸入形狀爲 299×299 像素。在最近的論文中似乎沒有提到這種歸一化和缺乏居中。

3.2 Train-Time Augmentation

使用多種技術來執行訓練時圖像增強。

使用3/4或4/3的隨機選擇的寬高比,隨機截取訓練數據集中圖像。

Still, one prescription that was verified to work very well after the competition includes sampling of various sized patches of the image whose size is distributed evenly between 8% and 100% of the image area and whose aspect ratio is chosen randomly between 3/4 and 4/3

另外,使用光度失真(photometric distortions),涉及圖像屬性(例如顏色,對比度和亮度)的隨機變化。調整圖像以適合模型的預期輸入形狀,並隨機選擇不同的插值方法(interpolation methods)。

In addition, we started to use random interpolation methods (bilinear, area, nearest neighbor and cubic, with equal probability) for resizing

3.3 Test-Time Augmentation

與AlexNet相似,執行測試時間增強,但範圍更廣。

每個圖像均以四個不同的比例進行重新採樣,然後從中獲取多個方形裁剪並將其調整爲圖像的預期輸入形狀。結果是對給定輸入圖像的多達144個版本的預測。

Specifically, we resize the image to 4 scales where the shorter dimension (height or width) is 256, 288, 320 and 352 respectively, take the left, center and right square of these resized images (in the case of portrait images, we take the top, center and bottom squares). For each square, we then take the 4 corners and the center 224×224 crop as well as the square resized to 224×224, and their mirrored versions. This results in 4×3×6×2 = 144 crops per image.

然後將這些預測取平均以做出最終預測。

The softmax probabilities are averaged over multiple crops and over all the individual classifiers to obtain the final prediction.


4. VGG Data Preparation

2015年,牛津大學VGG在論文《Very Deep Convolutional Networks for Large-Scale Image Recognition》 提出了 VGG Net。

4.1 Data Preparation

如先前模型所述,數據準備包括將輸入圖像的形狀標準化爲小方塊,並減去在訓練數據集上計算出的每通道像素均值。

During training, the input to our ConvNets is a fixed-size 224 × 224 RGB image. The only preprocessing we do is subtracting the mean RGB value, computed on the training set, from each pixel.

4.2 Train-Time Augmentation

首先訓練具有固定但較小圖像尺寸的模型,保留模型權重,然後將其用作訓練具有較大但仍固定尺寸圖像的新模型的初始化權重方法。這是爲了加快對較大(第二個)模型的訓練。另一種圖像縮放方法,稱爲多尺度訓練(multi-scale training),涉及爲每個圖像隨機選擇圖像縮放大小。

在兩種訓練方法中,然後將輸入圖像作爲較小的輸入裁剪。此外,將水平翻轉(horizontal flips)和顏色偏移(color shifts)應用於裁剪圖像。

To obtain the fixed-size 224×224 ConvNet input images, they were randomly cropped from rescaled training images (one crop per image per SGD iteration). To further augment the training set, the crops underwent random horizontal flipping and random RGB colour shift.

4.3 Test-Time Augmentation

在訓練時評估的多尺度方法也在測試時進行了評估,通常被稱爲尺度抖動(scale jitter)

創建給定測試圖像的多個不同比例的版本,針對每個版本進行預測,然後對預測值求平均值以得出最終預測值。


5. ResNet Data Preparation

5.1 Data Preparation

與其他模型一樣,從圖像中減去整個訓練過程中計算出的平均像素值,每個通道居中。

5.2 Train-Time Augmentation

圖像數據增強是上述方法的組合,主要參考AlexNet和VGG。圖像被隨機調整爲小尺寸或大尺寸,在VGG中使用了比例增強(scale augmentation)。然後採取可能的水平翻轉和顏色增強來截取一小塊方形圖像。

5.3 Test-Time Augmentation

與AlexNet一樣,測試集中每個圖像的創建了10個方形裁剪圖像,儘管這些圖像是在每個具有固定大小的測試圖像的多個版本上計算的,從而實現了針對VGG所述的尺度抖動(scale jittering),然後將所有變化的預測取平均。

In testing, for comparison studies we adopt the standard 10-crop testing. In testing, for comparison studies we adopt the standard 10-crop testing [21]. For best results, we adopt the fully-convolutional form as in [41, 13], and average the scores at multiple scales (images are resized such that the shorter side is in {224, 256, 384, 480, 640}).


6. Data Preparation Recommendations

  • Data Preparation:必須爲輸入圖像選擇固定尺寸,並且所有圖像都必須調整爲該形狀。像素縮放的最常見類型涉及將每個通道的像素值居中,然後進行某種類型的歸一化處理。
  • Train-Time Augmentation:需要訓練時增強,最常見的是輸入圖像的大小調整和裁剪,以及諸如變換,翻轉和顏色更改之類的圖像修改。
  • Test-Time Augmentation:測試時間增強的重點是輸入圖像的系統裁剪,以確保檢測到輸入圖像中存在的特徵。

參考:
https://machinelearningmastery.com/best-practices-for-preparing-and-augmenting-image-data-for-convolutional-neural-networks/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章