12個常用的影像資料增強技術總結

王林
發布: 2023-04-11 22:49:01
轉載
2032 人瀏覽過

機器學習或深度學習模型的訓練的目標是成為「通用」模型。這就需要模型沒有過度擬合訓練資料集,或者換句話說,我們的模型對看不見的資料有很好的了解。資料增強也是避免過度擬合的眾多方法之一。

擴展用於訓練模型的資料量的過程稱為資料增強。透過訓練具有多種資料類型的模型,我們可以獲得更「泛化」的模型。 「多種資料類型」是什麼意思呢?本片文章只討論「影像」資料增強技術,只詳細介紹各種圖片資料增強策略。我們還將使用 PyTorch 動手實踐並實現影像資料或電腦視覺中主要使用的資料增強技術。

12個常用的影像資料增強技術總結


因為介紹的是資料增強技術。所以只使用一張圖片就可以了,我們先看看可視話的程式碼

import PIL.Image as Image
 import torch
 from torchvision import transforms
 import matplotlib.pyplot as plt
 import numpy as np
 import warnings
 
 def imshow(img_path, transform):
登入後複製

Resize/Rescale

此函數用於將圖像的高度和寬度調整為我們想要的特定大小。下面的程式碼示範了我們想要將圖像從其原始大小調整為 224 x 224。

path = './kitten.jpeg'
 transform = transforms.Resize((224, 224))
 imshow(path, transform)
登入後複製

12個常用的影像資料增強技術總結

Cropping

該技術將要選擇的映像的一部分套用到新映像。例如,使用 CenterCrop 來傳回一個中心裁剪的影像。

transform = transforms.CenterCrop((224, 224))
 imshow(path, transform)
登入後複製

12個常用的影像資料增強技術總結

RandomResizedCrop

這種方法同時結合了裁切和調整大小。

transform = transforms.RandomResizedCrop((100, 300))
 imshow(path, transform)
登入後複製

12個常用的影像資料增強技術總結

Flipping

水平或垂直翻轉圖像,下面程式碼將嘗試應用水平翻轉到我們的圖像。

transform = transforms.RandomHorizontalFlip()
 imshow(path, transform)
登入後複製

12個常用的影像資料增強技術總結

Padding

填充包含在影像的所有邊緣上以指定的數量填充。我們將每條邊填入50像素。

transform = transforms.Pad((50,50,50,50))
 imshow(path, transform)
登入後複製

12個常用的影像資料增強技術總結

Rotation

對影像隨機施加旋轉角度。我們將這個角設為15度。

transform = transforms.RandomRotation(15)
 imshow(path, transform)
登入後複製

12個常用的影像資料增強技術總結

Random Affine

這種技巧是一種保持中心不變的變換。這種技術有一些參數:

  • degrees:旋轉角度
  • translate:水平和垂直轉換
  • scale:縮放參數
  • ##share:圖片裁剪參數
  • fillcolor:圖像外部填充的顏色
  • transform = transforms.RandomAffine(1, translate=(0.5, 0.5), scale=(1, 1), shear=(1,1), fillcolor=(256,256,256))
     imshow(path, transform)
    登入後複製

12個常用的影像資料增強技術總結

Gaussian Blur

圖像將使用高斯模糊進行模糊處理。

transform = transforms.GaussianBlur(7, 3)
 imshow(path, transform)
登入後複製

12個常用的影像資料增強技術總結

Grayscale

將彩色影像轉換為灰階。

transform = transforms.Grayscale(num_output_channels=3)
 imshow(path, transform)
登入後複製

12個常用的影像資料增強技術總結

顏色增強,也稱為顏色抖動,是透過改變影像的像素值來修改影像的顏色屬性的過程。下面的方法都是顏色相關的操作。

Brightness

改變影像的亮度當與原始影像對比時,產生的影像變暗或變亮。

transform = transforms.ColorJitter(brightness=2)
 imshow(path, transform)
登入後複製

12個常用的影像資料增強技術總結

Contrast

影像最暗和最亮部分之間的差異程度稱為對比。影像的對比度也可以作為增強進行調整。

transform = transforms.ColorJitter(cnotallow=2)
 imshow(path, transform)
登入後複製

12個常用的影像資料增強技術總結

Saturation

12個常用的影像資料增強技術總結中颜色的分离被定义为饱和度。

transform = transforms.ColorJitter(saturatinotallow=20)
 imshow(path, transform)
登入後複製

12個常用的影像資料增強技術總結

Hue

色调被定义为12個常用的影像資料增強技術總結中颜色的深浅。

transform = transforms.ColorJitter(hue=2)
 imshow(path, transform)
登入後複製

12個常用的影像資料增強技術總結

总结

图像本身的变化将有助于模型对未见数据的泛化,从而不会对数据进行过拟合。以上整理的都是我们常见的数据增强技术,torchvision中还包含了很多方法,可以在他的文档中找到:https://pytorch.org/vision/stable/transforms.html

以上是12個常用的影像資料增強技術總結的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:51cto.com
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!