diff --git a/mmedit/datasets/pipelines/augmentation.py b/mmedit/datasets/pipelines/augmentation.py index a36d427b8c..ea9faba214 100644 --- a/mmedit/datasets/pipelines/augmentation.py +++ b/mmedit/datasets/pipelines/augmentation.py @@ -1,7 +1,6 @@ import math import numbers import os.path as osp -import random import cv2 import mmcv @@ -611,7 +610,7 @@ def __init__(self, keys, binary_thr=0., kernel_min=9, kernel_max=49): self.binary_thr = binary_thr def _random_dilate(self, img): - kernel_size = random.randint(self.kernel_min, self.kernel_max) + kernel_size = np.random.randint(self.kernel_min, self.kernel_max + 1) kernel = np.ones((kernel_size, kernel_size), dtype=np.uint8) dilate_kernel_size = kernel_size img_ = cv2.dilate(img, kernel, iterations=1) diff --git a/mmedit/datasets/pipelines/crop.py b/mmedit/datasets/pipelines/crop.py index c7f0520700..df4443f6f7 100644 --- a/mmedit/datasets/pipelines/crop.py +++ b/mmedit/datasets/pipelines/crop.py @@ -1,5 +1,3 @@ -import random - import mmcv import numpy as np from torch.nn.modules.utils import _pair @@ -214,8 +212,8 @@ def __call__(self, results): f'{results["lq_path"][0]} and {results["gt_path"][0]}.') # randomly choose top and left coordinates for lq patch - top = random.randint(0, h_lq - lq_patch_size) - left = random.randint(0, w_lq - lq_patch_size) + top = np.random.randint(h_lq - lq_patch_size + 1) + left = np.random.randint(w_lq - lq_patch_size + 1) # crop lq patch results['lq'] = [ v[top:top + lq_patch_size, left:left + lq_patch_size, ...]