Browse Source

clean_str() function addition (#1674)

* clean_str() function addition

* cleanup

* add euro symbol €

* add closing exclamation (spanish)

* cleanup
5.0
Glenn Jocher GitHub 3 years ago
parent
commit
d5289b54c4
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 7 deletions
  1. +5
    -4
      detect.py
  2. +2
    -2
      utils/datasets.py
  3. +6
    -1
      utils/general.py

+ 5
- 4
detect.py View File

# Process detections # Process detections
for i, det in enumerate(pred): # detections per image for i, det in enumerate(pred): # detections per image
if webcam: # batch_size >= 1 if webcam: # batch_size >= 1
p, s, im0, frame = Path(path[i]), '%g: ' % i, im0s[i].copy(), dataset.count
p, s, im0, frame = path[i], '%g: ' % i, im0s[i].copy(), dataset.count
else: else:
p, s, im0, frame = Path(path), '', im0s, getattr(dataset, 'frame', 0)
p, s, im0, frame = path, '', im0s, getattr(dataset, 'frame', 0)


save_path = str(save_dir / p.name)
txt_path = str(save_dir / 'labels' / p.stem) + ('' if dataset.mode == 'image' else f'_{frame}')
p = Path(p) # to Path
save_path = str(save_dir / p.name) # img.jpg
txt_path = str(save_dir / 'labels' / p.stem) + ('' if dataset.mode == 'image' else f'_{frame}') # img.txt
s += '%gx%g ' % img.shape[2:] # print string s += '%gx%g ' % img.shape[2:] # print string
gn = torch.tensor(im0.shape)[[1, 0, 1, 0]] # normalization gain whwh gn = torch.tensor(im0.shape)[[1, 0, 1, 0]] # normalization gain whwh
if len(det): if len(det):

+ 2
- 2
utils/datasets.py View File

from torch.utils.data import Dataset from torch.utils.data import Dataset
from tqdm import tqdm from tqdm import tqdm


from utils.general import xyxy2xywh, xywh2xyxy
from utils.general import xyxy2xywh, xywh2xyxy, clean_str
from utils.torch_utils import torch_distributed_zero_first from utils.torch_utils import torch_distributed_zero_first


# Parameters # Parameters


n = len(sources) n = len(sources)
self.imgs = [None] * n self.imgs = [None] * n
self.sources = sources
self.sources = [clean_str(x) for x in sources] # clean source names for later
for i, s in enumerate(sources): for i, s in enumerate(sources):
# Start the thread to read frames from the video stream # Start the thread to read frames from the video stream
print('%g/%g: %s... ' % (i + 1, n, s), end='') print('%g/%g: %s... ' % (i + 1, n, s), end='')

+ 6
- 1
utils/general.py View File



import glob import glob
import logging import logging
import math
import os import os
import platform import platform
import random import random
from pathlib import Path from pathlib import Path


import cv2 import cv2
import math
import numpy as np import numpy as np
import torch import torch
import torchvision import torchvision
return math.ceil(x / divisor) * divisor return math.ceil(x / divisor) * divisor




def clean_str(s):
# Cleans a string by replacing special characters with underscore _
return re.sub(pattern="[|@#!¡·$€%&()=?¿^*;:,¨´><+]", repl="_", string=s)


def labels_to_class_weights(labels, nc=80): def labels_to_class_weights(labels, nc=80):
# Get class weights (inverse frequency) from training labels # Get class weights (inverse frequency) from training labels
if labels[0] is None: # no labels loaded if labels[0] is None: # no labels loaded

Loading…
Cancel
Save