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

got missing from current font warning when train Chinese names images #6522

Closed
1 of 2 tasks
gaoyanzeng opened this issue Feb 3, 2022 · 19 comments · Fixed by #6526
Closed
1 of 2 tasks

got missing from current font warning when train Chinese names images #6522

gaoyanzeng opened this issue Feb 3, 2022 · 19 comments · Fixed by #6526
Labels
bug Something isn't working Stale Stale and schedule for closing soon

Comments

@gaoyanzeng
Copy link

Search before asking

  • I have searched the YOLOv5 issues and found no similar bug report.

YOLOv5 Component

Training

Bug

Got warning as below:
metrics.py:199: UserWarning: Glyph 31888 (\N{CJK UNIFIED IDEOGRAPH-7C90}) missing from current font.
fig.savefig(Path(save_dir) / 'confusion_matrix.png', dpi=250)

All I changed is in the ./data/coco128.yaml as below:

Classes

nc: 4 # number of classes
names: ['翘头剪', '直剪', '止血钳', '组织钳'] # class names

Environment

OS: Windows 11
Python: 3.9.5

Minimal Reproducible Example

No response

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@gaoyanzeng gaoyanzeng added the bug Something isn't working label Feb 3, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Feb 3, 2022

👋 Hello @gaoyanzeng, 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 [email protected].

Requirements

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

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

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

@gaoyanzeng warnings are not errors and can be safely ignored if they do not impact performance. Does this cause any problems in your workflow?

@glenn-jocher
Copy link
Member

@gaoyanzeng I investigated a bit, seems like Unicode Arial.ttf is not downloading as it should for Chinese fonts usage. I'll add a TODO to investigate further.

@glenn-jocher glenn-jocher added the TODO High priority items label Feb 3, 2022
@glenn-jocher
Copy link
Member

Screenshot 2022-02-03 at 12 31 08

@gaoyanzeng
Copy link
Author

thank you very much

@gaoyanzeng
Copy link
Author

It can't plot chinese correctly when use "fig.savefig(Path(save_dir) / 'confusion_matrix.png', dpi=250)" in the 191 line of utils/metrics.py
图片

@glenn-jocher glenn-jocher linked a pull request Feb 3, 2022 that will close this issue
@glenn-jocher
Copy link
Member

@gaoyanzeng yeah I see that. It looks like PIL image plotting with Chinese fonts is working correctly now after some updates in #6526 but matplotlib plotting is separate and needs to specify Arial.Unicode.tty as well. I should have a fix for this soon.

@glenn-jocher
Copy link
Member

TODO: Fix matplotlib plots for Chinese characters

@gaoyanzeng
Copy link
Author

Thank you very much, looking forward to your work fix this problem.

@gaoyanzeng
Copy link
Author

It draw correctly in other *.py file without font settings of matplotlib. But can't savefig correctly with Chinese labels int the metrics.py
image

@gaoyanzeng
Copy link
Author

I found that when I set the matplotlib 'font.sans-serif', the font missing warnning disappeared. But the labels still messy in the result images.
图片

And the model summary's class name is messy. May be the chinese labels are not encoded correctly
图片

@glenn-jocher
Copy link
Member

@gaoyanzeng can you paste the code for your reproducible matplotlib Chinese plotting example?

Maybe the YOLOv5 matplotlib settings here are affecting the Chinese characters:

yolov5/utils/plots.py

Lines 24 to 28 in 079b36d

# Settings
RANK = int(os.getenv('RANK', -1))
matplotlib.rc('font', **{'size': 11})
matplotlib.use('Agg') # for writing to files only

@gaoyanzeng
Copy link
Author

I mean when print the result before the matplotlib is not correcttly. As below
image

@glenn-jocher
Copy link
Member

It draw correctly in other *.py file without font settings of matplotlib. But can't savefig correctly with Chinese labels int the metrics.py image

Yes but can you send the the main.py script you show above please? Thanks!

@glenn-jocher
Copy link
Member

@gaoyanzeng about the indentation issues maybe if we place this data into a pandas dataframe and then print() it pandas might resolve the indentation issues. Right now the printing is done manually here:

yolov5/val.py

Lines 261 to 269 in e1a6a0b

# Print results
pf = '%20s' + '%11i' * 2 + '%11.3g' * 4 # print format
LOGGER.info(pf % ('all', seen, nt.sum(), mp, mr, map50, map))
# Print results per class
if (verbose or (nc < 50 and not training)) and nc > 1 and len(stats):
for i, c in enumerate(ap_class):
LOGGER.info(pf % (names[c], seen, nt[c], p[i], r[i], ap50[i], ap[i]))

@gaoyanzeng
Copy link
Author

@glenn-jocher Maybe, It load the *.yaml file imcorrectly when there are chinese characters in the *.yaml file?

@gaoyanzeng
Copy link
Author

When I set chinese classes names in the coco128.yaml, then load the file should set the encoding tobe UTF-8,
image
Then, the chinese classes names be right.
image
Thank you very much. @glenn-jocher

@glenn-jocher glenn-jocher removed the TODO High priority items label Apr 26, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Jun 1, 2022

👋 Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs.

Access additional YOLOv5 🚀 resources:

Access additional Ultralytics ⚡ resources:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLOv5 🚀 and Vision AI ⭐!

@github-actions github-actions bot added the Stale Stale and schedule for closing soon label Jun 1, 2022
@github-actions github-actions bot closed this as completed Jun 7, 2022
@glenn-jocher
Copy link
Member

You're welcome, @gaoyanzeng! It's great to hear that setting the encoding to UTF-8 worked for you. Let me know if there's anything else I can assist you with. Have a great day!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Stale Stale and schedule for closing soon
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants