标题RuntimeError: There were no tensor arguments to this function 解决方案
Error
展示
测试图片模型时出现了 RuntimeError
。全:RuntimeError: There were no tensor arguments to this function(e.g., you passed an empty list of Tensors), but no fallback function is registered for schema aten::_cat. This usually means that this function requires a non-empty list of Tensors. Available functions are [CUDATensorId, CPUTensorId, VariableTensorId]
Detecting objects: 18%|█▊ | 25/136 [00:02<00:11, 10.07it/s]Traceback (most recent call last):
File "/home/zero/blood_detect/PyTorch-YOLOv3/test.py", line 88, in <module>
batch_size=2
File "/home/zero/blood_detect/PyTorch-YOLOv3/test.py", line 39, in evaluate
for batch_i, (_, imgs, targets) in enumerate(tqdm.tqdm(dataloader, desc="Detecting objects")):
File "/home/zero/anaconda3/lib/python3.7/site-packages/tqdm/std.py", line 1081, in __iter__
for obj in iterable:
File "/home/zero/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 819, in __next__
return self._process_data(data)
File "/home/zero/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 846, in _process_data
data.reraise()
File "/home/zero/anaconda3/lib/python3.7/site-packages/torch/_utils.py", line 385, in reraise
raise self.exc_type(msg)
RuntimeError: Caught RuntimeError in DataLoader worker process 0.
Original Traceback (most recent call last):
File "/home/zero/anaconda3/lib/python3.7/site-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop
data = fetcher.fetch(index)
File "/home/zero/anaconda3/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 47, in fetch
return self.collate_fn(data)
File "/home/zero/blood_detect/PyTorch-YOLOv3/utils/datasets.py", line 143, in collate_fn
targets = torch.cat(targets, 0)
RuntimeError: There were no tensor arguments to this function (e.g., you passed an empty list of Tensors), but no fallback function is registered for schema aten::_cat. This usually means that this function requires a non-empty list of Tensors. Available functions are [CUDATensorId, CPUTensorId, VariableTensorId]
Detecting objects: 18%|█▊ | 25/136 [00:02<00:12, 8.81it/s]
错误源代码
precision, recall, AP, f1, ap_class = evaluate(
model,
path=valid_path,
iou_thres=opt.iou_thres,
conf_thres=opt.conf_thres,
nms_thres=opt.nms_thres,
img_size=opt.img_size,
batch_size=2
)
解决方案
将batch_size
设置高一点,加快测试速度。我设置为4
就可以了。