当前位置:网站首页>RuntimeError: output with shape [1, 256, 256] doesn‘t match the broadcast shape [3, 256, 256]【报错】
RuntimeError: output with shape [1, 256, 256] doesn‘t match the broadcast shape [3, 256, 256]【报错】
2022-07-27 16:15:00 【太简单了】
解决方法
在dataloader前的dataset函数里,加.convert(‘RGB’),eg:
image = Image.open(image_file).convert('RGB')解决过程
论文复现过程中尝试将未使用的数据集应用到源代码里,出现如上报错。检查后发现错误出现在dataloader里,考虑是输入图片的问题,通过如下代码判断新加的数据集是灰度图(1.灰度图只有一个通道2.直接查看像素值),因此推断dataloader只接受三通道RGB图,将图片转化为RGB图即可。
打印图片像素值
img_path = '这里写要查看的图像地址'
from PIL import Image
from torchvision import transforms
img = Image.open(img_path)
change = transforms.ToTensor()
img = change(img)
print(img)查看图片像素值
import cv2
img_path = '这里写要查看的图像地址'
img_c = cv2.imread(img_path,cv2.IMREAD_UNCHANGED)
cv2.imshow('photo',img_c)
key = cv2.waitKey(0)有博客的解决方案是在transforms.Compose()里加入如下程序段,我的程序并未好转,如果是灰度图,RGB转换与repeat转换的三通道图像是一致的,这可能是程序存在其他的原因。
transforms.Lambda(lambda x: x.repeat(3, 1, 1))边栏推荐
- 一个案例理解mysql视图
- Labels such as {@code}, {@link} and < P > in the notes
- 2021.8.1 notes DBA
- RSA encryption and decryption (compatible with wechat applet environment)
- Visual studio code installation tutorial (super detailed)
- [MIT 6.S081] Lab 9: file system
- MySQL学习 Day1 DDL、DML、DQL基础查询
- JPA connection database password field blob
- Solve the problem that reids cannot be accessed by other IPS
- rsa加解密(兼容微信小程序环境)
猜你喜欢

Wechat applet obtains openid, sessionkey, unionid

解决Jsp级联问题
![[mit 6.s081] LEC 8: page faults notes](/img/e2/0f5332dd9d2b439bcf29e87a9fa27f.png)
[mit 6.s081] LEC 8: page faults notes
![[MIT 6.S081] Lab 11: networking](/img/9d/cca59a662412f3c3c57c26c5987a24.png)
[MIT 6.S081] Lab 11: networking
![[MIT 6.S081] Lab 7: Multithreading](/img/f4/26e513fb8678a88cfba29c1a636b37.png)
[MIT 6.S081] Lab 7: Multithreading

Complete set of machine learning classification task effect evaluation indicators (including ROC and AUC)

Visual Studio Code安装教程(超详细)

USB充电式暖手宝芯片-DLTAP602SC-杰力科创

2021.7.30 note index

低噪负离子风扇触摸IC
随机推荐
阿里架构师耗时280个小时整理的1015页分布式全栈小册,轻松入手分布式系统
音乐律动七彩渐变灯芯片--DLT8S04A-杰力科创
2021.8.1 Notes database design
使用jieba、pyhanlp工具实现关键字词句的提取
微信小程序微信支付概述
Using Jieba and pyhanlp tools to extract keyword words and sentences
Solve the problem that reids cannot be accessed by other IPS
XML学习 Day1 : xml / Jsoup解析器 / selector选择器 /Xpath选择器
2021.8.1笔记 DBA
这样的API网关查询接口优化,我是被迫的
Class not found: "the com.parkmanagement.dao.daotest test cannot find the test class
Meituan Er Mian: why does redis have sentinels?
Conflict between blur event and click event in input box
Build a simple knowledge question and answer system
Must the MySQL query column be consistent with the group by field?
机器学习分类任务效果评估指标大全(包含ROC和AUC)
2021.7.22笔记 约束
MySQL learning day3 multi table query / transaction / DCL
Uniapp has no effect on the page selector on the app side
2021.7.31 note view