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

Class ChannelAdap

ChannelAug.py:12–48  ·  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

10
11
12class ChannelAdap(object):
13 """ Adaptive selects a channel or two channels.
14 Args:
15 probability: The probability that the Random Erasing operation will be performed.
16 sl: Minimum proportion of erased area against input image.
17 sh: Maximum proportion of erased area against input image.
18 r1: Minimum aspect ratio of erased area.
19 mean: Erasing value.
20 """
21
22 def __init__(self, probability = 0.5):
23 self.probability = probability
24
25
26 def __call__(self, img):
27
28 # if random.uniform(0, 1) > self.probability:
29 # return img
30
31 idx = random.randint(0, 3)
32
33 if idx ==0:
34 # random select R Channel
35 img[1, :,:] = img[0,:,:]
36 img[2, :,:] = img[0,:,:]
37 elif idx ==1:
38 # random select B Channel
39 img[0, :,:] = img[1,:,:]
40 img[2, :,:] = img[1,:,:]
41 elif idx ==2:
42 # random select G Channel
43 img[0, :,:] = img[2,:,:]
44 img[1, :,:] = img[2,:,:]
45 else:
46 img = img
47
48 return img
49
50
51class ChannelAdapGray(object):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected