def augment_detections(hyper_params, feature, label):
<EOL>if hyper_params.problem.get("<STR_LIT>", None) is None:<EOL><INDENT>return feature, label<EOL><DEDENT>img_h, img_w, img_c = feature["<STR_LIT:image>"].shape<EOL>augmented_feature = {}<EOL>augmented_label = {}<EOL>augmented_feature["<STR_LIT:image>"] = feature["<STR_LIT:image>"].copy()<EOL>if "<STR_LIT>" in feature:<EOL><INDENT>augmented_feature["<STR_LIT>"] = feature["<STR_LIT>"].copy()<EOL><DEDENT>if "<STR_LIT>" in feature:<EOL><INDENT>augmented_feature["<STR_LIT>"] = feature["<STR_LIT>"]<EOL><DEDENT>augmented_feature["<STR_LIT>"] = np.array([<NUM_LIT:0>], dtype=np.uint8)<EOL>augmented_feature["<STR_LIT>"] = np.array([<NUM_LIT:0>, <NUM_LIT:0>], dtype=np.int8)<EOL>for k in label.keys():<EOL><INDENT>augmented_label[k] = [detection.copy() for detection in label[k]]<EOL><DEDENT>if hyper_params.problem.augmentation.get("<STR_LIT>", False):<EOL><INDENT>if random.random() < <NUM_LIT:0.5>:<EOL><INDENT>img_h, img_w, img_c = augmented_feature["<STR_LIT:image>"].shape<EOL>augmented_feature["<STR_LIT:image>"] = np.fliplr(augmented_feature["<STR_LIT:image>"])<EOL>if "<STR_LIT>" in feature:<EOL><INDENT>augmented_feature["<STR_LIT>"] = np.fliplr(augmented_feature["<STR_LIT>"])<EOL><DEDENT>augmented_feature["<STR_LIT>"][<NUM_LIT:0>] = <NUM_LIT:1><EOL>hflip_detections(augmented_label, img_w)<EOL><DEDENT><DEDENT>if hyper_params.problem.augmentation.get("<STR_LIT>", False):<EOL><INDENT>img_h, img_w, img_c = augmented_feature["<STR_LIT:image>"].shape<EOL>dx = int(random.random() * <NUM_LIT:3>)<EOL>dy = int(random.random() * <NUM_LIT:3>)<EOL>augmented_feature["<STR_LIT:image>"] = crop_image(augmented_feature["<STR_LIT:image>"], dy, dx, img_h - dy, img_w - dx)<EOL>if "<STR_LIT>" in feature:<EOL><INDENT>augmented_feature["<STR_LIT>"] = crop_image(augmented_feature["<STR_LIT>"], dy, dx, img_h - dy, img_w - dx)<EOL><DEDENT>augmented_feature["<STR_LIT>"][<NUM_LIT:0>] += dy<EOL>augmented_feature["<STR_LIT>"][<NUM_LIT:1>] += dx<EOL>move_detections(augmented_label, -dy, -dx)<EOL><DEDENT>if hyper_params.problem.augmentation.get("<STR_LIT>", None) is not None:<EOL><INDENT>img_h, img_w, img_c = augmented_feature["<STR_LIT:image>"].shape<EOL>target_w = hyper_params.problem.augmentation.random_crop.shape.width<EOL>target_h = hyper_params.problem.augmentation.random_crop.shape.height<EOL>delta_x = max(int(math.ceil((target_w + <NUM_LIT:1> - img_w) / <NUM_LIT:2>)), <NUM_LIT:0>)<EOL>delta_y = max(int(math.ceil((target_h + <NUM_LIT:1> - img_h) / <NUM_LIT:2>)), <NUM_LIT:0>)<EOL>move_detections(augmented_label, delta_y, delta_x)<EOL>augmented_feature["<STR_LIT:image>"] = cv2.copyMakeBorder(augmented_feature["<STR_LIT:image>"],<EOL>delta_y, delta_y, delta_x, delta_x,<EOL>cv2.BORDER_CONSTANT)<EOL>img_h, img_w, img_c = augmented_feature["<STR_LIT:image>"].shape<EOL>start_x = <NUM_LIT:0><EOL>start_y = <NUM_LIT:0><EOL>if len(augmented_label["<STR_LIT>"]) != <NUM_LIT:0>:<EOL><INDENT>idx = random.randint(<NUM_LIT:0>, len(augmented_label["<STR_LIT>"]) - <NUM_LIT:1>)<EOL>detection = augmented_label["<STR_LIT>"][idx]<EOL>start_x = int(detection.cx - random.random() * (target_w - <NUM_LIT:20>) / <NUM_LIT> - <NUM_LIT:10>)<EOL>start_y = int(detection.cy - random.random() * (target_h - <NUM_LIT:20>) / <NUM_LIT> - <NUM_LIT:10>)<EOL><DEDENT>else:<EOL><INDENT>start_x = int(img_w * random.random())<EOL>start_y = int(img_h * random.random())<EOL><DEDENT>if start_x < <NUM_LIT:0>:<EOL><INDENT>start_x = <NUM_LIT:0><EOL><DEDENT>if start_y < <NUM_LIT:0>:<EOL><INDENT>start_y = <NUM_LIT:0><EOL><DEDENT>if start_x >= img_w - target_w:<EOL><INDENT>start_x = img_w - target_w - <NUM_LIT:1><EOL><DEDENT>if start_y >= img_h - target_h:<EOL><INDENT>start_y = img_h - target_h - <NUM_LIT:1><EOL><DEDENT>augmented_feature["<STR_LIT:image>"] = crop_image(augmented_feature["<STR_LIT:image>"], start_y, start_x, target_h, target_w)<EOL>if "<STR_LIT>" in feature:<EOL><INDENT>augmented_feature["<STR_LIT>"] = crop_image(augmented_feature["<STR_LIT>"], start_y, start_x, target_h, target_w)<EOL><DEDENT>augmented_feature["<STR_LIT>"][<NUM_LIT:0>] += start_y<EOL>augmented_feature["<STR_LIT>"][<NUM_LIT:1>] += start_x<EOL>move_detections(augmented_label, -start_y, -start_x)<EOL><DEDENT>if hyper_params.problem.augmentation.get("<STR_LIT>", False):<EOL><INDENT>if random.random() < <NUM_LIT:0.5>:<EOL><INDENT>augmented_feature["<STR_LIT:image>"] = full_texture_augmentation(augmented_feature["<STR_LIT:image>"])<EOL><DEDENT><DEDENT>return augmented_feature, augmented_label<EOL>
Augment the detection dataset.

In your hyper_parameters.problem.augmentation add configurations to enable features.
Supports "enable_horizontal_flip", "enable_micro_translation", "random_crop" : {"shape": { "width", "height" }}
and "enable_texture_augmentation". Make sure to also set the "steps" otherwise this method will not be used properly.

Random crop ensures at least one detection is in the crop region.

Sample configuration
"problem": {
    "augmentation": {
        "steps": 40,
        "enable_texture_augmentation": true,
        "enable_micro_translation": true,
        "enable_horizontal_flip": true,
        "random_crop": {
            "shape": {
                "width": 256,
                "height": 256
            }
        }
    }
}

:param hyper_params: The hyper parameters object
:param feature: A dict containing all features, must be in the style created by detection datasets.
:param label: A label dict in the detection dataset style.
:return: Modified feature and label dict (copied & modified).