MCPcopy Create free account
hub / github.com/XLearning-SCU/2022-CVPR-DART / ChannelAdapGray

Class ChannelAdapGray

ChannelAug.py:51–93  ·  view source on GitHub ↗

Adaptive selects a channel or two channels. Args: probability: The probability that the Random Erasing operation will be performed. sl: Minimum proportion of erased area against input image. sh: Maximum proportion of erased area against input image. r1:

Source from the content-addressed store, hash-verified

49
50
51class ChannelAdapGray(object):
52 """ Adaptive selects a channel or two channels.
53 Args:
54 probability: The probability that the Random Erasing operation will be performed.
55 sl: Minimum proportion of erased area against input image.
56 sh: Maximum proportion of erased area against input image.
57 r1: Minimum aspect ratio of erased area.
58 mean: Erasing value.
59 """
60
61 def __init__(self, probability = 0.5):
62 self.probability = probability
63
64
65 def __call__(self, img):
66
67 # if random.uniform(0, 1) > self.probability:
68 # return img
69
70 idx = random.randint(0, 3)
71
72 if idx ==0:
73 # random select R Channel
74 img[1, :,:] = img[0,:,:]
75 img[2, :,:] = img[0,:,:]
76 elif idx ==1:
77 # random select B Channel
78 img[0, :,:] = img[1,:,:]
79 img[2, :,:] = img[1,:,:]
80 elif idx ==2:
81 # random select G Channel
82 img[0, :,:] = img[2,:,:]
83 img[1, :,:] = img[2,:,:]
84 else:
85 if random.uniform(0, 1) > self.probability:
86 # return img
87 img = img
88 else:
89 tmp_img = 0.2989 * img[0,:,:] + 0.5870 * img[1,:,:] + 0.1140 * img[2,:,:]
90 img[0,:,:] = tmp_img
91 img[1,:,:] = tmp_img
92 img[2,:,:] = tmp_img
93 return img
94
95class ChannelRandomErasing(object):
96 """ Randomly selects a rectangle region in an image and erases its pixels.

Callers 3

run.pyFile · 0.90
__init__Method · 0.90
__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected