discopat.nn_training.torch_detection_utils.transforms

Classes

Compose(transforms)

FixedSizeCrop(size[, fill, padding_mode])

PILToTensor(*args, **kwargs)

RandomHorizontalFlip([p])

RandomIoUCrop([min_scale, max_scale, ...])

RandomPhotometricDistort([contrast, ...])

RandomShortestSize(min_size, max_size[, ...])

RandomZoomOut([fill, side_range, p])

ScaleJitter(target_size[, scale_range, ...])

Randomly resizes the image and its bounding boxes within the specified scale range.

SimpleCopyPaste([blending, resize_interpolation])

ToDtype(dtype[, scale])

class discopat.nn_training.torch_detection_utils.transforms.Compose(transforms)[source]

Bases: object

class discopat.nn_training.torch_detection_utils.transforms.FixedSizeCrop(size, fill=0, padding_mode='constant')[source]

Bases: Module

forward(img, target=None)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class discopat.nn_training.torch_detection_utils.transforms.PILToTensor(*args, **kwargs)[source]

Bases: Module

forward(image, target=None)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:
  • image (Tensor)

  • target (Dict[str, Tensor] | None)

Return type:

Tuple[Tensor, Dict[str, Tensor] | None]

class discopat.nn_training.torch_detection_utils.transforms.RandomHorizontalFlip(p=0.5)[source]

Bases: RandomHorizontalFlip

forward(image, target=None)[source]
Parameters:
  • img (PIL Image or Tensor) – Image to be flipped.

  • image (Tensor)

  • target (Dict[str, Tensor] | None)

Returns:

Randomly flipped image.

Return type:

PIL Image or Tensor

class discopat.nn_training.torch_detection_utils.transforms.RandomIoUCrop(min_scale=0.3, max_scale=1.0, min_aspect_ratio=0.5, max_aspect_ratio=2.0, sampler_options=None, trials=40)[source]

Bases: Module

Parameters:
  • min_scale (float)

  • max_scale (float)

  • min_aspect_ratio (float)

  • max_aspect_ratio (float)

  • sampler_options (List[float] | None)

  • trials (int)

forward(image, target=None)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:
  • image (Tensor)

  • target (Dict[str, Tensor] | None)

Return type:

Tuple[Tensor, Dict[str, Tensor] | None]

class discopat.nn_training.torch_detection_utils.transforms.RandomPhotometricDistort(contrast=(0.5, 1.5), saturation=(0.5, 1.5), hue=(-0.05, 0.05), brightness=(0.875, 1.125), p=0.5)[source]

Bases: Module

Parameters:
  • contrast (Tuple[float, float])

  • saturation (Tuple[float, float])

  • hue (Tuple[float, float])

  • brightness (Tuple[float, float])

  • p (float)

forward(image, target=None)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:
  • image (Tensor)

  • target (Dict[str, Tensor] | None)

Return type:

Tuple[Tensor, Dict[str, Tensor] | None]

class discopat.nn_training.torch_detection_utils.transforms.RandomShortestSize(min_size, max_size, interpolation=InterpolationMode.BILINEAR)[source]

Bases: Module

Parameters:
  • min_size (List[int] | Tuple[int] | int)

  • max_size (int)

  • interpolation (InterpolationMode)

forward(image, target=None)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:
  • image (Tensor)

  • target (Dict[str, Tensor] | None)

Return type:

Tuple[Tensor, Dict[str, Tensor] | None]

class discopat.nn_training.torch_detection_utils.transforms.RandomZoomOut(fill=None, side_range=(1.0, 4.0), p=0.5)[source]

Bases: Module

Parameters:
  • fill (List[float] | None)

  • side_range (Tuple[float, float])

  • p (float)

forward(image, target=None)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:
  • image (Tensor)

  • target (Dict[str, Tensor] | None)

Return type:

Tuple[Tensor, Dict[str, Tensor] | None]

class discopat.nn_training.torch_detection_utils.transforms.ScaleJitter(target_size, scale_range=(0.1, 2.0), interpolation=InterpolationMode.BILINEAR, antialias=True)[source]

Bases: Module

Randomly resizes the image and its bounding boxes within the specified scale range. The class implements the Scale Jitter augmentation as described in the paper “Simple Copy-Paste is a Strong Data Augmentation Method for Instance Segmentation”.

Parameters:
  • target_size (tuple of ints) – The target size for the transform provided in (height, weight) format.

  • scale_range (tuple of ints) – scaling factor interval, e.g (a, b), then scale is randomly sampled from the range a <= scale <= b.

  • interpolation (InterpolationMode) – Desired interpolation enum defined by torchvision.transforms.InterpolationMode. Default is InterpolationMode.BILINEAR.

forward(image, target=None)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:
  • image (Tensor)

  • target (Dict[str, Tensor] | None)

Return type:

Tuple[Tensor, Dict[str, Tensor] | None]

class discopat.nn_training.torch_detection_utils.transforms.SimpleCopyPaste(blending=True, resize_interpolation=InterpolationMode.BILINEAR)[source]

Bases: Module

forward(images, targets)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:
  • images (List[Tensor])

  • targets (List[Dict[str, Tensor]])

Return type:

Tuple[List[Tensor], List[Dict[str, Tensor]]]

class discopat.nn_training.torch_detection_utils.transforms.ToDtype(dtype, scale=False)[source]

Bases: Module

Parameters:
  • dtype (dtype)

  • scale (bool)

forward(image, target=None)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:
  • image (Tensor)

  • target (Dict[str, Tensor] | None)

Return type:

Tuple[Tensor, Dict[str, Tensor] | None]