From 91e3b7818f254cc3e29c06c31afb54388d451850 Mon Sep 17 00:00:00 2001 From: Bubbliiiing <47347516+bubbliiiing@users.noreply.github.com> Date: Sun, 26 Jul 2020 21:07:38 +0800 Subject: [PATCH] Update dataloader.py --- utils/dataloader.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/utils/dataloader.py b/utils/dataloader.py index f23ee11..a663645 100644 --- a/utils/dataloader.py +++ b/utils/dataloader.py @@ -3,6 +3,7 @@ import numpy as np import torch import torch.nn as nn import math +import cv2 import torch.nn.functional as F from PIL import Image from torch.autograd import Variable @@ -61,15 +62,16 @@ class SSDDataset(Dataset): hue = self.rand(-hue, hue) sat = self.rand(1, sat) if self.rand() < .5 else 1 / self.rand(1, sat) val = self.rand(1, val) if self.rand() < .5 else 1 / self.rand(1, val) - x = rgb_to_hsv(np.array(image) / 255.) - x[..., 0] += hue - x[..., 0][x[..., 0] > 1] -= 1 - x[..., 0][x[..., 0] < 0] += 1 + x = cv2.cvtColor(np.array(image,np.float32)/255, cv2.COLOR_RGB2HSV) + x[..., 0] += hue*360 + x[..., 0][x[..., 0]>1] -= 1 + x[..., 0][x[..., 0]<0] += 1 x[..., 1] *= sat x[..., 2] *= val - x[x > 1] = 1 - x[x < 0] = 0 - image_data = hsv_to_rgb(x) * 255 # numpy array, 0 to 1 + x[x[:,:, 0]>360, 0] = 360 + x[:, :, 1:][x[:, :, 1:]>1] = 1 + x[x<0] = 0 + image_data = cv2.cvtColor(x, cv2.COLOR_HSV2RGB)*255 # 调整目标框坐标 box_data = np.zeros((len(box), 5)) -- GitLab