search
HomeTechnology peripheralsAISummary of 12 commonly used image data enhancement techniques

Summary of 12 commonly used image data enhancement techniques

Apr 11, 2023 pm 10:49 PM
machine learningdeep learningdata set

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.

Summary of 12 commonly used image data enhancement techniques


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)

Summary of 12 commonly used image data enhancement techniques

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)

Summary of 12 commonly used image data enhancement techniques

RandomResizedCrop

This method combines cropping and resizing at the same time.

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

Summary of 12 commonly used image data enhancement techniques

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)

Summary of 12 commonly used image data enhancement techniques

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)

Summary of 12 commonly used image data enhancement techniques

Rotation

Applies a random rotation angle to the image. We'll set this angle to 15 degrees.

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

Summary of 12 commonly used image data enhancement techniques

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)

Summary of 12 commonly used image data enhancement techniques

Gaussian Blur

The image will be blurred using Gaussian blur deal with.

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

Summary of 12 commonly used image data enhancement techniques

Grayscale

Convert color images to grayscale.

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

Summary of 12 commonly used image data enhancement techniques

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)

Summary of 12 commonly used image data enhancement techniques

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)

Summary of 12 commonly used image data enhancement techniques

Saturation

Summary of 12 commonly used image data enhancement techniques中颜色的分离被定义为饱和度。

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

Summary of 12 commonly used image data enhancement techniques

Hue

色调被定义为Summary of 12 commonly used image data enhancement techniques中颜色的深浅。

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

Summary of 12 commonly used image data enhancement techniques

总结

图像本身的变化将有助于模型对未见数据的泛化,从而不会对数据进行过拟合。以上整理的都是我们常见的数据增强技术,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!

Statement
This article is reproduced at:51CTO.COM. If there is any infringement, please contact admin@php.cn delete
Gemma Scope: Google's Microscope for Peering into AI's Thought ProcessGemma Scope: Google's Microscope for Peering into AI's Thought ProcessApr 17, 2025 am 11:55 AM

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

Who Is a Business Intelligence Analyst and How To Become One?Who Is a Business Intelligence Analyst and How To Become One?Apr 17, 2025 am 11:44 AM

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

How to Add a Column in SQL? - Analytics VidhyaHow to Add a Column in SQL? - Analytics VidhyaApr 17, 2025 am 11:43 AM

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

Business Analyst vs. Data AnalystBusiness Analyst vs. Data AnalystApr 17, 2025 am 11:38 AM

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

What are COUNT and COUNTA in Excel? - Analytics VidhyaWhat are COUNT and COUNTA in Excel? - Analytics VidhyaApr 17, 2025 am 11:34 AM

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

Chrome is Here With AI: Experiencing Something New Everyday!!Chrome is Here With AI: Experiencing Something New Everyday!!Apr 17, 2025 am 11:29 AM

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

AI's Human Side: Wellbeing And The Quadruple Bottom LineAI's Human Side: Wellbeing And The Quadruple Bottom LineApr 17, 2025 am 11:28 AM

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

5 Game-Changing Quantum Computing Use Cases You Should Know About5 Game-Changing Quantum Computing Use Cases You Should Know AboutApr 17, 2025 am 11:24 AM

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

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Safe Exam Browser

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

SublimeText3 English version

Recommended: Win version, supports code prompts!

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment