deepdisc.astrodet.detectron

Classes

SaveHook

This Hook saves the model during training

LossEvalHook

Validation loss code adopted from https://gist.github.com/ortegatron/c0dad15e49c2b74de8bb09a5615d9f6b

CustomLRScheduler

A hook which executes a torch builtin LR scheduler and summarizes the LR.

GenericWrapperTransform

Code from Deshwal on Stack Overflow

CustomAug

Given a probability and a custom function, return a GenericWrapperTransform object whose apply_image

ShapeAug

Given a probability and a custom function, return a GenericWrapperTransform object whose apply_image

KRandomAugmentationList

Select and Apply "K" augmentations in "RANDOM" order with "Every" __call__ method invoke

_TransformToAug

Functions

plot_stretch_Q(dataset_dicts, astro_metadata[, num, ...])

Plots different normalizations of your image using the stretch, Q parameters.

_transform_to_aug(tfm_or_aug)

Wrap Transform into Augmentation.

Module Contents

plot_stretch_Q(dataset_dicts, astro_metadata, num=0, stretches=[0.01, 0.1, 0.5, 1], Qs=[1, 10, 5, 100], ceil_percentile=99.5)[source]

Plots different normalizations of your image using the stretch, Q parameters.

Parameters:
  • dataset_dicts (dict) – detectron dataset dictionary

  • num (int) – Dataset number/index to use

  • stretches (array) – List of stretch params you want to permutate through to find optimal image normalization. Default is [0.01, 0.1, 0.5, 1]

  • Qs (array) – List of Q params you want to permutate through to find optimal image normalization. Default is [1, 10, 5, 100]

  • from (Code adapted) – https://pmelchior.github.io/scarlet/tutorials/display.html

Returns:

fig

Return type:

Figure object

class SaveHook(save_period)[source]

Bases: detectron2.engine.HookBase

This Hook saves the model during training

Parameters:

save_period (int) – How many iterations to run before a checkpoint is saved

output_name = 'model_temp'[source]
_period[source]
set_output_name(name)[source]
after_step()[source]
class LossEvalHook(eval_period, model, data_loader)[source]

Bases: detectron2.engine.HookBase

Validation loss code adopted from https://gist.github.com/ortegatron/c0dad15e49c2b74de8bb09a5615d9f6b

Parameters:
  • eval_period (int) – How many iterations to run before validation loss is calculated

  • model (torch.NN.module) – The model being trained

  • data_loader (detectron2 DataLoader) – The dataloader that loads in the evaluation dataset

_model[source]
_period[source]
_data_loader[source]
_do_loss_eval()[source]
_get_loss(data)[source]
after_step()[source]
class CustomLRScheduler(optimizer=None, scheduler=None)[source]

Bases: detectron2.engine.HookBase

A hook which executes a torch builtin LR scheduler and summarizes the LR. It is executed after every iteration.

Parameters:
  • optimizer (torch optimizer) – the training optimizer

  • scheduler (torch scheduler) – The learning rate scheduler

_optimizer = None[source]
_scheduler = None[source]
before_train()[source]
static get_best_param_group_id(optimizer)[source]
after_step()[source]
property scheduler[source]
state_dict()[source]
load_state_dict(state_dict)[source]
class GenericWrapperTransform(custom_function)[source]

Bases: fvcore.transforms.transform.Transform

Code from Deshwal on Stack Overflow Generic wrapper for any transform (for color transform only. You can give functionality to apply_coods, apply_segmentation too)

apply_image(img)[source]

apply transformation to image array based on the custom_function

apply_coords(coords)[source]

Apply transformations to Bounding Box Coordinates. Currently is won’t do anything but we can change this based on our use case

inverse()[source]
apply_segmentation(segmentation)[source]

Apply transformations to segmentation. currently is won’t do anything but we can change this based on our use case

class CustomAug(custom_function, prob=1.0)[source]

Bases: detectron2.data.transforms.Augmentation

Given a probability and a custom function, return a GenericWrapperTransform object whose apply_image will be called to perform augmentation

get_transform(image)[source]

Based on probability, choose whether you want to apply the given function or not

class ShapeAug(custom_function, prob=1.0)[source]

Bases: detectron2.data.transforms.Augmentation

Given a probability and a custom function, return a GenericWrapperTransform object whose apply_image will be called to perform augmentation

get_transform(image, instances)[source]

Based on probability, choose whether you want to apply the given function or not

class KRandomAugmentationList(augs, k: int = -1, cropaug=None)[source]

Bases: detectron2.data.transforms.Augmentation

Select and Apply “K” augmentations in “RANDOM” order with “Every” __call__ method invoke

max_range[source]
k = -1[source]
augs[source]
cropaug = None[source]
_setup_augs(augs, k: int)[source]

Setup the argument list. Generates the list of argument to use from the given list :param augs: list of [Augmentation or Transform]) :param k: Number of augment to use from the given list in range [1,len_augs]. :param If False: :param use all. If it is -1: :param generate K randomly between [1: :param len_augs]:

__call__(aug_input) fvcore.transforms.transform.Transform[source]
__repr__()[source]
__str__[source]
class _TransformToAug(tfm: fvcore.transforms.transform.Transform)[source]

Bases: detectron2.data.transforms.Augmentation

tfm[source]
get_transform(*args)[source]
__repr__()[source]
__str__[source]
_transform_to_aug(tfm_or_aug)[source]

Wrap Transform into Augmentation. Private, used internally to implement custom augmentations.