foxai.explainer.computer_vision.object_detection package
Submodules
foxai.explainer.computer_vision.object_detection.base_object_detector module
File contains abstract base ObjectDetector class.
- class foxai.explainer.computer_vision.object_detection.base_object_detector.BaseObjectDetector[source]
Bases:
Module
,ABC
Base ObjectDetector class which returns predictions with logits to explain.
Code based on https://github.com/pooya-mohammadi/yolov5-gradcam.
- abstract forward(image: Tensor) Tuple[List[PredictionOutput], List[Tensor]] [source]
Forward pass of the network.
- Parameters:
image – Image to process.
- Returns:
Tuple of 2 values, first is tuple of predictions containing bounding-boxes, class number, class name and confidence; second value is list of tensors with logits per each detection.
- static preprocessing(img: ndarray, new_shape: Tuple[int, int] = (640, 640), change_original_ratio: bool = False, scaleup: bool = True) Tensor [source]
Preprocess image before prediction.
Preprocessing is a process consisting of steps: * adding batch dimension * resizing images to desired shapes * adjusting image channels to (B x C x H x W) * convertion to float
- Parameters:
img – Image to preprocess.
new_shape – Desired shape of image. Defaults to (640, 640).
change_original_ratio – If resized image should have different height to width ratio than original image. Defaults to False.
scaleup – If scale up image. Defaults to True.
- Returns:
Tensor containing preprocessed image.
- training: bool
foxai.explainer.computer_vision.object_detection.types module
File contains data class for object detection unified model output.
- class foxai.explainer.computer_vision.object_detection.types.ObjectDetectionOutput(saliency_maps: List[Tensor], logits: List[Tensor], predictions: List[PredictionOutput])[source]
Bases:
object
Data class for model predictions for object detection.
It contains heatmaps, logits and predictions in YOLO style.
- logits: List[Tensor]
- predictions: List[PredictionOutput]
- saliency_maps: List[Tensor]
foxai.explainer.computer_vision.object_detection.utils module
File contains functions to handle images, coordinates and calcualte IoU.
Based on code: https://github.com/pooya-mohammadi/yolov5-gradcam.
- foxai.explainer.computer_vision.object_detection.utils.resize_image(image: ndarray, new_shape: Tuple[int, int] = (640, 640), change_original_ratio: bool = False, scaleup: bool = True, interpolation: int = 1) ndarray [source]
Resize image to given shape.
- Parameters:
image – Image to resize.
new_shape – Desired shape of image. Defaults to (640, 640).
change_original_ratio – If resized image should have different height to width ratio than original image. Defaults to False.
scaleup – If scale up image. Defaults to True.
interpolation – OpenCV interpolation method. Defaults to cv2.INTER_LINEAR.
- Returns:
Resized image.