Skip to content

Commit

Permalink
Fix floating point in number of workers nw (ultralytics#6701)
Browse files Browse the repository at this point in the history
Integer division by a float yields a (rounded) float. This causes
the dataloader to crash when creating a range.
  • Loading branch information
SamuelYvon authored and eladco committed Mar 10, 2022
1 parent 385c799 commit 000a10f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion utils/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def create_dataloader(path, imgsz, batch_size, stride, single_cls=False, hyp=Non

batch_size = min(batch_size, len(dataset))
nd = torch.cuda.device_count() # number of CUDA devices
nw = min([os.cpu_count() // max(nd / 2, 1), batch_size if batch_size > 1 else 0, workers]) # number of workers
nw = min([os.cpu_count() // max(nd // 2, 1), batch_size if batch_size > 1 else 0, workers]) # number of workers
sampler = None if rank == -1 else distributed.DistributedSampler(dataset, shuffle=shuffle)
loader = DataLoader if image_weights else InfiniteDataLoader # only DataLoader allows for attribute updates
return loader(dataset,
Expand Down

0 comments on commit 000a10f

Please sign in to comment.