TVP

# 自监督学习和对比学习

zenRRan

1.7K0

Contrastive Learning: 当研究两个物体时，我们很容易区分它们，即使以前从未见过它们。例如，一只狗和一把椅子，尽管它们的颜色可能彼此相似，但会有非常明显的特征，而一对狗，尽管它们的品种差异很小，但属于同一类别，我们会认识到这一事实。换句话说，通过辨别一个物体的视觉特征，能够在它和其他事物之间形成对比。

SimCLR:在图像分类任务中，如果每张照片都属于一个类，最基本的就要构造正负样本对，前者是来自一个类别的实例，后者是来自两个类别的两个数据点。然而，这将破坏SSL的目的，因此我们必须设计一种解决方案，处理成堆的未标记数据。SimCLR的方法是将每个图像视为一个单独的类别，并对其进行扩充，以便为每个所谓的类生成实例。例如，与配对（需要监督）不同，下图每行都是正例，随机取两行，取yige：

• 正例对: (蓝色的椅子， 白色的椅子)
• 负例对: (蓝色的椅子，狗)

1. Crop, resize, flip: The picture is cropped (the area of the cropped piece is between 8% to 100% of the original size, and the aspect ratio between 3/4 and 4/3), resized back to its original dimensions, and flipped horizontally (with a 50% chance).
2. Colour distortion: Colour jitter (alter the brightness, contrast, saturation, and hue) with a hyperparameter to control its intensity in composition with greying out the picture, with probabilities of 80% and 20% respectively.
3. Gaussian blur: A Gaussian kernel 10% of the size of the picture blurs the image half the time. The standard deviation for creating the kernel is randomly picked from the range [0.1, 2.0].

``````from torchvision import transforms
# Size used in SimCLR
size = 224
crop_resize_flip = transforms.Compose([transforms.RandomResizedCrop(size, scale=(0.08, 1.0), ratio=(3/4, 4/3)),
transforms.RandomHorizontalFlip(p=0.5)])

# Higher means stronger
s = 1.0
# 0.8*s and 0.2*s are from the paper
colour_jitter = transforms.ColorJitter(brightness=0.8*s, contrast=0.8*s, saturation=0.8*s, hue=0.2*s)
colour_jitter = transforms.RandomApply([colour_jitter], p=0.8)
colour_distortion = transforms.Compose([colour_jitter,
transforms.RandomGrayscale(p=0.2)])

kernel_size = int(0.1*size)
# The size of the kernel must be odd
kernel_size = kernel_size if kernel_size%2 == 1 else kernel_size+1
gaussian_blur = transforms.GaussianBlur(kernel_size, sigma=(0.1, 2.0))
gaussian_blur = transforms.RandomApply([gaussian_blur], p=0.5)

augment = transforms.Compose([crop_resize_flip,
colour_distortion,
gaussian_blur])
``````

https://zhuanlan.zhihu.com/p/107269105

0 条评论

LV.

NLP 服务
NLP 服务（Natural Language Process，NLP）深度整合了腾讯内部的 NLP 技术，提供多项智能文本处理和文本生成能力，包括词法分析、相似词召回、词相似度、句子相似度、文本润色、句子纠错、文本补全、句子生成等。满足各行业的文本智能需求。