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

Annotator check_font() RANK -1 remove progress #4864

Merged
merged 2 commits into from
Sep 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions utils/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
Plotting utils
"""

import math
import os
from copy import copy
from pathlib import Path

import cv2
import math
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
Expand All @@ -21,6 +22,7 @@

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

Expand Down Expand Up @@ -55,12 +57,13 @@ def check_font(font='Arial.ttf', size=10):
except Exception as e: # download if missing
url = "https://ultralytics.com/assets/" + font.name
print(f'Downloading {url} to {font}...')
torch.hub.download_url_to_file(url, str(font))
torch.hub.download_url_to_file(url, str(font), progress=False)
return ImageFont.truetype(str(font), size)


class Annotator:
check_font() # download TTF if necessary
if RANK in (-1, 0):
check_font() # download TTF if necessary

# YOLOv5 Annotator for train/val mosaics and jpgs and detect/hub inference annotations
def __init__(self, im, line_width=None, font_size=None, font='Arial.ttf', pil=True):
Expand Down