export.drise package
Submodules
export.drise.exporter module
- class export.drise.exporter.DRiseSaliencyObjectDetectionExporter(model: ObjectDetector, num_classes: int, batch_size: int = 1, name: str | None = None, num_masks: int = 1000, score_threshold: float = 0.5, criterion: Callable[[int, Batch], bool | Iterable[int]] | None = None)
Bases:
ExporterAn exporter for D-RISE object detection saliency maps.
- class ModelWrapper(model: ObjectDetector, num_classes: int, spec)
Bases:
ModuleA wrapper around an Armory object detector to make it work with the D-RISE implementation.
- expand_scores(scores: Tensor, labels: Tensor) Tensor
Expands the given batch of scores and labels into probabilities for all classes. The score for the assigned label remains as specified, with all other classes receiving the evenly divided remaining probability.
- Parameters:
scores (torch.Tensor) – N-length tensor of predicted scores
labels (torch.Tensor) – N-length tensor of assigned labels
- Returns:
(N, C) tensor of probabilities, where C is the total number of classes
- Return type:
torch.Tensor
- forward(images_pt: Tensor)
Invokes the wrapped model and returns the resulting boxes, class probabilities, and objectness as a tuple.
- Parameters:
images_pt (torch.Tensor) – images_pt
- training: bool
- export_samples(batch_idx: int, batch: ObjectDetectionBatch, samples: Iterable[int]) None
Export samples
- Parameters:
batch_idx (int) – Batch index
batch (ObjectDetectionBatch) – Batch
samples (Iterable[int]) – Samples
- spec = ImageSpec(dim=<ImageDimensions.CHW: 1>, scale=Scale(dtype=<DataType.FLOAT: 2>, max=1.0, mean=None, std=None))
export.drise.impl module
- export.drise.impl.draw_box(image, box, color='red')
Draw box
- Parameters:
image (_type_) – Image
box (_type_) – Box
color (str, optional) – Color, defaults to “red”
- export.drise.impl.draw_contour(img_pt, cpu_map, thickness=1, levels=[0.95, 0.99], pixel_weight=True)
Draw contour
- Parameters:
img_pt (_type_) – img_pt
cpu_map (_type_) – cpu_map
thickness (int, optional) – Thickness, defaults to 1
levels (list, optional) – Levels, defaults to [0.95, 0.99]
pixel_weight (bool, optional) – If true, uses the pixels that contain <level> of the total value (after subtracting the min) if false, <level> is quartiles. Defaults to True
- export.drise.impl.draw_heatmap(image, saliency_map: Tensor, box)
Draw heatmap
- Parameters:
image (_type_) – Image
saliency_map (torch.Tensor) – Saliency map
box (_type_) – Box
- export.drise.impl.generate_masks(w=16, h=16, p=0.5, number_of_masks=5000)
Generate masks
- Parameters:
w (int, optional) – Width, defaults to 16
h (int, optional) – Height defaults to 16
p (float, optional) – P, defaults to 0.5
number_of_masks (int, optional) – Number of masks, defaults to 5000
- export.drise.impl.get_proposal_data(img_pt, model, w=16, h=16, p=0.5, number_of_masks=5000, batch_size=16, object_thres=0.5, device='cpu')
Get proposal data
- Parameters:
img_pt (_type_) – img_pt
model (_type_) – Model
w (int, optional) – Width, defaults to 16
h (int, optional) – Height, defaults to 16
p (float, optional) – P, defaults to 0.5
number_of_masks (int, optional) – Number of masks, defaults to 5000
batch_size (int, optional) – Batch size, defaults to 16
object_thres (float, optional) – Object threshold, defaults to 0.5
device (str, optional) – Device, defaults to “cpu”
- export.drise.impl.imgpath2tensor(directory, file_name)
Image path to tensor
- Parameters:
directory (str) – Directory
file_name (str) – File name
- export.drise.impl.make_saliency_img(img_pt, saliency_map, box, color='black', levels=[0.9, 0.95, 0.975, 0.99], contour=False)
Make saliency image
- Parameters:
img_pt (_type_) – img_pt
saliency_map (_type_) – Saliency map
box (_type_) – Box
color (str, optional) – Color, defaults to “black”
levels (list, optional) – Levels, defaults to [0.9, 0.95, 0.975, 0.99]
contour (bool, optional) – Contour, defaults to False
- export.drise.impl.make_saliency_map(img_pt, gt_box, gt_prob, masks, rand_offset_nums, boxes, cls_probs, objectiveness, device='cpu')
Make saliency map
- Parameters:
img_pt (_type_) – img_pt
gt_box (_type_) – gt_box
gt_prob (_type_) – gt_prob
masks (_type_) – Masks
rand_offset_nums (_type_) – rand_offset_nums
boxes (_type_) – Box
cls_probs (_type_) – cls_probs
objectiveness (_type_) – Objectiveness
device (str, optional) – Device, defaults to “cpu”
- export.drise.impl.masked_dataloader(img_pt, masks_all, rand_offset_nums, batch_size=4, device='cpu')
Masked dataloader
- Parameters:
img_pt (_type_) – image_pt
masks_all (_type_) – masks_all
rand_offset_nums (_type_) – rand_offset_nums
batch_size (int, optional) – Batch size, defaults to 4
device (str, optional) – Device, defaults to “cpu”