glenn-jocher commited on
Commit
8f875d9
1 Parent(s): 2c63175

Refactor NUM_THREADS (#5954)

Browse files
Files changed (2) hide show
  1. utils/datasets.py +2 -3
  2. utils/general.py +5 -4
utils/datasets.py CHANGED
@@ -26,8 +26,8 @@ from torch.utils.data import DataLoader, Dataset, dataloader, distributed
26
  from tqdm import tqdm
27
 
28
  from utils.augmentations import Albumentations, augment_hsv, copy_paste, letterbox, mixup, random_perspective
29
- from utils.general import (LOGGER, check_dataset, check_requirements, check_yaml, clean_str, segments2boxes, xyn2xy,
30
- xywh2xyxy, xywhn2xyxy, xyxy2xywhn)
31
  from utils.torch_utils import torch_distributed_zero_first
32
 
33
  # Parameters
@@ -35,7 +35,6 @@ HELP_URL = 'https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data'
35
  IMG_FORMATS = ['bmp', 'jpg', 'jpeg', 'png', 'tif', 'tiff', 'dng', 'webp', 'mpo'] # acceptable image suffixes
36
  VID_FORMATS = ['mov', 'avi', 'mp4', 'mpg', 'mpeg', 'm4v', 'wmv', 'mkv'] # acceptable video suffixes
37
  WORLD_SIZE = int(os.getenv('WORLD_SIZE', 1)) # DPP
38
- NUM_THREADS = min(8, max(1, os.cpu_count() - 1)) # number of multiprocessing threads
39
 
40
  # Get orientation exif tag
41
  for orientation in ExifTags.TAGS.keys():
 
26
  from tqdm import tqdm
27
 
28
  from utils.augmentations import Albumentations, augment_hsv, copy_paste, letterbox, mixup, random_perspective
29
+ from utils.general import (LOGGER, NUM_THREADS, check_dataset, check_requirements, check_yaml, clean_str,
30
+ segments2boxes, xyn2xy, xywh2xyxy, xywhn2xyxy, xyxy2xywhn)
31
  from utils.torch_utils import torch_distributed_zero_first
32
 
33
  # Parameters
 
35
  IMG_FORMATS = ['bmp', 'jpg', 'jpeg', 'png', 'tif', 'tiff', 'dng', 'webp', 'mpo'] # acceptable image suffixes
36
  VID_FORMATS = ['mov', 'avi', 'mp4', 'mpg', 'mpeg', 'm4v', 'wmv', 'mkv'] # acceptable video suffixes
37
  WORLD_SIZE = int(os.getenv('WORLD_SIZE', 1)) # DPP
 
38
 
39
  # Get orientation exif tag
40
  for orientation in ExifTags.TAGS.keys():
utils/general.py CHANGED
@@ -33,14 +33,15 @@ from utils.downloads import gsutil_getsize
33
  from utils.metrics import box_iou, fitness
34
 
35
  # Settings
 
 
 
 
36
  torch.set_printoptions(linewidth=320, precision=5, profile='long')
37
  np.set_printoptions(linewidth=320, formatter={'float_kind': '{:11.5g}'.format}) # format short g, %precision=5
38
  pd.options.display.max_columns = 10
39
  cv2.setNumThreads(0) # prevent OpenCV from multithreading (incompatible with PyTorch DataLoader)
40
- os.environ['NUMEXPR_MAX_THREADS'] = str(min(os.cpu_count(), 8)) # NumExpr max threads
41
-
42
- FILE = Path(__file__).resolve()
43
- ROOT = FILE.parents[1] # YOLOv5 root directory
44
 
45
 
46
  def set_logging(name=None, verbose=True):
 
33
  from utils.metrics import box_iou, fitness
34
 
35
  # Settings
36
+ FILE = Path(__file__).resolve()
37
+ ROOT = FILE.parents[1] # YOLOv5 root directory
38
+ NUM_THREADS = min(8, max(1, os.cpu_count() - 1)) # number of YOLOv5 multiprocessing threads
39
+
40
  torch.set_printoptions(linewidth=320, precision=5, profile='long')
41
  np.set_printoptions(linewidth=320, formatter={'float_kind': '{:11.5g}'.format}) # format short g, %precision=5
42
  pd.options.display.max_columns = 10
43
  cv2.setNumThreads(0) # prevent OpenCV from multithreading (incompatible with PyTorch DataLoader)
44
+ os.environ['NUMEXPR_MAX_THREADS'] = str(NUM_THREADS) # NumExpr max threads
 
 
 
45
 
46
 
47
  def set_logging(name=None, verbose=True):