clean_str() function addition (#1674)
Browse files* clean_str() function addition
* cleanup
* add euro symbol €
* add closing exclamation (spanish)
* cleanup
- detect.py +5 -4
- utils/datasets.py +2 -2
- utils/general.py +6 -1
detect.py
CHANGED
@@ -81,12 +81,13 @@ def detect(save_img=False):
|
|
81 |
# Process detections
|
82 |
for i, det in enumerate(pred): # detections per image
|
83 |
if webcam: # batch_size >= 1
|
84 |
-
p, s, im0, frame =
|
85 |
else:
|
86 |
-
p, s, im0, frame =
|
87 |
|
88 |
-
|
89 |
-
|
|
|
90 |
s += '%gx%g ' % img.shape[2:] # print string
|
91 |
gn = torch.tensor(im0.shape)[[1, 0, 1, 0]] # normalization gain whwh
|
92 |
if len(det):
|
|
|
81 |
# Process detections
|
82 |
for i, det in enumerate(pred): # detections per image
|
83 |
if webcam: # batch_size >= 1
|
84 |
+
p, s, im0, frame = path[i], '%g: ' % i, im0s[i].copy(), dataset.count
|
85 |
else:
|
86 |
+
p, s, im0, frame = path, '', im0s, getattr(dataset, 'frame', 0)
|
87 |
|
88 |
+
p = Path(p) # to Path
|
89 |
+
save_path = str(save_dir / p.name) # img.jpg
|
90 |
+
txt_path = str(save_dir / 'labels' / p.stem) + ('' if dataset.mode == 'image' else f'_{frame}') # img.txt
|
91 |
s += '%gx%g ' % img.shape[2:] # print string
|
92 |
gn = torch.tensor(im0.shape)[[1, 0, 1, 0]] # normalization gain whwh
|
93 |
if len(det):
|
utils/datasets.py
CHANGED
@@ -19,7 +19,7 @@ from PIL import Image, ExifTags
|
|
19 |
from torch.utils.data import Dataset
|
20 |
from tqdm import tqdm
|
21 |
|
22 |
-
from utils.general import xyxy2xywh, xywh2xyxy
|
23 |
from utils.torch_utils import torch_distributed_zero_first
|
24 |
|
25 |
# Parameters
|
@@ -267,7 +267,7 @@ class LoadStreams: # multiple IP or RTSP cameras
|
|
267 |
|
268 |
n = len(sources)
|
269 |
self.imgs = [None] * n
|
270 |
-
self.sources = sources
|
271 |
for i, s in enumerate(sources):
|
272 |
# Start the thread to read frames from the video stream
|
273 |
print('%g/%g: %s... ' % (i + 1, n, s), end='')
|
|
|
19 |
from torch.utils.data import Dataset
|
20 |
from tqdm import tqdm
|
21 |
|
22 |
+
from utils.general import xyxy2xywh, xywh2xyxy, clean_str
|
23 |
from utils.torch_utils import torch_distributed_zero_first
|
24 |
|
25 |
# Parameters
|
|
|
267 |
|
268 |
n = len(sources)
|
269 |
self.imgs = [None] * n
|
270 |
+
self.sources = [clean_str(x) for x in sources] # clean source names for later
|
271 |
for i, s in enumerate(sources):
|
272 |
# Start the thread to read frames from the video stream
|
273 |
print('%g/%g: %s... ' % (i + 1, n, s), end='')
|
utils/general.py
CHANGED
@@ -2,6 +2,7 @@
|
|
2 |
|
3 |
import glob
|
4 |
import logging
|
|
|
5 |
import os
|
6 |
import platform
|
7 |
import random
|
@@ -11,7 +12,6 @@ import time
|
|
11 |
from pathlib import Path
|
12 |
|
13 |
import cv2
|
14 |
-
import math
|
15 |
import numpy as np
|
16 |
import torch
|
17 |
import torchvision
|
@@ -97,6 +97,11 @@ def make_divisible(x, divisor):
|
|
97 |
return math.ceil(x / divisor) * divisor
|
98 |
|
99 |
|
|
|
|
|
|
|
|
|
|
|
100 |
def labels_to_class_weights(labels, nc=80):
|
101 |
# Get class weights (inverse frequency) from training labels
|
102 |
if labels[0] is None: # no labels loaded
|
|
|
2 |
|
3 |
import glob
|
4 |
import logging
|
5 |
+
import math
|
6 |
import os
|
7 |
import platform
|
8 |
import random
|
|
|
12 |
from pathlib import Path
|
13 |
|
14 |
import cv2
|
|
|
15 |
import numpy as np
|
16 |
import torch
|
17 |
import torchvision
|
|
|
97 |
return math.ceil(x / divisor) * divisor
|
98 |
|
99 |
|
100 |
+
def clean_str(s):
|
101 |
+
# Cleans a string by replacing special characters with underscore _
|
102 |
+
return re.sub(pattern="[|@#!¡·$€%&()=?¿^*;:,¨´><+]", repl="_", string=s)
|
103 |
+
|
104 |
+
|
105 |
def labels_to_class_weights(labels, nc=80):
|
106 |
# Get class weights (inverse frequency) from training labels
|
107 |
if labels[0] is None: # no labels loaded
|