-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaugmentation_zoo.py
executable file
·28 lines (23 loc) · 1.21 KB
/
augmentation_zoo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import sys
# diff augmentation
import kornia
# diff jpeg
sys.path.append("DiffJPEG/")
from DiffJPEG import DiffJPEG
augmentation_zoo_list=['lavisCLIP','jpeg']
def getAug_lavisCLIP(image_size):
'''
augmentation used in xinstructBLIP
according to https://github.com/salesforce/LAVIS/blob/ac8fc98c93c02e2dfb727e24a361c4c309c8dbbc/lavis/processors/clip_processors.py#L20
'''
return kornia.augmentation.RandomResizedCrop(
size=(image_size, image_size), scale=(0.9, 1.0), ratio=(0.75, 1.3333333333333333),
resample="BICUBIC", align_corners=True, cropping_mode="resample", same_on_batch=False, keepdim=False, p=1.0)
def get_image_augmentation(augmentation_name, image_size):
assert augmentation_name in augmentation_zoo_list, f'{augmentation_name} is not implemented'
if augmentation_name == 'lavisCLIP':
print('Using lavisCLIP as the image augmentation method. lavisCLIP is used in xInstructBLIP')
return getAug_lavisCLIP(image_size=image_size)
if augmentation_name == 'jpeg':
print('Using diff jpeg as the image augmentation method')
return DiffJPEG(height=image_size, width=image_size, differentiable=True, quality=75).cuda()