glenn-jocher commited on
Commit
8ad9e4e
·
unverified ·
1 Parent(s): 2b3109e

Annotator `check_font()` RANK -1 remove progress (#4864)

Browse files

* Annotator `check_font()` RANK -1 remove progress

* Cleanup

Files changed (1) hide show
  1. utils/plots.py +6 -3
utils/plots.py CHANGED
@@ -3,11 +3,12 @@
3
  Plotting utils
4
  """
5
 
 
 
6
  from copy import copy
7
  from pathlib import Path
8
 
9
  import cv2
10
- import math
11
  import matplotlib
12
  import matplotlib.pyplot as plt
13
  import numpy as np
@@ -21,6 +22,7 @@ from utils.metrics import fitness
21
 
22
  # Settings
23
  CONFIG_DIR = user_config_dir() # Ultralytics settings dir
 
24
  matplotlib.rc('font', **{'size': 11})
25
  matplotlib.use('Agg') # for writing to files only
26
 
@@ -55,12 +57,13 @@ def check_font(font='Arial.ttf', size=10):
55
  except Exception as e: # download if missing
56
  url = "https://ultralytics.com/assets/" + font.name
57
  print(f'Downloading {url} to {font}...')
58
- torch.hub.download_url_to_file(url, str(font))
59
  return ImageFont.truetype(str(font), size)
60
 
61
 
62
  class Annotator:
63
- check_font() # download TTF if necessary
 
64
 
65
  # YOLOv5 Annotator for train/val mosaics and jpgs and detect/hub inference annotations
66
  def __init__(self, im, line_width=None, font_size=None, font='Arial.ttf', pil=True):
 
3
  Plotting utils
4
  """
5
 
6
+ import math
7
+ import os
8
  from copy import copy
9
  from pathlib import Path
10
 
11
  import cv2
 
12
  import matplotlib
13
  import matplotlib.pyplot as plt
14
  import numpy as np
 
22
 
23
  # Settings
24
  CONFIG_DIR = user_config_dir() # Ultralytics settings dir
25
+ RANK = int(os.getenv('RANK', -1))
26
  matplotlib.rc('font', **{'size': 11})
27
  matplotlib.use('Agg') # for writing to files only
28
 
 
57
  except Exception as e: # download if missing
58
  url = "https://ultralytics.com/assets/" + font.name
59
  print(f'Downloading {url} to {font}...')
60
+ torch.hub.download_url_to_file(url, str(font), progress=False)
61
  return ImageFont.truetype(str(font), size)
62
 
63
 
64
  class Annotator:
65
+ if RANK in (-1, 0):
66
+ check_font() # download TTF if necessary
67
 
68
  # YOLOv5 Annotator for train/val mosaics and jpgs and detect/hub inference annotations
69
  def __init__(self, im, line_width=None, font_size=None, font='Arial.ttf', pil=True):