报错信息

TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found <class 'NoneType'>

主要原因是由于获取到batch中输入有None,反推代码,说明你的__getitem__()函数返回值为None,因此出现如下报错。

解决方法

因此,解决方法就是不要让返回值有None即可。

示例

  • 原代码:
def prepare_train_data(self, index):"""Training data preparation.Args:index (int): Index for accessing the target data.Returns:dict: Training data dict of the corresponding index."""input_dict = self.get_data_info(index)if input_dict is None:return None     # 这里就是报错根源self.pre_pipeline(input_dict)example = self.pipeline(input_dict)return example
def prepare_train_data(self, index):"""Training data preparation.Args:index (int): Index for accessing the target data.Returns:dict: Training data dict of the corresponding index."""input_dict = self.get_data_info(index)if input_dict is None:# 如果当前为None,则取下一帧,直到不为None时return即可return self.get_data_info(index+1)self.pre_pipeline(input_dict)example = self.pipeline(input_dict)return example

参考文章:

  • 报错记录:TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists;

Pytorch——报错解决:TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, found相关推荐

  1. PyTorch 报错:TypeError: exceptions must derive from BaseException

    项目场景: PyTorch 报错:TypeError: exceptions must derive from BaseException 其实是个低级错误,我个人认为是因为没有找到要运行的载体. 问 ...

  2. 报错解决:alueError: When using data tensors as input to a model, you should specify the `steps_per_epoch

    报错解决:valueError: When using data tensors as input to a model, you should specify the steps_per_epoch ...

  3. #报错解决#TypeError Failed to execute ‘readAsText‘ on ‘FileReader‘ parameter 1 is not of type ‘Blob‘

    问题描述 在实现需求:批量下载的时候,返回的数据类型设置为blob $http({method: 'post',url: dataurl,data: bodyParam,headers: { 'Con ...

  4. Pytorch——报错解决:RuntimeError: Output 0 of SelectBackward is a view and is being modified inplace.

    我在做Semi-Supervised过程中,需要分别计算labeled和unlabeled data的loss,但是在多卡分布式过程中,不允许出现同一个model前向两次的情况,会报错(Runtime ...

  5. pytorch报错: invalid argument 0: Sizes of tensors must match except in dimension 0.

    这个问题是在dataloader遇到的,网上一般是数据的维度不同,但我这里其实是最后一份数据和之前的数据比数量不足,所以凑不够一个batch,所以我的做法是加入drop_last=True意思是如果数 ...

  6. 报错解决:TypeError: Object type class 'str' cannot be passed to C code

    此文首发于我的个人博客:报错解决 TypeError Object type class 'str' cannot be passed to C code - zhang0peter的个人博客 下午在 ...

  7. 安装pytorch报错及解决

    环境,win10,64位,Anaconda4.10.3,Cuda 9.2.148,cudnn应该为v7.4.2.24 其中在Anaconda中好像安装tensorflow-gpu 1.9 ,pytho ...

  8. python3运行报错:TypeError: Object of type ‘type‘ is not JSON serializable解决方法(详细)

    python3运行报错:TypeError: Object of type 'type' is not JSON serializable解决方法(详细) 参考文章: (1)python3运行报错:T ...

  9. TypeError: ‘builtin_function_or_method‘ object is not subscriptable 报错解决方法

    TypeError: 'builtin_function_or_method' object is not subscriptable 报错解决方法 参考文章: (1)TypeError: 'buil ...

最新文章

  1. 小米4c怎么添加语言怎么设置在哪里,小米4c路由器设置教程
  2. Gulp:插件编写入门
  3. maven项目里面程序不能正确读取resources目录配置文件
  4. 【数学建模】数模day13-灰色系统理论I-灰色关联与GM(1,1)预测
  5. 《selenium2 python 自动化测试实战》(15)——调用js控制滚动条等操作
  6. mysql实际项目中使用多长时间_存储过程在实际项目中用的多吗?
  7. java实现分页打印功能_web 页面分页打印的实现
  8. a标签跳转后返回原页面 layui_layui页面操作,点击一个添加页面,跳转有确定,然后点击确定后将选择的几个数据返回前一个页面获取值,然后ajax请求后台...
  9. 定义变量和常量的规范 c语言,C语言编程规范教材及练习(标识符命名与定义 变量 宏、常量 表的达式).pptx...
  10. linux 常见路径,linux中目录与路径常见相关命令
  11. html input提交按钮无法使用,无法找到并单击提交按钮使用mshtml.HTMLInputElement
  12. PSFTP 常用命令
  13. IOUtils使用介绍
  14. 计算机操作系统教程徐甲同pdf,《操作系统实践教程》.pdf
  15. Adobe Illustrator 中的路径查找器
  16. Your build settings specify a provisioning profile with the UUID, no provisioni(没多大用)
  17. Rockchip HDMI 软件开发指南
  18. 3D模型在线云转换和在线展示
  19. 【技术邻】搞热仿真离不开热电偶
  20. java祖玛_Canvas小练习_祖玛游戏01

热门文章

  1. 26进制的加法和除法codeforces1144E
  2. ​华润MMX链上云的价值
  3. 表单提交 form选择
  4. 告诉你用Python赚钱的五种方法,闲余月赚1000~5000
  5. 100套炫酷网站错误页Html5模板(403,404,500等)
  6. form标签的action之前 加密_HTML从零开始——表单标签
  7. 复合维生素的功效和作用是哪些?每天吃维生素有什么好处?
  8. Java/Android中的引用类型及WeakReference应用实践
  9. 如何在windows docker上搭建本地ChatGPT,不需要翻墙
  10. linux安装usermod命令,Linux中的Usermod命令