|
29 | 29 | from utils.augmentations import Albumentations, augment_hsv, copy_paste, letterbox, mixup, random_perspective
|
30 | 30 | from utils.general import (LOGGER, NUM_THREADS, check_dataset, check_requirements, check_yaml, clean_str,
|
31 | 31 | segments2boxes, xyn2xy, xywh2xyxy, xywhn2xyxy, xyxy2xywhn)
|
32 |
| -from utils.torch_utils import device_count, torch_distributed_zero_first |
| 32 | +from utils.torch_utils import torch_distributed_zero_first |
33 | 33 |
|
34 | 34 | # Parameters
|
35 | 35 | HELP_URL = 'https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data'
|
36 | 36 | IMG_FORMATS = ['bmp', 'dng', 'jpeg', 'jpg', 'mpo', 'png', 'tif', 'tiff', 'webp'] # include image suffixes
|
37 | 37 | VID_FORMATS = ['asf', 'avi', 'gif', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'wmv'] # include video suffixes
|
38 |
| -DEVICE_COUNT = max(device_count(), 1) # number of CUDA devices |
39 | 38 |
|
40 | 39 | # Get orientation exif tag
|
41 | 40 | for orientation in ExifTags.TAGS.keys():
|
@@ -110,7 +109,8 @@ def create_dataloader(path, imgsz, batch_size, stride, single_cls=False, hyp=Non
|
110 | 109 | prefix=prefix)
|
111 | 110 |
|
112 | 111 | batch_size = min(batch_size, len(dataset))
|
113 |
| - nw = min([os.cpu_count() // DEVICE_COUNT, batch_size if batch_size > 1 else 0, workers]) # number of workers |
| 112 | + nd = torch.cuda.device_count() # number of CUDA devices |
| 113 | + nw = min([os.cpu_count() // max(nd, 1), batch_size if batch_size > 1 else 0, workers]) # number of workers |
114 | 114 | sampler = None if rank == -1 else distributed.DistributedSampler(dataset, shuffle=shuffle)
|
115 | 115 | loader = DataLoader if image_weights else InfiniteDataLoader # only DataLoader allows for attribute updates
|
116 | 116 | return loader(dataset,
|
|
0 commit comments