偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

12個常用的圖像數(shù)據(jù)增強技術(shù)總結(jié)

人工智能 機器學習
機器學習或深度學習模型的訓練的目標是成為“通用”模型。這就需要模型沒有過度擬合訓練數(shù)據(jù)集,或者換句話說,我們的模型對看不見的數(shù)據(jù)有很好的了解。數(shù)據(jù)增強也是避免過度擬合的眾多方法之一。

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

擴展用于訓練模型的數(shù)據(jù)量的過程稱為數(shù)據(jù)增強。通過訓練具有多種數(shù)據(jù)類型的模型,我們可以獲得更“泛化”的模型。“多種數(shù)據(jù)類型”是什么意思呢?本片文章只討論“圖像”數(shù)據(jù)增強技術(shù),只詳細地介紹各種圖片數(shù)據(jù)增強策略。我們還將使用 PyTorch 動手實踐并實現(xiàn)圖像數(shù)據(jù)或計算機視覺中主要使用的數(shù)據(jù)增強技術(shù)。

圖片


因為介紹的是數(shù)據(jù)增強技術(shù)。所以只使用一張圖片就可以了,我們先看看可視話的代碼

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

此函數(shù)用于將圖像的高度和寬度調(diào)整為我們想要的特定大小。下面的代碼演示了我們想要將圖像從其原始大小調(diào)整為 224 x 224。

path = './kitten.jpeg'
transform = transforms.Resize((224, 224))
imshow(path, transform)

圖片

Cropping

該技術(shù)將要選擇的圖像的一部分應(yīng)用于新圖像。例如,使用 CenterCrop 來返回一個中心裁剪的圖像。

transform = transforms.CenterCrop((224, 224))
imshow(path, transform)

圖片

RandomResizedCrop

這種方法同時結(jié)合了裁剪和調(diào)整大小。

transform = transforms.RandomResizedCrop((100, 300))
imshow(path, transform)

Flipping

水平或垂直翻轉(zhuǎn)圖像,下面代碼將嘗試應(yīng)用水平翻轉(zhuǎn)到我們的圖像。

transform = transforms.RandomHorizontalFlip()
imshow(path, transform)

Padding

填充包括在圖像的所有邊緣上按指定的數(shù)量填充。我們將每條邊填充50像素。

transform = transforms.Pad((50,50,50,50))
imshow(path, transform)

Rotation

對圖像隨機施加旋轉(zhuǎn)角度。我們將這個角設(shè)為15度。

transform = transforms.RandomRotation(15)
imshow(path, transform)

Random Affine

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

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

圖片

Gaussian Blur

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

transform = transforms.GaussianBlur(7, 3)
imshow(path, transform)

Grayscale

將彩色圖像轉(zhuǎn)換為灰度。

transform = transforms.Grayscale(num_output_channels=3)
imshow(path, transform)

圖片

顏色增強,也稱為顏色抖動,是通過改變圖像的像素值來修改圖像的顏色屬性的過程。下面的方法都是顏色相關(guān)的操作。

Brightness

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

transform = transforms.ColorJitter(brightness=2)
imshow(path, transform)

圖片

Contrast

圖像最暗和最亮部分之間的區(qū)別程度被稱為對比度。圖像的對比度也可以作為增強進行調(diào)整。

transform = transforms.ColorJitter(cnotallow=2)
imshow(path, transform)

圖片

Saturation

圖片中顏色的分離被定義為飽和度。

transform = transforms.ColorJitter(saturatinotallow=20)
imshow(path, transform)

圖片

Hue

色調(diào)被定義為圖片中顏色的深淺。

transform = transforms.ColorJitter(hue=2)
imshow(path, transform)

圖片

總結(jié)

圖像本身的變化將有助于模型對未見數(shù)據(jù)的泛化,從而不會對數(shù)據(jù)進行過擬合。以上整理的都是我們常見的數(shù)據(jù)增強技術(shù),torchvision中還包含了很多方法,可以在他的文檔中找到:https://pytorch.org/vision/stable/transforms.html

責任編輯:華軒 來源: DeepHub IMBA
相關(guān)推薦

2020-02-04 17:31:49

Python 開發(fā)編程語言

2024-10-08 15:42:45

2025-01-20 08:00:00

圖像增強深度學習AI

2022-11-24 14:07:48

元宇宙VR

2010-03-25 17:52:11

2019-10-24 10:04:33

技術(shù)債務(wù)開發(fā)軟件

2020-07-13 11:20:23

Python魔法命令代碼

2010-03-03 13:12:56

Python圖像處理

2021-03-16 10:12:24

python內(nèi)置函數(shù)

2020-06-23 08:28:26

前端開發(fā)技巧

2024-01-08 16:30:42

2024-03-18 15:04:02

物聯(lián)網(wǎng)通信協(xié)議IOT

2019-03-05 16:21:44

Java開發(fā)代碼

2017-09-06 08:04:49

2011-05-07 14:39:00

投影

2021-09-27 18:07:06

物聯(lián)網(wǎng)協(xié)議物聯(lián)網(wǎng)IOT

2022-12-27 08:53:54

IT領(lǐng)導者CIO

2010-07-28 15:42:44

Flex

2023-10-07 11:36:15

2023-03-09 15:25:49

點贊
收藏

51CTO技術(shù)棧公眾號