为什么我的数据加载器会加载空批次?

问题描述 投票:0回答:1

我正在尝试根据您的教程微调 MaskFormer 模型。但是,我在数据加载器方面遇到了一些问题。有时,训练会继续进行一次迭代,然后才会显示错误。有时则不然。但它不会训练超过一次迭代。这是错误的屏幕截图: enter image description here

下面的代码也有类似的行为: enter image description here

有人可以帮助我吗?

如果您想看一下,这里是整个笔记本:https://colab.research.google.com/drive/1pE9wyx6RUmQbqyzGBpOWs-m_nCOPYQZ1?usp=sharing

我没想到加载器中会有任何空批次,因为我是按照笔记本一步步操作的。我尝试减小批量大小,num_workers = 0

这是我得到的错误:

ValueError                                Traceback (most recent call last)
<ipython-input-28-d508975bf819> in <cell line: 3>()
      1 cnt = 0
      2 
----> 3 for item in train_dataloader:
      4   print(item)
      5   cnt += 1

10 frames
/usr/local/lib/python3.10/dist-packages/numpy/core/shape_base.py in stack(arrays, axis, out)
    420     arrays = [asanyarray(arr) for arr in arrays]
    421     if not arrays:
--> 422         raise ValueError('need at least one array to stack')
    423 
    424     shapes = {arr.shape for arr in arrays}

ValueError: need at least one array to stack
numpy deep-learning pytorch huggingface-transformers pytorch-dataloader
1个回答
0
投票

很确定这是因为代码正在使用来自albumentations的随机裁剪,

A.RandomCrop(width=512, height=512),
- 这意味着有时它最终会得到没有标签和崩溃的裁剪。

尝试用此替换该行

A.CropNonEmptyMaskIfExists(width=512, height=512),

https://albumentations.ai/docs/api_reference/augmentations/crops/transforms/#albumentations.augmentations.crops.transforms.CropNonEmptyMaskIfExists

© www.soinside.com 2019 - 2024. All rights reserved.