Utils
Saliency Generation CLI Entrypoint
sal-on-coco-dets
Generate saliency maps for detections in a COCO format file and write them to disk.
Maps for each detection are written out in subdirectories named after their corresponding image file.
DATASET_DIR - Root directory of dataset. OUTPUT_DIR - Directory to write the saliency maps to. CONFIG_FILE - Configuration file for the object detector and GenerateObjectDetectorBlackboxSaliency implementations to use.
- param dataset_dir:
Root directory of dataset.
- param output_dir:
Directory to write the saliency maps to.
- param config_file:
Config file specifying the object detector and
GenerateObjectDetectorBlackboxSaliencyimplementations to use.- param overlay_image:
Overlay saliency maps on images with bounding boxes. RGB images are converted to grayscale. Default is to write out saliency maps by themselves.
- param generate_config_file:
File to write default config file, only written if specified. Only one of “DetectImageObjects” and “ObjectDetector” should be kept. This skips the normal operation of this tool and only outputs the file.
- param verbose:
Display progress messages. Default is false.
sal-on-coco-dets [OPTIONS] DATASET_DIR OUTPUT_DIR CONFIG_FILE
Options
- -g, --generate-config-file <generate_config_file>
write default config to specified file
- --overlay-image
overlay saliency map on images with bounding boxes, RGB images are converted to grayscale
- -v, --verbose
print progress messages
Arguments
- DATASET_DIR
Required argument
- OUTPUT_DIR
Required argument
- CONFIG_FILE
Required argument
Saliency Computation function
This module provides functionality for generating saliency maps for object detection models using blackbox saliency generation techniques. It integrates with the MAITE dataset and object detection protocols to produce visual explanations for model predictions.
- Functions:
- compute_sal_maps: Generates saliency maps for a given dataset using a blackbox object detector
and a saliency map generator.
sal_on_dets: Facilitates saliency map computation with a MAITE-compatible detector.
- Dependencies:
numpy: For numerical operations.
smqtk_core.configuration: For configuration handling.
smqtk_detection.interfaces.detect_image_objects: Interface for object detection in images.
xaitk_saliency: For generating saliency maps for object detection.
maite.protocols.object_detection: For handling datasets and models in the MAITE framework.
xaitk_jatic.interop.object_detection.model: For interoperability with JATIC object detection models.
- Usage:
These functions enable generating saliency maps for datasets using compatible object detection models and saliency generators. Saliency maps provide insights into which parts of an image influenced the model’s predictions.
- Example:
# Generate saliency maps for a dataset using a specific saliency generator and detector. saliency_maps, config = sal_on_dets(
dataset=my_dataset, sal_generator=my_sal_generator, detector=my_model, id_to_name=my_label_mapping, img_batch_size=4
)
- xaitk_jatic.utils.sal_on_dets.compute_sal_maps(dataset: Dataset, sal_generator: GenerateObjectDetectorBlackboxSaliency, blackbox_detector: DetectImageObjects, num_classes: int) tuple[list[ndarray], dict]
Generate saliency maps for the provided dataset.
- Parameters:
dataset – MAITE dataset
sal_generator –
GenerateObjectDetectorBlackboxSaliencygeneratorblackbox_detector –
DetectImageObjectsdetectornum_classes – Number of classes potentially predicted by the detector.
- xaitk_jatic.utils.sal_on_dets.sal_on_dets(dataset: Dataset, sal_generator: GenerateObjectDetectorBlackboxSaliency, detector: Model, ids: Sequence[int], img_batch_size: int = 1) tuple[list[ndarray], dict]
Generate saliency maps for provided dataset.
- Parameters:
dataset – MAITE dataset
sal_generator –
GenerateObjectDetectorBlackboxSaliencygeneratordetector – MAITE detector
id_to_name – Mapping from label IDs to names
img_batch_size – Image batch size for inference