deepdisc.model.meta_arch
Classes
Generalized R-CNN. Any models that contains the following three components: |
|
Backbone model meant for pre-training. |
Module Contents
- class GeneralizedRCNNWCS(*, backbone: Backbone, proposal_generator: torch.nn.Module, roi_heads: torch.nn.Module, pixel_mean: Tuple[float], pixel_std: Tuple[float], input_format: str | None = None, vis_period: int = 0)[source]
Bases:
torch.nn.ModuleGeneralized R-CNN. Any models that contains the following three components: 1. Per-image feature extraction (aka backbone) 2. Region proposal generation 3. Per-region feature extraction and prediction
- visualize_training(batched_inputs, proposals)[source]
A function used to visualize images and proposals. It shows ground truth bounding boxes on the original image and up to 20 top-scoring predicted object proposals on the original image. Users can implement different visualization functions for different models.
- Parameters:
batched_inputs (list) – a list that contains input to the model.
proposals (list) – a list that contains predicted proposals. Both batched_inputs and proposals should have the same length.
- forward(batched_inputs: List[Dict[str, torch.Tensor]])[source]
- Parameters:
batched_inputs –
a list, batched outputs of
DatasetMapper. Each item in the list contains the inputs for one image. For now, each item in the list is a dict that contains:image: Tensor, image in (C, H, W) format.
instances (optional): groundtruth
Instancesproposals (optional):
Instances, precomputed proposals.
Other information that’s included in the original dicts, such as:
”height”, “width” (int): the output resolution of the model, used in inference. See
postprocess()for details.
- Returns:
Each dict is the output for one input image. The dict contains one key “instances” whose value is a
Instances. TheInstancesobject has the following keys: “pred_boxes”, “pred_classes”, “scores”, “pred_masks”, “pred_keypoints”- Return type:
list[dict]
- inference(batched_inputs: List[Dict[str, torch.Tensor]], detected_instances: List[detectron2.structures.Instances] | None = None, do_postprocess: bool = True)[source]
Run inference on the given inputs.
- Parameters:
batched_inputs (list[dict]) – same as in
forward()detected_instances (None or list[Instances]) – if not None, it contains an Instances object per image. The Instances object contains “pred_boxes” and “pred_classes” which are known boxes in the image. The inference will then skip the detection of bounding boxes, and only predict other per-ROI outputs.
do_postprocess (bool) – whether to apply post-processing on the outputs.
- Returns:
When do_postprocess=True, same as in
forward(). Otherwise, a list[Instances] containing raw network outputs.
- class Backbone(*, backbone: torch.nn.Module, feature_level: str = None, projection_head: torch.nn.Module, pixel_mean: Tuple[float], pixel_std: Tuple[float], input_format: str | None = None)[source]
Bases:
torch.nn.ModuleBackbone model meant for pre-training.
- forward(batched_inputs: List[Tuple[torch.Tensor, torch.Tensor]])[source]
- Parameters:
batched_inputs –
a list, batched outputs of
DatasetMapper. Each item in the list contains the image and corresponding label. For now, each item in the list is a tuple that contains:image: Tensor, image in (C, H, W) format.
label (optional):`
- Returns:
Each item is the predicted label for one input image.
- Return type:
list[labels]
- inference(batched_inputs: List[Tuple[torch.Tensor, torch.Tensor]])[source]
Run inference on the given inputs.
- Parameters:
batched_inputs (list[dict]) – same as in
forward()detected_instances (None or list[Instances]) – if not None, it contains an Instances object per image. The Instances object contains “pred_boxes” and “pred_classes” which are known boxes in the image. The inference will then skip the detection of bounding boxes, and only predict other per-ROI outputs.
do_postprocess (bool) – whether to apply post-processing on the outputs.
- Returns:
When do_postprocess=True, same as in
forward(). Otherwise, a list[Instances] containing raw network outputs.