Summary of 12 commonly used image data enhancement techniques
The goal of training a machine learning or deep learning model is to become a "universal" model. This requires that the model does not overfit the training data set, or in other words, our model has a good understanding of the unseen data. Data augmentation is also one of many ways to avoid overfitting.
The process of expanding the amount of data used to train a model is called data augmentation. By training a model with multiple data types, we can obtain a more "generalized" model. What does "multiple data types" mean? This article only discusses "image" data enhancement technology and only introduces various image data enhancement strategies in detail. We will also get hands-on and implement data augmentation techniques primarily used in image data or computer vision using PyTorch.
Because it introduces data enhancement technology. So just use one image. Let’s look at the visual code first.
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
This function is used to adjust the height and width of the image to what we want. specific size. The code below demonstrates that we want to resize the image from its original size to 224 x 224.
path = './kitten.jpeg' transform = transforms.Resize((224, 224)) imshow(path, transform)
Cropping
This technique applies a portion of a selected image to a new image. For example, use CenterCrop to return a center-cropped image.
transform = transforms.CenterCrop((224, 224)) imshow(path, transform)
RandomResizedCrop
This method combines cropping and resizing at the same time.
transform = transforms.RandomResizedCrop((100, 300)) imshow(path, transform)
Flipping
Flip the image horizontally or vertically, the code below will try to apply a horizontal flip to our image.
transform = transforms.RandomHorizontalFlip() imshow(path, transform)
Padding
Padding consists of padding a specified amount on all edges of the image. We'll fill each edge with 50 pixels.
transform = transforms.Pad((50,50,50,50)) imshow(path, transform)
Rotation
Applies a random rotation angle to the image. We'll set this angle to 15 degrees.
transform = transforms.RandomRotation(15) imshow(path, transform)
Random Affine
This technique is a transformation that leaves the center unchanged. This technique has some parameters:
- degrees: rotation angle
- translate: horizontal and vertical translation
- scale: scaling parameters
- share: Image cropping parameters
- fillcolor: The color of the outer fill of the image
transform = transforms.RandomAffine(1, translate=(0.5, 0.5), scale=(1, 1), shear=(1,1), fillcolor=(256,256,256)) imshow(path, transform)
Gaussian Blur
The image will be blurred using Gaussian blur deal with.
transform = transforms.GaussianBlur(7, 3) imshow(path, transform)
Grayscale
Convert color images to grayscale.
transform = transforms.Grayscale(num_output_channels=3) imshow(path, transform)
Color enhancement, also known as color dithering, is the process of modifying the color properties of an image by changing its pixel values. The following methods are all color-related operations.
Brightness
Change the brightness of the image The resulting image becomes darker or lighter when compared to the original image.
transform = transforms.ColorJitter(brightness=2) imshow(path, transform)
Contrast
The degree of difference between the darkest and lightest parts of an image is called contrast. The contrast of the image can also be adjusted as an enhancement.
transform = transforms.ColorJitter(cnotallow=2) imshow(path, transform)
Saturation
Summary of 12 commonly used image data enhancement techniques中颜色的分离被定义为饱和度。
transform = transforms.ColorJitter(saturatinotallow=20) imshow(path, transform)
Hue
色调被定义为Summary of 12 commonly used image data enhancement techniques中颜色的深浅。
transform = transforms.ColorJitter(hue=2) imshow(path, transform)
总结
图像本身的变化将有助于模型对未见数据的泛化,从而不会对数据进行过拟合。以上整理的都是我们常见的数据增强技术,torchvision中还包含了很多方法,可以在他的文档中找到:https://pytorch.org/vision/stable/transforms.html
The above is the detailed content of Summary of 12 commonly used image data enhancement techniques. For more information, please follow other related articles on the PHP Chinese website!

Exploring the Inner Workings of Language Models with Gemma Scope Understanding the complexities of AI language models is a significant challenge. Google's release of Gemma Scope, a comprehensive toolkit, offers researchers a powerful way to delve in

Unlocking Business Success: A Guide to Becoming a Business Intelligence Analyst Imagine transforming raw data into actionable insights that drive organizational growth. This is the power of a Business Intelligence (BI) Analyst – a crucial role in gu

SQL's ALTER TABLE Statement: Dynamically Adding Columns to Your Database In data management, SQL's adaptability is crucial. Need to adjust your database structure on the fly? The ALTER TABLE statement is your solution. This guide details adding colu

Introduction Imagine a bustling office where two professionals collaborate on a critical project. The business analyst focuses on the company's objectives, identifying areas for improvement, and ensuring strategic alignment with market trends. Simu

Excel data counting and analysis: detailed explanation of COUNT and COUNTA functions Accurate data counting and analysis are critical in Excel, especially when working with large data sets. Excel provides a variety of functions to achieve this, with the COUNT and COUNTA functions being key tools for counting the number of cells under different conditions. Although both functions are used to count cells, their design targets are targeted at different data types. Let's dig into the specific details of COUNT and COUNTA functions, highlight their unique features and differences, and learn how to apply them in data analysis. Overview of key points Understand COUNT and COU

Google Chrome's AI Revolution: A Personalized and Efficient Browsing Experience Artificial Intelligence (AI) is rapidly transforming our daily lives, and Google Chrome is leading the charge in the web browsing arena. This article explores the exciti

Reimagining Impact: The Quadruple Bottom Line For too long, the conversation has been dominated by a narrow view of AI’s impact, primarily focused on the bottom line of profit. However, a more holistic approach recognizes the interconnectedness of bu

Things are moving steadily towards that point. The investment pouring into quantum service providers and startups shows that industry understands its significance. And a growing number of real-world use cases are emerging to demonstrate its value out


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version
Useful JavaScript development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version
Recommended: Win version, supports code prompts!

Zend Studio 13.0.1
Powerful PHP integrated development environment