Diff of /random_eraser.py [000000] .. [38391a]

Switch to unified view

a b/random_eraser.py
1
import numpy as np
2
3
from imgaug import augmenters as iaa
4
import numpy as np
5
6
#def get_augumentation()
7
#    def eraser(input_img):
8
#        seq = iaa.Sequential([iaa.GaussianBlur((0,3.0)), iaa.Affine(translate_px={"x":(-40,40)})])
9
#        seq_det = seq.to_deterministic()
10
#        input_img = seq_det.augment_images(input_img)
11
12
#        return input_img
13
#    return eraser
14
15
16
def get_random_eraser(p=0.5, s_l=0.02, s_h=0.4, r_1=0.3, r_2=1/0.3, v_l=0, v_h=255, pixel_level=False):
17
    def eraser(input_img):
18
        img_h, img_w, img_c = input_img.shape
19
        p_1 = np.random.rand()
20
21
        if p_1 > p:
22
            return input_img
23
24
        while True:
25
            s = np.random.uniform(s_l, s_h) * img_h * img_w
26
            r = np.random.uniform(r_1, r_2)
27
            w = int(np.sqrt(s / r))
28
            h = int(np.sqrt(s * r))
29
            left = np.random.randint(0, img_w)
30
            top = np.random.randint(0, img_h)
31
32
            if left + w <= img_w and top + h <= img_h:
33
                break
34
35
        if pixel_level:
36
            c = np.random.uniform(v_l, v_h, (h, w, img_c))
37
        else:
38
            c = np.random.uniform(v_l, v_h)
39
40
        input_img[top:top + h, left:left + w, :] = c
41
42
        return input_img
43
44
    return eraser