MCPcopy Create free account
hub / github.com/NVIDIA/semantic-segmentation / get_params

Method get_params

transforms/transforms.py:317–350  ·  view source on GitHub ↗

Get a randomized transform to be applied on image. Arguments are same as that of __init__. Returns: Transform which randomly adjusts brightness, contrast and saturation in a random order.

(brightness, contrast, saturation, hue)

Source from the content-addressed store, hash-verified

315
316 @staticmethod
317 def get_params(brightness, contrast, saturation, hue):
318 """Get a randomized transform to be applied on image.
319
320 Arguments are same as that of __init__.
321
322 Returns:
323 Transform which randomly adjusts brightness, contrast and
324 saturation in a random order.
325 """
326 transforms = []
327 if brightness > 0:
328 brightness_factor = np.random.uniform(max(0, 1 - brightness), 1 + brightness)
329 transforms.append(
330 torch_tr.Lambda(lambda img: adjust_brightness(img, brightness_factor)))
331
332 if contrast > 0:
333 contrast_factor = np.random.uniform(max(0, 1 - contrast), 1 + contrast)
334 transforms.append(
335 torch_tr.Lambda(lambda img: adjust_contrast(img, contrast_factor)))
336
337 if saturation > 0:
338 saturation_factor = np.random.uniform(max(0, 1 - saturation), 1 + saturation)
339 transforms.append(
340 torch_tr.Lambda(lambda img: adjust_saturation(img, saturation_factor)))
341
342 if hue > 0:
343 hue_factor = np.random.uniform(-hue, hue)
344 transforms.append(
345 torch_tr.Lambda(lambda img: adjust_hue(img, hue_factor)))
346
347 np.random.shuffle(transforms)
348 transform = torch_tr.Compose(transforms)
349
350 return transform
351
352 def __call__(self, img):
353 """

Callers 1

__call__Method · 0.95

Calls 4

adjust_brightnessFunction · 0.85
adjust_contrastFunction · 0.85
adjust_saturationFunction · 0.85
adjust_hueFunction · 0.85

Tested by

no test coverage detected