当前位置:网站首页>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
边栏推荐
- Preparation of functional test report
- Detailed explanation of common configurations in redis configuration file [easy to understand]
- 转--利用C语言中的setjmp和longjmp,来实现异常捕获和协程
- Delete AWS bound credit card account
- Pytorch's code for visualizing feature maps after training its own network
- 转--原来gdb的底层调试原理这么简单
- Kubernetes create service access pod
- Cutefishos system~
- Origin2018 installation tutorial "recommended collection"
- 正则系列之组和范围(Groups and Ranges)
猜你喜欢
[MySQL] index classification
Kubernetes create service access pod
Multi picture alert ~ comparison of Huawei ECs and Alibaba cloud ECS
[image segmentation] 2021 segformer neurips
SAP 智能机器人流程自动化(iRPA)解决方案分享
Chen Tianqi's machine learning compilation course (free)
Metauniverse may become a new direction of Internet development
Stimulate new kinetic energy and promote digital economy in multiple places
“信任机器”为发展赋能
447-哔哩哔哩面经1
随机推荐
Map container
Origin2018安装教程「建议收藏」
LC501. Mode in binary search tree
[image segmentation] 2021 segformer neurips
14年本科毕业,3个月转行软件测试月薪13.5k,32的岁我终于找对了方向
The principle, testing and Countermeasures of malicious software reverse closing EDR
Turn -- use setjmp and longjmp in C language to realize exception capture and collaboration
Use and function of spark analyze command map join broadcast join
思科--高可用和高可靠网络考试
Understanding of transactions in MySQL
nn. Parameter] pytoch feature fusion adaptive weight setting (learnable weight use)
MySQL中对于索引的理解
What class loading mechanisms does the JVM have?
Share some feelings of a programmer who has experienced layoffs twice a year
Arlo's thinking after confusion
Awoo's favorite problem (priority queue)
人体姿态估计的热图变成坐标点的两种方案
Genicam gentl standard ver1.5 (4) Chapter 5 acquisition engine
104. SAP ui5 table control supports multi select and how to select multiple table row items at a time with code
SAP 智能机器人流程自动化(iRPA)解决方案分享