ultralytics / yolov5

YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
51.38k stars 16.47k forks source link

How to display the Chinese label on th detetion box? #4947

Closed HTRT closed 3 years ago

HTRT commented 3 years ago

❔Question

Additional context

github-actions[bot] commented 3 years ago

👋 Hello @HTRT, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://ultralytics.com or email Glenn Jocher at glenn.jocher@ultralytics.com.

Requirements

Python>=3.6.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

$ git clone https://github.com/ultralytics/yolov5
$ cd yolov5
$ pip install -r requirements.txt

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

CI CPU testing

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), validation (val.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.

glenn-jocher commented 3 years ago

@HTRT Arial Unicode should be used, but we should do this automatically. I'll queue this as a TODO.

/Users/glennjocher/PycharmProjects/yolov5/venv/bin/python /Users/glennjocher/PycharmProjects/yolov5/detect.py

Downloading https://ultralytics.com/assets/Arial.Unicode.ttf to /Users/glennjocher/Library/Application Support/Ultralytics/Arial.Unicode.ttf...

detect: weights=yolov5s.pt, source=data/images, imgsz=[640, 640], conf_thres=0.25, iou_thres=0.45, max_det=1000, device=, view_img=False, save_txt=False, save_conf=False, save_crop=False, nosave=False, classes=None, agnostic_nms=False, augment=False, visualize=False, update=False, project=runs/detect, name=exp, exist_ok=False, line_thickness=3, hide_labels=False, hide_conf=False, half=False
YOLOv5 🚀 v5.0-466-gc5ba2ab torch 1.9.1 CPU

Fusing layers... 
Model Summary: 224 layers, 7266973 parameters, 0 gradients
image 1/2 /Users/glennjocher/PycharmProjects/yolov5/data/images/bus.jpg: 640x480 4 欧洲和西班牙s, 1 bus, 1 fire hydrant, Done. (0.193s)
image 2/2 /Users/glennjocher/PycharmProjects/yolov5/data/images/zidane.jpg: 384x640 2 欧洲和西班牙s, 2 ties, Done. (0.152s)
Speed: 1.1ms pre-process, 172.8ms inference, 1.0ms NMS per image at shape (1, 3, 640, 640)
Results saved to runs/detect/exp3

zidane

glenn-jocher commented 3 years ago

TODO: implement Arial Unicode automatically for Chinese characters.

glenn-jocher commented 3 years ago

@HTRT good news 😃! Your original issue may now be fixed ✅ in PR #4951. This PR enables plotting images with Chinese characters. Fonts are downloaded automatically, no action required on your part other than to update your code. You do not need to retrain any models.

To receive this update:

Thank you for spotting this issue and informing us of the problem. Please let us know if this update resolves the issue for you, and feel free to inform us of any other issues you discover or feature requests that come to mind. Happy trainings with YOLOv5 🚀!

lonngxiang commented 1 year ago

how to let predict labels display other languages?

glenn-jocher commented 1 year ago

@lonngxiang You can display labels in other languages by setting the font for the annotation using Pillow (PIL). Try the following code to display Chinese labels:

from PIL import Image, ImageDraw, ImageFont

# Open image
img = Image.open('path_to_image.jpg')

# Define the font (Arial Unicode MS supports many languages, including Chinese)
font = ImageFont.truetype("path_to_Arial_Unicode.ttf", 50)

# Draw label
draw = ImageDraw.Draw(img)
draw.text((10, 10), "你好", font=font)  # Draw Chinese label at position (10, 10)

# Save or display the annotated image
img.save('output.jpg')
img.show()

Be sure to replace 'path_to_image.jpg' and 'path_to_Arial_Unicode.ttf' with your file paths.

More details on using fonts with PIL can be found in the Pillow documentation.

Let us know if you encounter any issues or have further questions!