invalid argument 0: Sizes of tensors must match except in dimension 0. Got 1

 

invalid argument 0: Sizes of tensors must match except in dimension 0. Got 1

原因:dataloader 需要的数据维度是一样的,有的有两个目标,有的有一个目标,就会出现异常:

解决方法:凑成一样的。

Traceback (most recent call last):
  File "G:/project/facebox/faceboxes/tools/convert_tenser.py", line 116, in
    gen_data(batch_size,data_path,target_path)
  File "G:/project/facebox/faceboxes/tools/convert_tenser.py", line 30, in gen_data
    for step, samples in enumerate(dataloader):
  File "D:\ProgramData\Miniconda3\lib\site-packages\torch\utils\data\dataloader.py", line 314, in __next__
    batch = self.collate_fn([self.dataset[i] for i in indices])
  File "D:\ProgramData\Miniconda3\lib\site-packages\torch\utils\data\dataloader.py", line 184, in default_collate
    return {key: default_collate([d[key] for d in batch]) for key in batch[0]}
  File "D:\ProgramData\Miniconda3\lib\site-packages\torch\utils\data\dataloader.py", line 184, in
    return {key: default_collate([d[key] for d in batch]) for key in batch[0]}
  File "D:\ProgramData\Miniconda3\lib\site-packages\torch\utils\data\dataloader.py", line 164, in default_collate
    return torch.stack(batch, 0, out=out)
RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 1 and 2 in dimension 1 at c:\new-builder_3\win-wheel\pytorch\aten\src\th\generic/THTensorMath.cpp:3616
 

你可能感兴趣的:(torch)