From dc2e462c4b5b68349457cad1c0375c9183f02e5f Mon Sep 17 00:00:00 2001 From: Stefan Klut Date: Tue, 12 Dec 2023 18:11:10 +0100 Subject: [PATCH] crop done --- .../baseline/baseline_ovdr_crop.yaml | 108 ++++++++++++++++++ datasets/augmentations.py | 108 ++++++++++-------- 2 files changed, 168 insertions(+), 48 deletions(-) create mode 100644 configs/segmentation/baseline/baseline_ovdr_crop.yaml diff --git a/configs/segmentation/baseline/baseline_ovdr_crop.yaml b/configs/segmentation/baseline/baseline_ovdr_crop.yaml new file mode 100644 index 0000000..e3bd4cc --- /dev/null +++ b/configs/segmentation/baseline/baseline_ovdr_crop.yaml @@ -0,0 +1,108 @@ +# python main.py --config configs/segmentation/baseline_ovdr.yaml --tmp_dir /encrypted/tmp +_BASE_: ../segmentation_base.yaml + +OUTPUT_DIR: /encrypted/baseline + +NAME: ovdr_scaling_test + +PREPROCESS: + OVERWRITE: False + DISABLE_CHECK: False + + RESIZE: + RESIZE_MODE: "scaling" + SCALING: 0.5 + MAX_SIZE: -1 + + BASELINE: + LINE_WIDTH: 10 + +INPUT: + RESIZE_MODE: "scaling" + SCALING_TRAIN: 1.0 + MAX_SIZE_TRAIN: -1 + + MAX_SIZE_TEST: -1 + + FORMAT: RGB + + GRAYSCALE: + PROBABILITY: 0.1 + + BRIGHTNESS: + PROBABILITY: 0.2 + MIN_INTENSITY: 0.5 + MAX_INTENSITY: 1.5 + + CONTRAST: + PROBABILITY: 0.2 + MIN_INTENSITY: 0.5 + MAX_INTENSITY: 1.5 + + SATURATION: + PROBABILITY: 0.1 + MIN_INTENSITY: 0.5 + MAX_INTENSITY: 1.5 + + GAUSSIAN_FILTER: + PROBABILITY: 0.2 + MIN_SIGMA: 0.5 + MAX_SIGMA: 1.5 + + HORIZONTAL_FLIP: + PROBABILITY: 0. + + VERTICAL_FLIP: + PROBABILITY: 0. + + ELASTIC_DEFORMATION: + PROBABILITY: 0.2 + ALPHA: 0.1 + SIGMA: 0.01 + + AFFINE: + PROBABILITY: 1. + + TRANSLATION: + PROBABILITY: 0.9 + STANDARD_DEVIATION: 0.02 + + ROTATION: + PROBABILITY: 0.9 + KAPPA: 30. + + SHEAR: + PROBABILITY: 0.9 + KAPPA: 20. + + SCALE: + PROBABILITY: 0.9 + STANDARD_DEVIATION: 0.12 + + CROP: + ENABLED: True + SIZE: [1024, 1024] + TYPE: absolute + +SOLVER: + IMS_PER_BATCH: 2 + CHECKPOINT_PERIOD: 25000 + BASE_LR: 0.0002 + GAMMA: 0.1 + STEPS: () #(80000, 120000, 160000) + MAX_ITER: 500000 + +MODEL: + MODE: baseline + + SEM_SEG_HEAD: + NUM_CLASSES: 2 + + WEIGHTS: + +TRAIN: + WEIGHTS: + +TEST: + WEIGHTS: + EVAL_PERIOD: 10000 diff --git a/datasets/augmentations.py b/datasets/augmentations.py index 33979f9..7b30ded 100644 --- a/datasets/augmentations.py +++ b/datasets/augmentations.py @@ -951,35 +951,36 @@ def build_augmentation(cfg: CfgNode, mode: str = "train") -> list[T.Augmentation if not mode == "train": return augmentation - # Color augments - augmentation.append(RandomApply(Grayscale(image_format=cfg.INPUT.FORMAT), prob=cfg.INPUT.GRAYSCALE.PROBABILITY)) - augmentation.append( - RandomApply( - RandomBrightness( - intensity_min=cfg.INPUT.BRIGHTNESS.MIN_INTENSITY, - intensity_max=cfg.INPUT.BRIGHTNESS.MAX_INTENSITY, - ), - prob=cfg.INPUT.BRIGHTNESS.PROBABILITY, - ) - ) + # Moving pixels + augmentation.append( RandomApply( - RandomContrast( - intensity_min=cfg.INPUT.CONTRAST.MIN_INTENSITY, - intensity_max=cfg.INPUT.CONTRAST.MAX_INTENSITY, + RandomAffine( + t_stdv=cfg.INPUT.AFFINE.TRANSLATION.STANDARD_DEVIATION, + r_kappa=cfg.INPUT.AFFINE.ROTATION.KAPPA, + sh_kappa=cfg.INPUT.AFFINE.SHEAR.KAPPA, + sc_stdv=cfg.INPUT.AFFINE.SCALE.STANDARD_DEVIATION, + probabilities=( + cfg.INPUT.AFFINE.TRANSLATION.PROBABILITY, + cfg.INPUT.AFFINE.ROTATION.PROBABILITY, + cfg.INPUT.AFFINE.SHEAR.PROBABILITY, + cfg.INPUT.AFFINE.SCALE.PROBABILITY, + ), ), - prob=cfg.INPUT.CONTRAST.PROBABILITY, + prob=cfg.INPUT.AFFINE.PROBABILITY, ) ) + augmentation.append( RandomApply( - RandomSaturation( - intensity_min=cfg.INPUT.SATURATION.MIN_INTENSITY, - intensity_max=cfg.INPUT.SATURATION.MAX_INTENSITY, + RandomElastic( + alpha=cfg.INPUT.ELASTIC_DEFORMATION.ALPHA, + sigma=cfg.INPUT.ELASTIC_DEFORMATION.SIGMA, ), - prob=cfg.INPUT.SATURATION.PROBABILITY, + prob=cfg.INPUT.ELASTIC_DEFORMATION.PROBABILITY, ) ) + augmentation.append( RandomApply( RandomGaussianFilter( @@ -1010,53 +1011,64 @@ def build_augmentation(cfg: CfgNode, mode: str = "train") -> list[T.Augmentation ) ) + # Orientation + augmentation.append( RandomApply( - RandomElastic( - alpha=cfg.INPUT.ELASTIC_DEFORMATION.ALPHA, - sigma=cfg.INPUT.ELASTIC_DEFORMATION.SIGMA, + RandomOrientation( + orientation_percentages=cfg.INPUT.ORIENTATION.PERCENTAGES, ), - prob=cfg.INPUT.ELASTIC_DEFORMATION.PROBABILITY, + prob=cfg.INPUT.ORIENTATION.PROBABILITY, ) ) + # Color augments augmentation.append( RandomApply( - RandomAffine( - t_stdv=cfg.INPUT.AFFINE.TRANSLATION.STANDARD_DEVIATION, - r_kappa=cfg.INPUT.AFFINE.ROTATION.KAPPA, - sh_kappa=cfg.INPUT.AFFINE.SHEAR.KAPPA, - sc_stdv=cfg.INPUT.AFFINE.SCALE.STANDARD_DEVIATION, - probabilities=( - cfg.INPUT.AFFINE.TRANSLATION.PROBABILITY, - cfg.INPUT.AFFINE.ROTATION.PROBABILITY, - cfg.INPUT.AFFINE.SHEAR.PROBABILITY, - cfg.INPUT.AFFINE.SCALE.PROBABILITY, - ), + Grayscale( + image_format=cfg.INPUT.FORMAT, ), - prob=cfg.INPUT.AFFINE.PROBABILITY, + prob=cfg.INPUT.GRAYSCALE.PROBABILITY, ) ) - augmentation.append( RandomApply( - RandomOrientation( - orientation_percentages=cfg.INPUT.ORIENTATION.PERCENTAGES, + RandomBrightness( + intensity_min=cfg.INPUT.BRIGHTNESS.MIN_INTENSITY, + intensity_max=cfg.INPUT.BRIGHTNESS.MAX_INTENSITY, ), - prob=cfg.INPUT.ORIENTATION.PROBABILITY, + prob=cfg.INPUT.BRIGHTNESS.PROBABILITY, + ) + ) + augmentation.append( + RandomApply( + RandomContrast( + intensity_min=cfg.INPUT.CONTRAST.MIN_INTENSITY, + intensity_max=cfg.INPUT.CONTRAST.MAX_INTENSITY, + ), + prob=cfg.INPUT.CONTRAST.PROBABILITY, + ) + ) + augmentation.append( + RandomApply( + RandomSaturation( + intensity_min=cfg.INPUT.SATURATION.MIN_INTENSITY, + intensity_max=cfg.INPUT.SATURATION.MAX_INTENSITY, + ), + prob=cfg.INPUT.SATURATION.PROBABILITY, ) ) - # augmentation.append(RandomApply(RandomTranslation(t_stdv=cfg.INPUT.AFFINE.TRANSLATION.STANDARD_DEVIATION), - # prob=cfg.INPUT.AFFINE.PROBABILITY * cfg.INPUT.AFFINE.TRANSLATION.PROBABILITY)) - # augmentation.append(RandomApply(RandomRotation(r_kappa=cfg.INPUT.AFFINE.ROTATION.KAPPA), - # prob=cfg.INPUT.AFFINE.PROBABILITY * cfg.INPUT.AFFINE.ROTATION.PROBABILITY)) - # augmentation.append(RandomApply(RandomShear(sh_kappa=cfg.INPUT.AFFINE.SHEAR.KAPPA), - # prob=cfg.INPUT.AFFINE.PROBABILITY * cfg.INPUT.AFFINE.SHEAR.PROBABILITY)) - # augmentation.append(RandomApply(RandomScale(sc_stdv=cfg.INPUT.AFFINE.SCALE.STANDARD_DEVIATION), - # prob=cfg.INPUT.AFFINE.PROBABILITY * cfg.INPUT.AFFINE.SCALE.PROBABILITY)) + # Crop + if cfg.INPUT.CROP.ENABLED: + augmentation.append( + RandomCrop_CategoryAreaConstraint( + crop_type=cfg.INPUT.CROP.TYPE, + crop_size=cfg.INPUT.CROP.SIZE, + single_category_max_area=cfg.INPUT.CROP.SINGLE_CATEGORY_MAX_AREA, + ) + ) - # print(augmentation) return augmentation