完整报错:

TypeError: conv2d() received an invalid combination of arguments - got (str, Parameter, NoneType, tuple, tuple, tuple, int), but expected one of:* (Tensor input, Tensor weight, Tensor bias, tuple of ints stride, tuple of ints padding, tuple of ints dilation, int groups)didn't match because some of the arguments have invalid types: (str, Parameter, NoneType, tuple, tuple, tuple, int)* (Tensor input, Tensor weight, Tensor bias, tuple of ints stride, str padding, tuple of ints dilation, int groups)didn't match because some of the arguments have invalid types: (str, Parameter, NoneType, tuple, tuple, tuple, int)

场景:在模型训练完用模型做预测的时候报错,预测代码:

def predict_process(root_path, transform):imgs = os.listdir(root_path)res=[]label_arry=['ant','bee']for img in imgs:img_path = root_path+'/'+imgprint(img_path)img_item = Image.open(img_path)img_item = transform(img_item)# 将输入图片的shape修改成符合输入条件的shapeimg_item = torch.reshape(img_item, (1,3, 224, 224))img_item=img_item.to(device)print(type(img_item))mymodel.eval()with torch.no_grad():output = mymodel(img)ret,index=torch.max(output,1)index=index.datares.append(label_arry[index])return res

原因分析:在卷积的时候接收到了无效的参数,所以要么就是输入的参数有问题,要么就是卷积层有问题,但是这里的mymodel我用的是pytorch中自带的resnet50所以卷积层肯定是没有问题的,所以问题就定位在我输入图片的格式,因为我在训练的时候是没有报错的,所以我只需要保证我在做预测的时候输入图片的格式和我训练的时候输入的图片格式是一样的就可以了,然后我把做预测的时候的图片img_item的shape和自身都输出了一遍,print(img_item.shape),print(img_item)去和训练的时候的图片做对比,发现是一模一样的,于是我开始疯狂改预测时输入的img_item的格式,希望能试出看看什么格式是ok的,就这样搞了一天还是不行,后来发现我搞了半天的img_item,最后输入模型做预测的时候用的是img,output = mymodel(img)img是一个str类型的变量"xxx.png",所以我浪费了一天的生命,但如果有类似的问题以上的分析步骤是没问的,问题一般就出在输入图片和卷积层上。

TypeError: conv2d() received an invalid combination of arguments相关推荐

  1. TypeError: mean() received an invalid combination of arguments - got (list, dim=int), but expected o

    TypeError: mean() received an invalid combination of arguments - got (list, dim=int), but expected o ...

  2. TypeError: norm() received an invalid combination of arguments解决办法

    1.问题 使用pytorch中torch.nn.functional模块时,出现以下报错: 问题代码位于: mean, std = [0.485, 0.456, 0.406], [0.229, 0.2 ...

  3. empty() received an invalid combination of arguments - got (tuple, dtype=NoneType, device=NoneType),

    完整报错如下: TypeError: empty() received an invalid combination of arguments - got (tuple, dtype=NoneType ...

  4. 【深度学习】empty() received an invalid combination of arguments - got (tuple, dtype=NoneType, device=None

    构建yoloV3的resblock时,python的一个小坑 在构建一个简单的卷积层时,出现如下的错误: 代码如下: class resblock(nn.Module):def __init__(se ...

  5. 成功解决TypeError: ‘encoding’ is an invalid keyword argument for this function

    成功解决TypeError: 'encoding' is an invalid keyword argument for this function 目录 解决问题 解决思路 解决方法 解决问题 Ty ...

  6. 502 Proxy Error The proxy server received an invalid response from an upstream server

    Proxy Error The proxy server received an invalid response from an upstream server. The proxy server ...

  7. scrapy shell 调试报错TypeError: module.__init__() takes at most 2 arguments (3 g iven)

    1.使用scrapy shell的时候本人之前安装了ipython,使用shell调式格式从>>>变成了[1]这种带有ipython的格式,结果整齐度看起来比较舒服. 2.现在创建了 ...

  8. ABOV E-PGM+提示 “No valid license” or “Received an invalid 32bit LOCTL

    ABOV E-PGM+提示  "No valid license" or "Received an invalid 32bit LOCTL 1. Disconnect t ...

  9. invalid number of arguments in root directive in

    从未见过如此厚颜无耻之人... 在windows上部署nginx,始终是报 invalid number of arguments in "root" directive in这个 ...

  10. TypeError系列之:TypeError: conv2d(): argument 'input' (position 1) must be Tensor, not NoneType

    这里出现类似错误往往是因为,conv2d()函数的第一个参数,需要时一个tensor行的数据,然而却赋值成了not后给的类型. 我出现问题的原因是,中间有一个函数缺少返回值,因此会造成NoneType ...

最新文章

  1. php unable to save,php – Laravel save()未定义
  2. 20应用统计考研复试要点(part28)--简答题
  3. python是什么语言-Python是什么?为什么现在越来越多的人选择学习Python语言
  4. LoadRunner 录制常见错误解决方法
  5. c语言基础知识scanf,C语言基础之scanf函数的使用
  6. Axure实操笔记之axure炫酷的作者信息设置
  7. LeetCode题解:幂集
  8. linux 找不到libaio.h,POSIX AIO和Linux上的libaio之间的区别?
  9. 中兴b860修改mac_【原创】猫盘群晖超级简单修改【SN MAC】 工具
  10. 算法基础:排序算法:7个常用的衡量指标
  11. super-resolution
  12. 专访神州飞象高级数据库工程师赖伟:迁移不怕难,大象肚里能撑船
  13. 【公众号技能+】添加白名单,允许其他公众号转载文章
  14. 数仓存在的意义价值及分层的好处
  15. BBR 拥塞控制算法blog笔记
  16. 使用matlab处理.nii图像
  17. 双边滤波去噪matlab代码,双边滤波器原理及其matlab实现
  18. 除了这门升级中的V2Pro课程,恐怕你找不到更好的学验证的途径了
  19. AndroidQ_默认数据连接的建立
  20. linux日常——挑选合适的笔记软件

热门文章

  1. Java读取OPC DA报错:org.jinterop.dcom.common.JIException: Access is denied. [0x80070005]
  2. 京东无货商品强制加入购物车
  3. Oracle Client卸载
  4. 域名邮箱用GMAIL,live
  5. 【工控老马】OPC通讯协议解析-OPC七问
  6. pdf批量盖章软件_我的PDF休要乱用 超实用的PDF批量加水印神器 它来了
  7. Angular设置代理
  8. java接口防抖_RxJava功能防抖
  9. bind9 域名劫持_域名劫持会怎样?如何解决域名劫持
  10. REST Assured 1 - REST Assured 介绍