Pytorch——报错解决:TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, found
报错信息
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相关推荐
- PyTorch 报错:TypeError: exceptions must derive from BaseException
项目场景: PyTorch 报错:TypeError: exceptions must derive from BaseException 其实是个低级错误,我个人认为是因为没有找到要运行的载体. 问 ...
- 报错解决: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 ...
- #报错解决#TypeError Failed to execute ‘readAsText‘ on ‘FileReader‘ parameter 1 is not of type ‘Blob‘
问题描述 在实现需求:批量下载的时候,返回的数据类型设置为blob $http({method: 'post',url: dataurl,data: bodyParam,headers: { 'Con ...
- Pytorch——报错解决:RuntimeError: Output 0 of SelectBackward is a view and is being modified inplace.
我在做Semi-Supervised过程中,需要分别计算labeled和unlabeled data的loss,但是在多卡分布式过程中,不允许出现同一个model前向两次的情况,会报错(Runtime ...
- pytorch报错: invalid argument 0: Sizes of tensors must match except in dimension 0.
这个问题是在dataloader遇到的,网上一般是数据的维度不同,但我这里其实是最后一份数据和之前的数据比数量不足,所以凑不够一个batch,所以我的做法是加入drop_last=True意思是如果数 ...
- 报错解决:TypeError: Object type class 'str' cannot be passed to C code
此文首发于我的个人博客:报错解决 TypeError Object type class 'str' cannot be passed to C code - zhang0peter的个人博客 下午在 ...
- 安装pytorch报错及解决
环境,win10,64位,Anaconda4.10.3,Cuda 9.2.148,cudnn应该为v7.4.2.24 其中在Anaconda中好像安装tensorflow-gpu 1.9 ,pytho ...
- python3运行报错:TypeError: Object of type ‘type‘ is not JSON serializable解决方法(详细)
python3运行报错:TypeError: Object of type 'type' is not JSON serializable解决方法(详细) 参考文章: (1)python3运行报错:T ...
- TypeError: ‘builtin_function_or_method‘ object is not subscriptable 报错解决方法
TypeError: 'builtin_function_or_method' object is not subscriptable 报错解决方法 参考文章: (1)TypeError: 'buil ...
最新文章
- 小米4c怎么添加语言怎么设置在哪里,小米4c路由器设置教程
- Gulp:插件编写入门
- maven项目里面程序不能正确读取resources目录配置文件
- 【数学建模】数模day13-灰色系统理论I-灰色关联与GM(1,1)预测
- 《selenium2 python 自动化测试实战》(15)——调用js控制滚动条等操作
- mysql实际项目中使用多长时间_存储过程在实际项目中用的多吗?
- java实现分页打印功能_web 页面分页打印的实现
- a标签跳转后返回原页面 layui_layui页面操作,点击一个添加页面,跳转有确定,然后点击确定后将选择的几个数据返回前一个页面获取值,然后ajax请求后台...
- 定义变量和常量的规范 c语言,C语言编程规范教材及练习(标识符命名与定义 变量 宏、常量 表的达式).pptx...
- linux 常见路径,linux中目录与路径常见相关命令
- html input提交按钮无法使用,无法找到并单击提交按钮使用mshtml.HTMLInputElement
- PSFTP 常用命令
- IOUtils使用介绍
- 计算机操作系统教程徐甲同pdf,《操作系统实践教程》.pdf
- Adobe Illustrator 中的路径查找器
- Your build settings specify a provisioning profile with the UUID, no provisioni(没多大用)
- Rockchip HDMI 软件开发指南
- 3D模型在线云转换和在线展示
- 【技术邻】搞热仿真离不开热电偶
- java祖玛_Canvas小练习_祖玛游戏01
热门文章
- 26进制的加法和除法codeforces1144E
- ​华润MMX链上云的价值
- 表单提交 form选择
- 告诉你用Python赚钱的五种方法,闲余月赚1000~5000
- 100套炫酷网站错误页Html5模板(403,404,500等)
- form标签的action之前 加密_HTML从零开始——表单标签
- 复合维生素的功效和作用是哪些?每天吃维生素有什么好处?
- Java/Android中的引用类型及WeakReference应用实践
- 如何在windows docker上搭建本地ChatGPT,不需要翻墙
- linux安装usermod命令,Linux中的Usermod命令