记录解决RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 27 but got size
问题描述
在做目标检测服务过程中,将yolov7模型通过flask打包成预测服务API,此次训练的图像输入大小是1280,输入预测图片是如果图像大于1280则预测成功,小于1280则报RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 27 but got size。
由于只有小图片预测报错,猜测是图像处理过程中resize问题,提示下面代码行错误
pred = self.model(img, augment=self.augment)[0]
完整错误提示如下:
原因分析:
提示:这里填写问题的分析:
分析了半天最终发现是小图片在pading没有处理好,下面代码中少给了一个参数stride,导致小图片在pading过程中像素错误,导致dimension错误。
img = letterbox(img0, new_shape=self.img_size)[0]
解决方案:
最终通过参考原始utils.datasets代码中图像处理过程,改造代码,参考代码如下
改造自己的base64_to_image函数代码如下:
def base64_to_image(self,imagebase64):"""输入base64图片,输出图片"""try:imgbase64= base64.b64decode(imagebase64)buf_str = BytesIO(imgbase64).getvalue()nparr = np.fromstring(buf_str, np.uint8)img0 = cv2.imdecode(nparr, cv2.IMREAD_COLOR)# img = letterbox(img0, new_shape=self.img_size)[0]img = letterbox(img0, self.img_size, stride=self.stride)[0]img = img[:, :, ::-1].transpose(2, 0, 1) # BGR to RGB, to 3x416x416img = np.ascontiguousarray(img)return img,img0except:print("输入图片必须是BASE64格式...")
因为第一版代码不是自己写的,花了一下午加晚上逐行代码排查,最终解决了,还是记录一下,防止下次忘了。
记录解决RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 27 but got size相关推荐
- Sizes of tensors must match except in dimension 1. Expected size 24 but got size 25 for tensor numbe
在做图像分割的时候遇到了错误,错误如下: File "D:/segmentation/Pytorch-UNet-master/train.py", line 193, in < ...
- RuntimeError: Sizes of tensors must match except in dimension 1. Got 61 and 60 in dimension 2
1. 背景介绍 在训练语义分割模型时,出现以下错误: RuntimeError: Sizes of tensors must match except in dimension 1. Got 61 a ...
- RuntimeError: Sizes of tensors must match except in dimension 2. Got 5 and 4
调试代码的时候,遇到***RuntimeError: Sizes of tensors must match except in dimension 2. Got 5 and 4*** 这个问题, 解 ...
- Pytorch_Geometric(PyG)使用DataLoader报错RuntimeError: Sizes of tensors must match except in dimension 0.
使用Pytorch_Geometric(PyG)时构建DataLoader,从DataLoader获取样本Batch时报错:RuntimeError: Sizes of tensors must ma ...
- 模型预测过程中报错 RuntimeError: Sizes of tensors must match except in dimension 1.
具体报错如上所示 问题背景 用gradio库写了一个YOLOv7检测logo的demo,上传图片之后报错如上. 解决方法 一开始我以为是类别数不对应的问题,然而并不是. 实际上是一个非常粗心的错误,原 ...
- Sizes of tensors must match except in dimension 1. Expected size 44 but got size 45 for tensor numbe
项目场景: 跑U-net网络的时候,有一步是torch.cat()操作,出现 下面是代码 class UNet(nn.Module):def __init__(self, in_channels, o ...
- Sizes of tensors must match except in dimension 1. Got 61 and 60 in dimension 2
1. 背景介绍 在训练编码解码网络模型时,出现以下错误: RuntimeError: Sizes of tensors must match except in dimension 1. ...
- RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 1.
最近在修改模型不支持的算子后,由于对模型的效果产生了影响,所以需要进行微调训练,但是训练的时候报错了,如下: File "/home/xxxxxxx/EdgeNets/nn_layers/e ...
- RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0—问题分析
声明: 这里仅仅提供一个思路,暂时没有绝对正确通用的解决方案 作者:{ 墨理 } 感谢通过私信.评论交流,协力探讨解决问题的同学 UP .Penser 文章目录 探讨的 pytorch 报错信息如下 ...
最新文章
- windows10+Python3-如何安装numpy和matplotlib包
- 批量过滤删除AD中的对象
- 【PAT乙级】1024 科学计数法 (20 分)
- 精通移动端布局 - 概念篇 -
- 网管日志-06.07.12
- c语言实参和形参占用存储单元_必须知道的C语言知识细节:函数形参和实参的区别...
- python爬虫从入门到精通
- 表变量和临时表的使用
- KMS的几个开源实现汇总
- .Net页面缓存OutPutCache详解
- python输出语句格式 f_Python基础之输出格式和If判断
- 信息检索评价标准计算
- 公共基础知识:四大名楼简介
- 微信小程序开发——将自己的图片变成网络图片/图片链接生成
- leet code 006:ZigZag Conversion
- 特征预处理和特征生成 (一)数字特征
- 摄像头数字信号方式传输的 GMSL、FPD-Link、V-by-One 方式
- 安卓app单webview改为多webview加载网页
- 社团管理系统软件测试,软件测试大作业——社团管理系统(19页)-原创力文档...
- 罗马数字表希腊字母表
热门文章
- java 吃鸡辅助,给你的Java程序拍个片子吧:jstack下令剖析_彩虹六号辅助,pubg辅助...
- iOS11 初识ARKit
- python 动态变量 excel 配置_python 实现众多excel表格中关键数据追加项目配置库台账.xlsx...
- 在IB国际高中学IB哲学是种什么样的体验
- 极简操作!跟着官方教程,下载并使用汉化版Figma!
- C语言中for循环里面控制变量i的作用域问题
- 用Vue2.x + Mint-UI实现智能家居app demo
- 岭深常得蛟龙在 梧高自有凤凰栖
- python爬虫搜片利器fmovice
- Arduino 多种按键模式下的检测