2.1.2.1.1. aijack.defense.debugging.assertions package#
2.1.2.1.1.1. Submodules#
2.1.2.1.1.2. aijack.defense.debugging.assertions.assertions module#
- exception aijack.defense.debugging.assertions.assertions.FlickerException(message)[source]#
Bases:
Exception
Custom exception class for flickering detection.
- exception aijack.defense.debugging.assertions.assertions.MultiBoxAssertionError(message)[source]#
Bases:
AssertionError
Custom assertion error class for multi-box assertions
- aijack.defense.debugging.assertions.assertions.assert_multibox(boxes, counter_threshold=2, eps=0)[source]#
Assert the multi-box condition for a list of boxes.
- Parameters
boxes (list) – A list of boxes. The format of each box is a tuple or list with the format of (x_min, y_min, x_max, y_max)
counter_threshold (int, optional) – The minimum number of overlaps required for each box. Defaults to 2.
eps (float, optional) – The epsilon value for nearly_contains function. Defaults to 0.
- Raises
MultiBoxAssertionError – If any box overlaps with more than counter_threshold other boxes.
- aijack.defense.debugging.assertions.assertions.except_flicker(frames, boxes_of_frames, cur_frame_id=- 1, window_size=10, similarity_threshold=35, data_range=255)[source]#
Check for flickering between the current frame and previous frames.
- Parameters
frames (list) – A list of frames.
boxes_of_frames (list) – A list of boxes for each frame.
cur_frame_id (int, optional) – The index of the current frame. Defaults to -1.
window_size (int, optional) – The number of previous frames to consider. Defaults to 10.
similarity_threshold (float, optional) – The similarity threshold for matching boxes. Defaults to 35.
data_range (int, optional) – The data range of the images. Defaults to 255.
- Raises
FlickerException – If flickering is detected between the current frame and a previous frame.
- aijack.defense.debugging.assertions.assertions.get_simillar_boxes(frame_1, frame_2, boxes_1, boxes_2, similarity_threshold=35, data_range=255, eps=1e-08)[source]#
Get similar boxes between two frames based on the peak signal-to-noise ratio (PSNR).
- Parameters
frame_1 (numpy.ndarray) – The first frame.
frame_2 (numpy.ndarray) – The second frame.
boxes_1 (list) – A list of boxes in frame_1.
boxes_2 (list) – A list of boxes in frame_2.
similarity_threshold (float, optional) – The similarity threshold for matching boxes. Defaults to 35.
data_range (int, optional) – The data range of the images. Defaults to 255.
eps (float, optional) – A small value to avoid division by zero. Defaults to 1e-8.
- Returns
A list of similar boxes.
- Return type
list
- aijack.defense.debugging.assertions.assertions.nearly_contains(box_1, box_2, eps)[source]#
Check if box_1 nearly contains box_2 with a given epsilon value.
- Parameters
box_1 (tuple|list) – The coordinates of the first box in the format (x_min, y_min, x_max, y_max).
box_2 (tuple|list) – The coordinates of the second box in the format (x_min, y_min, x_max, y_max).
eps (float) – The epsilon value.
- Returns
True if box_1 nearly contains box_2, False otherwise.
- Return type
bool
- aijack.defense.debugging.assertions.assertions.psnr(img_1, img_2, data_range=255, eps=1e-08)[source]#
Calculate the peak signal-to-noise ratio (PSNR) between two images.
- Parameters
img_1 (numpy.ndarray) – The first image.
img_2 (numpy.ndarray) – The second image.
data_range (int, optional) – The data range of the images. Defaults to 255.
eps (float, optional) – A small value to avoid division by zero. Defaults to 1e-8.
- Returns
The PSNR value.
- Return type
float