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

TypeError: expected string or bytes-like object #5374

Closed
wennycooper opened this issue Oct 28, 2021 · 5 comments · Fixed by #5592 or #5616
Closed

TypeError: expected string or bytes-like object #5374

wennycooper opened this issue Oct 28, 2021 · 5 comments · Fixed by #5592 or #5616
Labels
bug Something isn't working

Comments

@wennycooper
Copy link

  • Current repo: run git fetch && git status -uno to check and git pull to update repo
  • Common dataset: coco128.yaml
  • Common environment: Docker image

🐛 Bug

A clear and concise description of what the bug is.

To Reproduce (REQUIRED)

Input:

# python train.py --img 640 --batch 16 --epochs 5 --data coco128.yaml --weights yolov5s.pt

Output:

Downloading https://ultralytics.com/assets/Arial.ttf to Arial.ttf...
Traceback (most recent call last):
  File "/workspace/folder/yolov5/utils/plots.py", line 56, in check_font
    return ImageFont.truetype(str(font) if font.exists() else font.name, size)
  File "/opt/conda/lib/python3.8/site-packages/PIL/ImageFont.py", line 853, in truetype
    return freetype(font)
  File "/opt/conda/lib/python3.8/site-packages/PIL/ImageFont.py", line 850, in freetype
    return FreeTypeFont(font, size, index, encoding, layout_engine)
  File "/opt/conda/lib/python3.8/site-packages/PIL/ImageFont.py", line 173, in __init__
    freetype_version = parse_version(features.version_module("freetype2"))
  File "/opt/conda/lib/python3.8/site-packages/packaging/version.py", line 49, in parse
    return Version(version)
  File "/opt/conda/lib/python3.8/site-packages/packaging/version.py", line 264, in __init__
    match = self._regex.search(version)
TypeError: expected string or bytes-like object

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "train.py", line 35, in <module>
    import val  # for end-of-epoch mAP
  File "/workspace/folder/yolov5/val.py", line 26, in <module>
    from models.experimental import attempt_load
  File "/workspace/folder/yolov5/models/experimental.py", line 10, in <module>
    from models.common import Conv
  File "/workspace/folder/yolov5/models/common.py", line 23, in <module>
    from utils.plots import Annotator, colors
  File "/workspace/folder/yolov5/utils/plots.py", line 64, in <module>
    class Annotator:
  File "/workspace/folder/yolov5/utils/plots.py", line 66, in Annotator
    check_font()  # download TTF if necessary
  File "/workspace/folder/yolov5/utils/plots.py", line 61, in check_font
    return ImageFont.truetype(str(font), size)
  File "/opt/conda/lib/python3.8/site-packages/PIL/ImageFont.py", line 853, in truetype
    return freetype(font)
  File "/opt/conda/lib/python3.8/site-packages/PIL/ImageFont.py", line 850, in freetype
    return FreeTypeFont(font, size, index, encoding, layout_engine)
  File "/opt/conda/lib/python3.8/site-packages/PIL/ImageFont.py", line 173, in __init__
    freetype_version = parse_version(features.version_module("freetype2"))
  File "/opt/conda/lib/python3.8/site-packages/packaging/version.py", line 49, in parse
    return Version(version)
  File "/opt/conda/lib/python3.8/site-packages/packaging/version.py", line 264, in __init__
    match = self._regex.search(version)
TypeError: expected string or bytes-like object

Expected behavior

Expected to start training

Environment

  • OS: Ubuntu 18.04
  • GPU: RTX 3060
@wennycooper wennycooper added the bug Something isn't working label Oct 28, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Oct 28, 2021

👋 Hello @wennycooper, 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

@wennycooper you've got an environment error caused by PIL. Can you put a breakpoint in here to see what is being passed to ImageFont.truetype() in utils/plots.py", line 56?

    return ImageFont.truetype(str(font) if font.exists() else font.name, size)

@wennycooper
Copy link
Author

Sorry that I've reinstalled the environment and the problem was gone.
I will close this issue. Thanks!

@rambles-tech
Copy link

rambles-tech commented Nov 10, 2021

I also had this issue. I was able to resolve it by uninstalling and then reinstalling pillow:
pip3 uninstall -y pillow
pip3 install pillow

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

@wennycooper @rambles-tech good news 😃! Your original issue may now be fixed ✅ in PR #5592. This PR updates the Docker base image to 21.10 and also updates PIL, which was the root cause of this bug.

To receive this update:

  • Gitgit pull from within your yolov5/ directory or git clone https://github.com/ultralytics/yolov5 again
  • PyTorch Hub – Force-reload 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 added a commit that referenced this issue Nov 11, 2021
@glenn-jocher glenn-jocher linked a pull request Nov 11, 2021 that will close this issue
glenn-jocher added a commit that referenced this issue Nov 11, 2021
* Improve plots.py robustness

Addresses issues #5374, #5395, #5611

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
BjarneKuehl pushed a commit to fhkiel-mlaip/yolov5 that referenced this issue Aug 26, 2022
* Improve plots.py robustness

Addresses issues ultralytics#5374, ultralytics#5395, ultralytics#5611

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants