`np.fromfile()` Chinese image paths fix (#6979)
Browse files* :tada: :new: now can read Chinese image path.
use "cv2.imdecode(np.fromfile(f, np.uint8), cv2.IMREAD_COLOR)" instead of "cv2.imread(f)" for Chinese image path.
* Update datasets.py
* Update __init__.py
Co-authored-by: Glenn Jocher <[email protected]>
- utils/datasets.py +3 -0
- utils/loggers/__init__.py +3 -0
utils/datasets.py
CHANGED
@@ -32,6 +32,9 @@ from utils.general import (DATASETS_DIR, LOGGER, NUM_THREADS, check_dataset, che
|
|
32 |
segments2boxes, xyn2xy, xywh2xyxy, xywhn2xyxy, xyxy2xywhn)
|
33 |
from utils.torch_utils import torch_distributed_zero_first
|
34 |
|
|
|
|
|
|
|
35 |
# Parameters
|
36 |
HELP_URL = 'https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data'
|
37 |
IMG_FORMATS = 'bmp', 'dng', 'jpeg', 'jpg', 'mpo', 'png', 'tif', 'tiff', 'webp' # include image suffixes
|
|
|
32 |
segments2boxes, xyn2xy, xywh2xyxy, xywhn2xyxy, xyxy2xywhn)
|
33 |
from utils.torch_utils import torch_distributed_zero_first
|
34 |
|
35 |
+
# Remap
|
36 |
+
cv2.imread = lambda x: cv2.imdecode(np.fromfile(x, np.uint8), cv2.IMREAD_COLOR) # for Chinese filenames
|
37 |
+
|
38 |
# Parameters
|
39 |
HELP_URL = 'https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data'
|
40 |
IMG_FORMATS = 'bmp', 'dng', 'jpeg', 'jpg', 'mpo', 'png', 'tif', 'tiff', 'webp' # include image suffixes
|
utils/loggers/__init__.py
CHANGED
@@ -148,6 +148,9 @@ class Loggers():
|
|
148 |
|
149 |
if self.tb:
|
150 |
import cv2
|
|
|
|
|
|
|
151 |
for f in files:
|
152 |
self.tb.add_image(f.stem, cv2.imread(str(f))[..., ::-1], epoch, dataformats='HWC')
|
153 |
|
|
|
148 |
|
149 |
if self.tb:
|
150 |
import cv2
|
151 |
+
import numpy as np
|
152 |
+
|
153 |
+
cv2.imread = lambda x: cv2.imdecode(np.fromfile(x, np.uint8), cv2.IMREAD_COLOR) # remap for Chinese files
|
154 |
for f in files:
|
155 |
self.tb.add_image(f.stem, cv2.imread(str(f))[..., ::-1], epoch, dataformats='HWC')
|
156 |
|