-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaugs.py
69 lines (51 loc) · 1.13 KB
/
augs.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Filename: augs.py
# @Project: D3R
# @Author: jie
# @Time: 2021/4/1 4:06 PM
import numpy as np
__all__ = [
'Compose',
'HFlip',
'VFlip',
'Rotate',
'Ident',
]
class Compose(object):
def __init__(self, transforms):
self.transforms = transforms
def __call__(self, rgb):
for t in self.transforms:
rgb = t(rgb)
return rgb
class HFlip(object):
"""
flip along horizontal axis
"""
def __call__(self, rgb):
flip = bool(np.random.randint(2))
if flip:
rgb = rgb[:, ::-1, :]
return rgb
class VFlip(object):
"""
flip along vertical axis
"""
def __call__(self, rgb):
flip = bool(np.random.randint(2))
if flip:
rgb = rgb[::-1, :, :]
return rgb
class Rotate(object):
"""
rotate 90 degrees
"""
def __call__(self, rgb):
rotate = bool(np.random.randint(2))
if rotate:
rgb = np.rot90(rgb)
return rgb
class Ident(object):
def __call__(self, rgb):
return rgb