Repository: open-mmlab/mmpretrain

Issue:
bug report
The argument **bboxes** of mmcv.imcrop should be in (xmin, ymin, xmax, ymax) format.
https://github.com/open-mmlab/mmclassification/blob/52d8ea462182872ac8801254298eeacbc0fd9757/mmcls/datasets/pipelines/transforms.py#L121-L124


Discussion:
Thanks for your report and we'll submit a pull request to fix it.

Resolving patch:
diff --git a/mmcls/datasets/pipelines/transforms.py b/mmcls/datasets/pipelines/transforms.py
--- a/mmcls/datasets/pipelines/transforms.py
+++ b/mmcls/datasets/pipelines/transforms.py
@@ -85,8 +85,8 @@ def get_params(img, output_size):
         if width == target_width and height == target_height:
             return 0, 0, height, width
 
-        xmin = random.randint(0, height - target_height)
-        ymin = random.randint(0, width - target_width)
+        ymin = random.randint(0, height - target_height)
+        xmin = random.randint(0, width - target_width)
         return xmin, ymin, target_height, target_width
 
     def __call__(self, results):
@@ -121,7 +121,12 @@ def __call__(self, results):
             xmin, ymin, height, width = self.get_params(img, self.size)
             results[key] = mmcv.imcrop(
                 img,
-                np.array([ymin, xmin, ymin + width - 1, xmin + height - 1]))
+                np.array([
+                    xmin,
+                    ymin,
+                    xmin + width - 1,
+                    ymin + height - 1,
+                ]))
         return results
 
     def __repr__(self):
@@ -202,8 +207,8 @@ def get_params(img, scale, ratio):
             target_height = int(round(math.sqrt(target_area / aspect_ratio)))
 
             if 0 < target_width <= width and 0 < target_height <= height:
-                xmin = random.randint(0, height - target_height)
-                ymin = random.randint(0, width - target_width)
+                ymin = random.randint(0, height - target_height)
+                xmin = random.randint(0, width - target_width)
                 return xmin, ymin, target_height, target_width
 
         # Fallback to central crop
@@ -217,8 +222,8 @@ def get_params(img, scale, ratio):
         else:  # whole image
             target_width = width
             target_height = height
-        xmin = (height - target_height) // 2
-        ymin = (width - target_width) // 2
+        ymin = (height - target_height) // 2
+        xmin = (width - target_width) // 2
         return xmin, ymin, target_height, target_width
 
     def __call__(self, results):
@@ -236,8 +241,8 @@ def __call__(self, results):
             img = mmcv.imcrop(
                 img,
                 np.array([
-                    ymin, xmin, ymin + target_width - 1,
-                    xmin + target_height - 1
+                    xmin, ymin, xmin + target_width - 1,
+                    ymin + target_height - 1
                 ]))
             results[key] = mmcv.imresize(
                 img,


Test patch:
diff --git a/tests/test_pipelines/test_transform.py b/tests/test_pipelines/test_transform.py
--- a/tests/test_pipelines/test_transform.py
+++ b/tests/test_pipelines/test_transform.py
@@ -584,7 +584,7 @@ def test_randomresizedcrop():
     kwargs = dict(
         size=(ori_img.shape[0], ori_img.shape[1]),
         scale=(1.0, 2.0),
-        ratio=(2, 3))
+        ratio=(2., 3.))
     random.seed(seed)
     np.random.seed(seed)
     aug = []
@@ -610,7 +610,7 @@ def test_randomresizedcrop():
     kwargs = dict(
         size=(ori_img.shape[0], ori_img.shape[1]),
         scale=(1.0, 2.0),
-        ratio=(3. / 4, 1))
+        ratio=(3. / 4., 1))
     random.seed(seed)
     np.random.seed(seed)
     aug = []