From 4a49818666f401a0264e4ef5bc14455db820979f Mon Sep 17 00:00:00 2001 From: Samuel Yvon Date: Fri, 18 Feb 2022 14:46:26 -0500 Subject: [PATCH] Fix floating point in number of workers Integer division by a float yields a (rounded) float. This causes the dataloader to crash when creating a range. --- utils/datasets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/datasets.py b/utils/datasets.py index a89edb861658..a67b10025887 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -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,