engine package

Subpackages

Submodules

engine.eval_detection module

engine.eval_detection.predict_and_save(opts, input_tensor: Tensor, model: Module, input_np: ndarray | None = None, device: Optional = device(type='cpu'), is_coco_evaluation: bool | None = False, file_name: str | None = None, output_stride: int | None = 32, orig_h: int | None = None, orig_w: int | None = None, *args, **kwargs)[source]

This function makes a prediction on the input tensor and optionally save the detection results :param opts: command-line arguments :param input_tensor: Input tensor of size \((1, C, H, W)\) :type input_tensor: Tensor :param model: detection model :type model: nn.Module :param input_np: Input numpy image of size \((H, W, C)\). Used only for visualization purposes. Defaults to None :type input_np: Optional[np.ndarray] :param device: Device. Defaults to cpu. :type device: Optional[str] :param is_coco_evaluation: Evaluating on MS-COCO object detection. Defaults to False. :type is_coco_evaluation: Optional[bool] :param file_name: File name for storing detection results. Only applicable when is_coco_evaluation is False. Defaults to None. :type file_name: Optional[bool] :param output_stride: Output stride. This is used to ensure that image size is divisible by this factor. Defaults to 32. :type output_stride: Optional[int] :param orig_h: Original height of the input image. Useful for visualizing detection results. Defaults to None. :type orig_h: Optional[int] :param orig_w: Original width of the input image. Useful for visualizing detection results. Defaults to None. :type orig_w: Optional[int]

engine.eval_detection.predict_labeled_dataset(opts, **kwargs)[source]
engine.eval_detection.read_and_process_image(opts, image_fname: str, *args, **kwargs)[source]
engine.eval_detection.predict_image(opts, image_fname, **kwargs)[source]
engine.eval_detection.predict_images_in_folder(opts, **kwargs)[source]
engine.eval_detection.main_detection_evaluation(args: List[str] | None = None, **kwargs)[source]

engine.eval_segmentation module

engine.eval_segmentation.predict_and_save(opts, input_tensor: Tensor, file_name: str, orig_h: int, orig_w: int, model: Module, target_mask: Tensor | None = None, device: Optional = device(type='cpu'), conf_mat: ConfusionMatrix | None = None, color_map: List | None = None, orig_image: Image | None = None, adjust_label: int | None = 0, is_cityscape: bool | None = False, *args, **kwargs) None[source]

Predict the segmentation mask and optionally save them

engine.eval_segmentation.draw_binary_masks(opts, pred_mask: Tensor, file_name: str, results_location: str, is_cityscape: bool | None = False) None[source]

Save masks whose values ranges between 0 and number_of_classes - 1

engine.eval_segmentation.draw_colored_masks(opts, orig_image: Image, pred_mask: Tensor, target_mask: Tensor, file_name: str, results_location: str, color_map: List | None = None) None[source]

Apply color map to segmentation masks

engine.eval_segmentation.predict_labeled_dataset(opts, **kwargs) None[source]
engine.eval_segmentation.read_and_process_image(opts, image_fname: str, *args, **kwargs)[source]
engine.eval_segmentation.predict_image(opts, image_fname: str, **kwargs) None[source]
engine.eval_segmentation.predict_images_in_folder(opts, **kwargs) None[source]
engine.eval_segmentation.main_segmentation_evaluation(args: List[str] | None = None, **kwargs) None[source]

engine.evaluation_engine module

class engine.evaluation_engine.Evaluator(opts, model, test_loader)[source]

Bases: object

__init__(opts, model, test_loader)[source]
eval_fn_image(model)[source]
eval_fn_video(model)[source]
run()[source]

engine.training_engine module

class engine.training_engine.Trainer(opts, model, validation_loader, training_loader, criterion, optimizer, scheduler, gradient_scaler, start_epoch: int = 0, start_iteration: int = 0, best_metric: float = 0.0, model_ema=None, *args, **kwargs)[source]

Bases: object

This class defines the training and validation code for training models with CVNets

__init__(opts, model, validation_loader, training_loader, criterion, optimizer, scheduler, gradient_scaler, start_epoch: int = 0, start_iteration: int = 0, best_metric: float = 0.0, model_ema=None, *args, **kwargs) None[source]
compute_grad_norm()[source]
train_epoch(epoch)[source]
val_epoch(epoch, model, extra_str='')[source]
find_easy_samples(epoch, model, *args, **kwargs)[source]

This function identifies easy samples in the training set and removes them from training.

Note

Currently, this is implemented separately to avoid breaking the training and validation pipeline. In future, this will be combined with main training loop to reduce overhead.

run(train_sampler=None)[source]
run_loss_landscape()[source]

engine.utils module

engine.utils.autocast_fn(enabled: bool, amp_precision: str | None = 'float16')[source]
engine.utils.get_batch_size(x: Tensor | Dict | List) int[source]
engine.utils.log_metrics(lrs: List | float, log_writer, train_loss: float, val_loss: float, epoch: int, best_metric: float, val_ema_loss: float | None = None, ckpt_metric_name: str | None = None, train_ckpt_metric: float | None = None, val_ckpt_metric: float | None = None, val_ema_ckpt_metric: float | None = None) None[source]
engine.utils.get_log_writers(opts: Namespace, save_location: str | None)[source]

Module contents