当前位置:网站首页>深度学习笔记 —— 数据增广
深度学习笔记 —— 数据增广
2022-04-23 04:53:00 【Whisper_yl】



固定形状?卷积神经网络通常是一个固定的输入。


作用好不好是不一定的。很多时候觉得它有用是因为觉得测试集里会有图片跟这个效果是差不多的。
所以如何选择数据增强?可以从后往前推,想一下部署和测试集里面的图片与训练集的图片会有什么变化,从而确定需要什么样的数据增强方式。

多样性更强,使得泛化性更好。增广的目的是想让训练集更像测试集,如果完全一样就更好了!:)
import torch
import torchvision
from torch import nn
from d2l import torch as d2l
import matplotlib.pyplot as plt
d2l.set_figsize()
img = d2l.Image.open('./img/cat1.jpg')
d2l.plt.imshow(img);
# aug:图片增广的方式
def apply(img, aug, num_rows=2, num_cols=4, scale=1.5):
Y = [aug(img) for _ in range(num_rows * num_cols)]
d2l.show_images(Y, num_rows, num_cols, scale=scale)
plt.show()
# 左右翻转图像
# apply(img, torchvision.transforms.RandomHorizontalFlip())
# 上下翻转图像
# apply(img, torchvision.transforms.RandomVerticalFlip())
# 随机裁剪
shape_aug = torchvision.transforms.RandomResizedCrop(
(200, 200), scale=(0.1, 1), ratio=(0.5, 2))
# 随机更改图像的亮度
'''
apply(img, torchvision.transforms.ColorJitter(
brightness=0.5, contrast=0, saturation=0, hue=0))
'''
# 随机更改图像的色调
'''
apply(img, torchvision.transforms.ColorJitter(
brightness=0, contrast=0, saturation=0, hue=0.5))
'''
# 随机更改图像的亮度、对比度、饱和度和色调
color_aug = torchvision.transforms.ColorJitter(
brightness=0.5, contrast=0.5, saturation=0.5, hue=0.5)
# 结合多种图像增广方法
augs = torchvision.transforms.Compose([
torchvision.transforms.RandomHorizontalFlip(), color_aug, shape_aug])
apply(img, augs)
版权声明
本文为[Whisper_yl]所创,转载请带上原文链接,感谢
https://blog.csdn.net/LightInDarkness/article/details/124251507
边栏推荐
- Record the blind injection script
- View analysis of scenic spots in ArcGIS
- Excel protects worksheets and workbooks from damage
- List remove an element
- Installation and deployment of Flink and wordcount test
- Analysis of POM files
- 使用model.load_state_dict()时,出现AttributeError: ‘str‘ object has no attribute ‘copy‘
- vscode ipynb文件没有代码高亮和代码补全解决方法
- Shanghai Hangxin technology sharing 𞓜 overview of safety characteristics of acm32 MCU
- C language: spoof games
猜你喜欢

【数据库】表的查看、修改和删除

PIP3 installation requests Library - the most complete pit sorting

Customize the navigation bar at the top of wechat applet (adaptive wechat capsule button, flex layout)

Opencv + clion face recognition + face model training

Installation and deployment of Flink and wordcount test

Recommended scheme of national manufactured electronic components for intelligent electronic scales

Record the ThreadPoolExecutor main thread waiting for sub threads

Innovation training (IX) integration

持续集成(CI)/持续交付(CD)如何彻底改变自动化测试

Thoughts on a small program
随机推荐
Field injection is not recommended using @ Autowired
Simply drag objects to the item bar
Spark small case - RDD, spark SQL
C language: spoof games
Set Chrome browser background to eye protection (eye escort / darkreader plug-in)
[database] MySQL single table query
Small volume Schottky diode compatible with nsr20f30nxt5g
ApplicationContext injection bean
leetcode——启发式搜索
Informatics Aosai yibentong 1212: letters | openjudge 2.5 156: Letters
Custom switch control
Leetcode008 -- implement strstr() function
C list field sorting contains numbers and characters
Leetcode002 -- inverts the numeric portion of a signed integer
【数据库】MySQL多表查询(一)
Agile practice | agile indicators to improve group predictability
MySQL -- execution process and principle of a statement
Leetcode005 -- delete duplicate elements in the array in place
[database] MySQL basic operation (basic operation ~)
JS determines whether the numeric string contains characters