metriclearningbench
metriclearningbench copied to clipboard
ValueError: sampler should be an instance of torch.utils.data.Sampler,
Dear vadimkantorov,
thank you for your publishing this nice repo, very well written. I'm running "python train.py --dataset cub2011 --model margin --base resnet50" with pytorch 1.0.1 and pythorn 3.6 but it crushes with the error
Traceback (most recent call last):
File "train.py", line 71, in
I guess it has something to do with the new pytorch version. Could you help me to make it run correctly?
Thanks
Could you try to modify:
adapt_sampler = lambda batch, dataset, sampler, **kwargs: type('', (), dict(__len__ = dataset.__len__, __iter__ = lambda _: itertools.chain.from_iterable(sampler(batch, dataset, **kwargs))))()
to read instead:
adapt_sampler = lambda batch, dataset, sampler, **kwargs: type('', (torch.utils.data.Sampler,), dict(__len__ = dataset.__len__, __iter__ = lambda _: itertools.chain.from_iterable(sampler(batch, dataset, **kwargs))))()
?
Please let me know if it works and don't hesitate to send a PR.
I get this error now
Traceback (most recent call last):
File "train.py", line 77, in
I know it's just a missing parameter but I don't understand what's happening in this piece of code, so please help! :D
Just checking, are you using (torch.utils.data.Sampler,) and not (torch.utils.data.Sampler)? (the difference is the comma, but it's important)
It gives me the same error in both cases
Sorry @bbrattoli, don't have time to look at this in detail these days. I'll update here if I check what's going on. Meanwhile, the way to go is to define yourself a Sampler subclass instead of my hacky adapt_sampler dynamic class creation.