提交 b3ee8133 编写于 作者: M minqiyang

Port np.randint to random.randint

上级 8067fd17
......@@ -37,8 +37,8 @@ def crop_image(img, target_size, center):
w_start = (width - size) / 2
h_start = (height - size) / 2
else:
w_start = np.random.randint(0, width - size)
h_start = np.random.randint(0, height - size)
w_start = np.random.randint(0, width - size + 1)
h_start = np.random.randint(0, height - size + 1)
w_end = w_start + size
h_end = h_start + size
img = img.crop((w_start, h_start, w_end, h_end))
......@@ -61,8 +61,8 @@ def random_crop(img, size, scale=[0.08, 1.0], ratio=[3. / 4., 4. / 3.]):
w = int(target_size * w)
h = int(target_size * h)
i = np.random.randint(0, img.size[0] - w)
j = np.random.randint(0, img.size[1] - h)
i = np.random.randint(0, img.size[0] - w + 1)
j = np.random.randint(0, img.size[1] - h + 1)
img = img.crop((i, j, i + w, j + h))
img = img.resize((size, size), Image.LANCZOS)
......@@ -70,7 +70,7 @@ def random_crop(img, size, scale=[0.08, 1.0], ratio=[3. / 4., 4. / 3.]):
def rotate_image(img):
angle = np.random.randint(-10, 10)
angle = np.random.randint(-10, 11)
img = img.rotate(angle)
return img
......@@ -111,7 +111,7 @@ def process_image(sample, mode, color_jitter, rotate):
if mode == 'train':
if color_jitter:
img = distort_color(img)
if np.random.randint(0, 1) == 1:
if np.random.randint(0, 2) == 1:
img = img.transpose(Image.FLIP_LEFT_RIGHT)
if img.mode != 'RGB':
......
......@@ -207,15 +207,15 @@ def distort_image(img, settings):
prob = np.random.uniform(0, 1)
# Apply different distort order
if prob > 0.5:
img = np.random_brightness(img, settings)
img = np.random_contrast(img, settings)
img = np.random_saturation(img, settings)
img = np.random_hue(img, settings)
img = random_brightness(img, settings)
img = random_contrast(img, settings)
img = random_saturation(img, settings)
img = random_hue(img, settings)
else:
img = np.random_brightness(img, settings)
img = np.random_saturation(img, settings)
img = np.random_hue(img, settings)
img = np.random_contrast(img, settings)
img = random_brightness(img, settings)
img = random_saturation(img, settings)
img = random_hue(img, settings)
img = random_contrast(img, settings)
return img
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册