From 6304b647328c7a63aaf820e837675c64bebcfb53 Mon Sep 17 00:00:00 2001
From: Korabelnikov Aleks <nesoriti@yandex.ru>
Date: Thu, 7 Nov 2019 20:58:40 +0300
Subject: [PATCH] generalization of Expand transfrom probability (#1633)

Allows to use not only 0.5 probability.
---
 mmdet/datasets/pipelines/transforms.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/mmdet/datasets/pipelines/transforms.py b/mmdet/datasets/pipelines/transforms.py
index b38884e..e0cca25 100644
--- a/mmdet/datasets/pipelines/transforms.py
+++ b/mmdet/datasets/pipelines/transforms.py
@@ -509,13 +509,15 @@ class Expand(object):
         mean (tuple): mean value of dataset.
         to_rgb (bool): if need to convert the order of mean to align with RGB.
         ratio_range (tuple): range of expand ratio.
+        prob (float): probability of applying this transformation
     """
 
     def __init__(self,
                  mean=(0, 0, 0),
                  to_rgb=True,
                  ratio_range=(1, 4),
-                 seg_ignore_label=None):
+                 seg_ignore_label=None,
+                 prob=0.5):
         self.to_rgb = to_rgb
         self.ratio_range = ratio_range
         if to_rgb:
@@ -524,9 +526,10 @@ class Expand(object):
             self.mean = mean
         self.min_ratio, self.max_ratio = ratio_range
         self.seg_ignore_label = seg_ignore_label
+        self.prob = prob
 
     def __call__(self, results):
-        if random.randint(2):
+        if random.uniform(0, 1) > self.prob:
             return results
 
         img, boxes = [results[k] for k in ('img', 'gt_bboxes')]
-- 
GitLab