Traceback (most recent call last): File "test.py", line 345, in <module> v5_metric=opt.v5_metric File "test.py", line 107, in test for batch_i, (img, targets, paths, shapes) in enumerate(tqdm(dataloader, desc=s)): File "C:\Users\Dell\.conda\envs\sparsercnn\lib\site-packages\tqdm\std.py", line 1195, in __iter__ for obj in iterable: File "F:\git\yolov7-main\yolov7-main\utils\datasets.py", line 109, in __iter__ yield next(self.iterator) File "C:\Users\Dell\.conda\envs\sparsercnn\lib\site-packages\torch\utils\data\dataloader.py", line 628, in __next__ data = self._next_data() File "C:\Users\Dell\.conda\envs\sparsercnn\lib\site-packages\torch\utils\data\dataloader.py", line 1333, in _next_data return self._process_data(data) File "C:\Users\Dell\.conda\envs\sparsercnn\lib\site-packages\torch\utils\data\dataloader.py", line 1359, in _process_data data.reraise() File "C:\Users\Dell\.conda\envs\sparsercnn\lib\site-packages\torch\_utils.py", line 543, in reraise raise exception RuntimeError: Caught RuntimeError in DataLoader worker process 1. Original Traceback (most recent call last): File "C:\Users\Dell\.conda\envs\sparsercnn\lib\site-packages\torch\utils\data\_utils\worker.py", line 302, in _worker_loop data = fetcher.fetch(index) File "C:\Users\Dell\.conda\envs\sparsercnn\lib\site-packages\torch\utils\data\_utils\fetch.py", line 61, in fetch return self.collate_fn(data) File "F:\git\yolov7-main\yolov7-main\utils\datasets.py", line 434, in collate_fn return torch.stack(img, 0), torch.cat(label, 0), path, shapes RuntimeError: stack expects each tensor to be equal size, but got [1539, 448, 672] at entry 0 and [12, 448, 672] at entry 1
时间: 2023-06-26 10:08:07 浏览: 285
浅谈Python traceback的优雅处理
这个错误的原因是在数据加载过程中,有些数据的尺寸大小不一致,而在使用 `torch.stack` 进行堆叠操作时,要求每个 tensor 的大小必须相同,因此出现了这个错误。你需要检查一下数据集中的数据,找出这些尺寸大小不一致的数据,并将其进行处理,使其大小与其他数据一致。可以使用 OpenCV 或者 Pillow 这样的库来调整图像的大小。
阅读全文