discopat.nn_training.torch_detection_utils package

Submodules

discopat.nn_training.torch_detection_utils.coco_eval module

class discopat.nn_training.torch_detection_utils.coco_eval.COCOevalIoMean(cocoGt=None, cocoDt=None, iouType='segm')[source]

Bases: COCOeval

Replace IoU by IoMean.

computeIoMean(imgId, catId)[source]
computeIoU(imgId, catId)[source]
class discopat.nn_training.torch_detection_utils.coco_eval.CocoEvaluator(coco_gt, iou_types)[source]

Bases: object

accumulate()[source]
prepare(predictions, iou_type)[source]
prepare_for_coco_detection(predictions)[source]
prepare_for_coco_keypoint(predictions)[source]
prepare_for_coco_segmentation(predictions)[source]
summarize()[source]
synchronize_between_processes()[source]
update(predictions)[source]
discopat.nn_training.torch_detection_utils.coco_eval.convert_to_xywh(boxes)[source]
discopat.nn_training.torch_detection_utils.coco_eval.create_common_coco_eval(coco_eval, img_ids, eval_imgs)[source]
discopat.nn_training.torch_detection_utils.coco_eval.evaluate(imgs)[source]
discopat.nn_training.torch_detection_utils.coco_eval.merge(img_ids, eval_imgs)[source]

discopat.nn_training.torch_detection_utils.coco_utils module

class discopat.nn_training.torch_detection_utils.coco_utils.CocoDetection(img_folder, ann_file, transforms)[source]

Bases: CocoDetection

class discopat.nn_training.torch_detection_utils.coco_utils.ConvertCocoPolysToMask[source]

Bases: object

discopat.nn_training.torch_detection_utils.coco_utils.convert_coco_poly_to_mask(segmentations, height, width)[source]
discopat.nn_training.torch_detection_utils.coco_utils.convert_to_coco_api(ds)[source]
discopat.nn_training.torch_detection_utils.coco_utils.get_coco(root, image_set, transforms, mode='instances', use_v2=False, with_masks=False)[source]
discopat.nn_training.torch_detection_utils.coco_utils.get_coco_api_from_dataset(dataset)[source]

discopat.nn_training.torch_detection_utils.engine module

discopat.nn_training.torch_detection_utils.engine.evaluate(model, data_loader, device)[source]
discopat.nn_training.torch_detection_utils.engine.train_one_epoch(model, optimizer, data_loader, device, epoch, print_freq, scaler=None)[source]

discopat.nn_training.torch_detection_utils.transforms module

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]

discopat.nn_training.torch_detection_utils.utils module

class discopat.nn_training.torch_detection_utils.utils.MetricLogger(delimiter='\t')[source]

Bases: object

add_meter(name, meter)[source]
log_every(iterable, print_freq, header=None)[source]
synchronize_between_processes()[source]
update(**kwargs)[source]
class discopat.nn_training.torch_detection_utils.utils.SmoothedValue(window_size=20, fmt=None)[source]

Bases: object

Track a series of values and provide access to smoothed values over a window or the global series average.

property avg
property global_avg
property max
property median
synchronize_between_processes()[source]

Warning: does not synchronize the deque!

update(value, n=1)[source]
property value
discopat.nn_training.torch_detection_utils.utils.all_gather(data)[source]

Run all_gather on arbitrary picklable data (not necessarily tensors) :param data: any picklable object

Returns:

list of data gathered from each rank

Return type:

list[data]

discopat.nn_training.torch_detection_utils.utils.collate_fn(batch)[source]
discopat.nn_training.torch_detection_utils.utils.get_rank()[source]
discopat.nn_training.torch_detection_utils.utils.get_world_size()[source]
discopat.nn_training.torch_detection_utils.utils.init_distributed_mode(args)[source]
discopat.nn_training.torch_detection_utils.utils.is_dist_avail_and_initialized()[source]
discopat.nn_training.torch_detection_utils.utils.is_main_process()[source]
discopat.nn_training.torch_detection_utils.utils.mkdir(path)[source]
discopat.nn_training.torch_detection_utils.utils.reduce_dict(input_dict, average=True)[source]
Parameters:
  • input_dict (dict) – all the values will be reduced

  • average (bool) – whether to do average or sum

Reduce the values in the dictionary from all processes so that all processes have the averaged results. Returns a dict with the same fields as input_dict, after reduction.

discopat.nn_training.torch_detection_utils.utils.save_on_master(*args, **kwargs)[source]
discopat.nn_training.torch_detection_utils.utils.setup_for_distributed(is_master)[source]

This function disables printing when not in master process

Module contents