question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

assert len(indices) == len(self)

See original GitHub issue

hello, When I use it, raise error: “assert len(indices) == len(self), f”{indices} not equal {len(self)} while offset is: {offset}“” then I print the length info, =====len of indices is 26865 - offset: 0 - len self 36650 below is the detail error info, Please help me. Traceback (most recent call last): File "tools/train.py", line 198, in <module> main() File "tools/train.py", line 193, in main meta=meta, File "/data6/ziqiwen/code/softteacher/ssod/apis/train.py", line 206, in train_detector runner.run(data_loaders, cfg.workflow) File "/home/ziqiwen/anaconda3/envs/mm/lib/python3.7/site-packages/mmcv/runner/iter_based_runner.py", line 117, in run iter_loaders = [IterLoader(x) for x in data_loaders] File "/home/ziqiwen/anaconda3/envs/mm/lib/python3.7/site-packages/mmcv/runner/iter_based_runner.py", line 117, in <listcomp> iter_loaders = [IterLoader(x) for x in data_loaders] File "/home/ziqiwen/anaconda3/envs/mm/lib/python3.7/site-packages/mmcv/runner/iter_based_runner.py", line 23, in __init__ self.iter_loader = iter(self._dataloader) File "/home/ziqiwen/anaconda3/envs/mm/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 291, in __iter__ return _MultiProcessingDataLoaderIter(self) File "/home/ziqiwen/anaconda3/envs/mm/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 764, in __init__ self._try_put_index() File "/home/ziqiwen/anaconda3/envs/mm/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 994, in _try_put_index index = self._next_index() File "/home/ziqiwen/anaconda3/envs/mm/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 357, in _next_index return next(self._sampler_iter) # may raise StopIteration File "/home/ziqiwen/anaconda3/envs/mm/lib/python3.7/site-packages/torch/utils/data/sampler.py", line 208, in __iter__ for idx in self.sampler: File "/data6/ziqiwen/code/softteacher/ssod/datasets/samplers/semi_sampler.py", line 189, in __iter__ assert len(indices) == len(self) AssertionError Traceback (most recent call last): File "/home/ziqiwen/anaconda3/envs/mm/lib/python3.7/runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "/home/ziqiwen/anaconda3/envs/mm/lib/python3.7/runpy.py", line 85, in _run_code exec(code, run_globals) File "/home/ziqiwen/anaconda3/envs/mm/lib/python3.7/site-packages/torch/distributed/launch.py", line 261, in <module> main() File "/home/ziqiwen/anaconda3/envs/mm/lib/python3.7/site-packages/torch/distributed/launch.py", line 257, in main cmd=cmd)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:15

github_iconTop GitHub Comments

1reaction
Jack-Hu-2001commented, Oct 21, 2021

I guess the parametyer epoch_length is too small for your dataset since I encountered the same problem in my medical daataset weeks ago and solved this simply by turning it bigger. I haven’t carefully look at the sampler code so it’s just a simple and maybe unreasonable guess.

1reaction
MendelXucommented, Oct 18, 2021

I am not sure what the problem is. I have tried to change the samplers_per_gpu to 4 like you, but it works well. I will take a deeper look later.

Read more comments on GitHub >

github_iconTop Results From Across the Web

assert len(indices) == self.total_size error during multiple GPU ...
I am trying to train my dataset on 8 GPU's. However, after calling ./dist_train.sh this error assertion appeares: Traceback (most recent ...
Read more >
Error when using distributedsampler - PyTorch Forums
... divisible indices += indices[:(self.total_size - len(indices))] assert ... assert len(indices) == self.num_samples return iter(indices).
Read more >
Source code for mmdet.datasets.samplers.distributed_sampler
Then different ranks # could use different indices to select non-overlapped data from the # same data list. device = get_device() self.seed ...
Read more >
torch.utils.data.distributed — PyTorch master documentation
Generator() g.manual_seed(self.epoch) indices = torch.randperm(len(self.dataset), generator=g).tolist() # add extra samples to make it evenly divisible ...
Read more >
torch.utils.data.dataset — Catalyst 20.02.4 documentation
def __getitem__(self, index): raise NotImplementedError def __add__(self, ... See NOTE [ Lack of Default `__len__` in Python Abstract Base Classes ] # in ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found