Skip to content

Commit

Permalink
np.fromfile() Chinese image paths fix (ultralytics#6979)
Browse files Browse the repository at this point in the history
* 🎉 🆕 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]>
  • Loading branch information
yeshanliu and glenn-jocher authored Mar 23, 2022
1 parent e08005c commit 99eeef0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions utils/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
segments2boxes, xyn2xy, xywh2xyxy, xywhn2xyxy, xyxy2xywhn)
from utils.torch_utils import torch_distributed_zero_first

# Remap
cv2.imread = lambda x: cv2.imdecode(np.fromfile(x, np.uint8), cv2.IMREAD_COLOR) # for Chinese filenames

# Parameters
HELP_URL = 'https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data'
IMG_FORMATS = 'bmp', 'dng', 'jpeg', 'jpg', 'mpo', 'png', 'tif', 'tiff', 'webp' # include image suffixes
Expand Down
3 changes: 3 additions & 0 deletions utils/loggers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ def on_train_end(self, last, best, plots, epoch, results):

if self.tb:
import cv2
import numpy as np

cv2.imread = lambda x: cv2.imdecode(np.fromfile(x, np.uint8), cv2.IMREAD_COLOR) # remap for Chinese files
for f in files:
self.tb.add_image(f.stem, cv2.imread(str(f))[..., ::-1], epoch, dataformats='HWC')

Expand Down

0 comments on commit 99eeef0

Please sign in to comment.