Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
HTRT opened this issue Sep 27, 2021 · 6 comments · Fixed by #4951
Closed

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

HTRT opened this issue Sep 27, 2021 · 6 comments · Fixed by #4951
Labels
question Further information is requested

Comments

@HTRT
Copy link

HTRT commented Sep 27, 2021

❔Question

Additional context

@HTRT HTRT added the question Further information is requested label Sep 27, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Sep 27, 2021

👋 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
Copy link
Member

@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
Copy link
Member

TODO: implement Arial Unicode automatically for Chinese characters.

@glenn-jocher glenn-jocher linked a pull request Sep 27, 2021 that will close this issue
@glenn-jocher
Copy link
Member

@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:

  • Gitgit pull from within your yolov5/ directory or git clone https://github.com/ultralytics/yolov5 again
  • PyTorch Hub – Force-reload with model = torch.hub.load('ultralytics/yolov5', 'yolov5s', force_reload=True)
  • Notebooks – View updated notebooks Open In Colab Open In Kaggle
  • Dockersudo docker pull ultralytics/yolov5:latest to update your image Docker Pulls

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 🚀!

@glenn-jocher glenn-jocher removed the TODO label Sep 27, 2021
@lonngxiang
Copy link

how to let predict labels display other languages?

@glenn-jocher
Copy link
Member

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants