当前位置:网站首页>Data enhancement of semi supervised learning
Data enhancement of semi supervised learning
2022-07-01 22:57:00 【Cross examination to Zhejiang University】
SDA
Generally, unmarked pictures and their pseudo tags are not directly sent to the network retraining , Before that , We need to enhance the unlabeled images and their pseudo tags , So that the network can learn Additional features also Alleviate over fitting of noise .
Common enhancement operations :
1: tailoring
Cut or fill directly to the specified size
2: Flip
Flip up and down 、 Flip left and right 、 Rotate the specified angle
3: Standardization
4: wave filtering
PIL Of ImageFilter Module introduction
5:resize( Interpolation fills )
Nearest neighbor (nearest) And bilinear (bilinear)
6:cutout
cutout yes 2017 A data enhancement method proposed in , The idea is simple , That is, randomly cut off part of the image during training , It can also be seen as a similar dropout The regularization method of .
Improved Regularization of Convolutional Neural Networks with Cutout
paper: https://arxiv.org/pdf/1708.04552.pdf
code: https://github.com/uoguelph-mlrg/Cutout
Use the above operation PIL Library implementation and encapsulation , Convenient for subsequent calls .
import numpy as np
from PIL import Image, ImageOps, ImageFilter
import random
import torch
from torchvision import transforms
import cv2
class DataAugmentations():
def __init__(self):
pass
def crop(self,img, mask, size):
# padding height or width if smaller than cropping size
w, h = img.size
padw = size - w if w < size else 0
padh = size - h if h < size else 0
img = ImageOps.expand(img, border=(0, 0, padw, padh), fill=0)
mask = ImageOps.expand(mask, border=(0, 0, padw, padh), fill=255)
# cropping
w, h = img.size
x = random.randint(0, w - size)
y = random.randint(0, h - size)
img = img.crop((x, y, x + size, y + size))
mask = mask.crop((x, y, x + size, y + size))
return img, mask
def hflip(self,img, mask, p=0.5):
if random.random() < p:
''' FLIP_LEFT_RIGHT = 0 Flip left and right FLIP_TOP_BOTTOM = 1 Flip up and down ROTATE_90 = 2 rotate ROTATE_180 = 3 ROTATE_270 = 4 TRANSPOSE = 5 TRANSVERSE = 6 '''
img = img.transpose(Image.FLIP_LEFT_RIGHT)
mask = mask.transpose(Image.FLIP_LEFT_RIGHT)
return img, mask
def normalize(self,img, mask=None):
""" :param img: PIL image :param mask: PIL image, corresponding mask :return: normalized torch tensor of image and mask """
img = transforms.Compose([
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),
])(img)
if mask is not None:
mask = torch.from_numpy(np.array(mask)).long()
return img, mask
return img
def resize(self,img, mask, base_size, ratio_range):
w, h = img.size
long_side = random.randint(int(base_size * ratio_range[0]), int(base_size * ratio_range[1]))
if h > w:
oh = long_side
ow = int(1.0 * w * long_side / h + 0.5)
else:
ow = long_side
oh = int(1.0 * h * long_side / w + 0.5)
img = img.resize((ow, oh), Image.BILINEAR)
mask = mask.resize((ow, oh), Image.NEAREST)
return img, mask
def blur(self,img, p=0.5):
if random.random() < p:
sigma = np.random.uniform(0.1, 2.0)
img = img.filter(ImageFilter.GaussianBlur(radius=sigma))
return img
def cutout(self,img, mask, p=0.5, size_min=0.02, size_max=0.4, ratio_1=0.3,
ratio_2=1/0.3, value_min=0, value_max=255, pixel_level=True):
if random.random() < p:
img = np.array(img)
mask = np.array(mask)
img_h, img_w, img_c = img.shape
while True:
size = np.random.uniform(size_min, size_max) * img_h * img_w
ratio = np.random.uniform(ratio_1, ratio_2)
erase_w = int(np.sqrt(size / ratio))
erase_h = int(np.sqrt(size * ratio))
x = np.random.randint(0, img_w)
y = np.random.randint(0, img_h)
if x + erase_w <= img_w and y + erase_h <= img_h:
break
if pixel_level:
value = np.random.uniform(value_min, value_max, (erase_h, erase_w, img_c))
else:
value = np.random.uniform(value_min, value_max)
img[y:y + erase_h, x:x + erase_w] = value
mask[y:y + erase_h, x:x + erase_w] = 255
img = Image.fromarray(img.astype(np.uint8))
mask = Image.fromarray(mask.astype(np.uint8))
return img, mask
if __name__=="__main__":
SDA=DataAugmentations()
img=Image.open("your path")
mask=Image.open("your path")
image1,mask1=SDA.hflip(img,mask)
image1.show(title=" Liu Yifei ")
cv Communication group
837038258
边栏推荐
- 转--深入LUA脚本语言,让你彻底明白调试原理
- cvpr2022 human pose estiamtion
- Unable to climb hill sort, directly insert sort
- Two schemes of transforming the heat map of human posture estimation into coordinate points
- SAP UI5 应用开发教程之一百零四 - SAP UI5 表格控件的支持复选(Multi-Select)以及如何用代码一次选中多个表格行项目
- [daily training] 66 add one-tenth
- Pytorch nn. functional. Simple understanding and usage of unfold()
- 【c语言】malloc函数详解[通俗易懂]
- vSphere+、vSAN+来了!VMware 混合云聚焦:原生、快速迁移、混合负载
- A few minutes before work, I found out V-model and The difference between sync
猜你喜欢
正则系列之量词(Quantifiers)
Fiori 应用通过 Adaptation Project 的增强方式分享
Kubernetes create service access pod
使用3DMax制作一个象棋棋子
[image segmentation] 2021 segformer neurips
el-input文本域字数限制,超过显示变红并禁止输入
死锁的处理策略—预防死锁、避免死锁、检测和解除死锁
Digital currency: far-reaching innovation
vSphere+、vSAN+来了!VMware 混合云聚焦:原生、快速迁移、混合负载
SAP GUI 里的收藏夹事务码管理工具
随机推荐
Multi picture alert ~ comparison of Huawei ECs and Alibaba cloud ECS
There is no signal in HDMI in computer games caused by memory, so it crashes
Arlo's thinking after confusion
Kubernetes create service access pod
el-input文本域字数限制,超过显示变红并禁止输入
Turn -- go deep into Lua scripting language, so that you can thoroughly understand the debugging principle
Pytorch nn.functional.unfold()的简单理解与用法
MySQL -- index of InnoDB storage engine
Use three JS realize the 'ice cream' earth, and let the earth cool for a summer
MySQL -- index of MyISAM storage engine
Origin2018 installation tutorial "recommended collection"
rxjs Observable of 操作符的单步调试分析
Quantifiers of regular series
转--拿来即用:分享一个检查内存泄漏的小工具
nn. Parameter] pytoch feature fusion adaptive weight setting (learnable weight use)
Using securecrtportable to remotely connect virtual machines
MySQL5.7 设置密码策略(等保三级密码改造)
locust的使用
Single step debugging analysis of rxjs observable of operator
Preparation of functional test report