Browse Source

Add histogram equalization fcn (#2049)

5.0
Glenn Jocher GitHub 3 years ago
parent
commit
08d3119e09
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 7 deletions
  1. +2
    -2
      Dockerfile
  2. +1
    -1
      models/yolo.py
  3. +10
    -4
      utils/datasets.py

+ 2
- 2
Dockerfile View File

# sudo docker kill $(sudo docker ps -q) # sudo docker kill $(sudo docker ps -q)


# Kill all image-based # Kill all image-based
# sudo docker kill $(sudo docker ps -a -q --filter ancestor=ultralytics/yolov5:latest)
# sudo docker kill $(sudo docker ps -qa --filter ancestor=ultralytics/yolov5:latest)


# Bash into running container # Bash into running container
# sudo docker exec -it 5a9b5863d93d bash # sudo docker exec -it 5a9b5863d93d bash


# Bash into stopped container # Bash into stopped container
# id=5a9b5863d93d && sudo docker start $id && sudo docker exec -it $id bash
# id=$(sudo docker ps -qa) && sudo docker start $id && sudo docker exec -it $id bash


# Send weights to GCP # Send weights to GCP
# python -c "from utils.general import *; strip_optimizer('runs/train/exp0_*/weights/best.pt', 'tmp.pt')" && gsutil cp tmp.pt gs://*.pt # python -c "from utils.general import *; strip_optimizer('runs/train/exp0_*/weights/best.pt', 'tmp.pt')" && gsutil cp tmp.pt gs://*.pt

+ 1
- 1
models/yolo.py View File

for si, fi in zip(s, f): for si, fi in zip(s, f):
xi = scale_img(x.flip(fi) if fi else x, si, gs=int(self.stride.max())) xi = scale_img(x.flip(fi) if fi else x, si, gs=int(self.stride.max()))
yi = self.forward_once(xi)[0] # forward yi = self.forward_once(xi)[0] # forward
# cv2.imwrite('img%g.jpg' % s, 255 * xi[0].numpy().transpose((1, 2, 0))[:, :, ::-1]) # save
# cv2.imwrite(f'img_{si}.jpg', 255 * xi[0].cpu().numpy().transpose((1, 2, 0))[:, :, ::-1]) # save
yi[..., :4] /= si # de-scale yi[..., :4] /= si # de-scale
if fi == 2: if fi == 2:
yi[..., 1] = img_size[0] - yi[..., 1] # de-flip ud yi[..., 1] = img_size[0] - yi[..., 1] # de-flip ud

+ 10
- 4
utils/datasets.py View File

img_hsv = cv2.merge((cv2.LUT(hue, lut_hue), cv2.LUT(sat, lut_sat), cv2.LUT(val, lut_val))).astype(dtype) img_hsv = cv2.merge((cv2.LUT(hue, lut_hue), cv2.LUT(sat, lut_sat), cv2.LUT(val, lut_val))).astype(dtype)
cv2.cvtColor(img_hsv, cv2.COLOR_HSV2BGR, dst=img) # no return needed cv2.cvtColor(img_hsv, cv2.COLOR_HSV2BGR, dst=img) # no return needed


# Histogram equalization
# if random.random() < 0.2:
# for i in range(3):
# img[:, :, i] = cv2.equalizeHist(img[:, :, i])

def hist_equalize(img, clahe=True, bgr=False):
# Equalize histogram on BGR image 'img' with img.shape(n,m,3) and range 0-255
yuv = cv2.cvtColor(img, cv2.COLOR_BGR2YUV if bgr else cv2.COLOR_RGB2YUV)
if clahe:
c = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
yuv[:, :, 0] = c.apply(yuv[:, :, 0])
else:
yuv[:, :, 0] = cv2.equalizeHist(yuv[:, :, 0]) # equalize Y channel histogram
return cv2.cvtColor(yuv, cv2.COLOR_YUV2BGR if bgr else cv2.COLOR_YUV2RGB) # convert YUV image to RGB




def load_mosaic(self, index): def load_mosaic(self, index):

Loading…
Cancel
Save