当前位置:网站首页>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))边栏推荐
- Complete set of machine learning classification task effect evaluation indicators (including ROC and AUC)
- Run the uniapp to the mobile phone (real machine debugging)
- [mit 6.s081] LEC 9: interrupts notes
- The song of the virtual idol was originally generated in this way!
- Vue uses keep alive to realize page caching
- Must the MySQL query column be consistent with the group by field?
- 低噪负离子风扇触摸IC
- MySQL four locks
- [mit 6.s081] LEC 5: calling conventions and stack frames risc-v notes
- JDBC学习 Day1:JDBC
猜你喜欢

2021.8.6 notes jsoup

2021.7.13 note sub query

What should I do if MySQL master-slave replication data is inconsistent?

MySQL learning Day1 DDL, DML, DQL basic query

C杂讲 链表初讲

The combination of text and words perfectly explains the implementation process of MySQL logical backup

浴室带除雾化妆镜触摸芯片-DLT8T10S

Class not found: "the com.parkmanagement.dao.daotest test cannot find the test class

Basic operations of MySQL view

File path read
随机推荐
Visual studio code installation tutorial (super detailed)
Generate PDM file from Navicat export table
Complete set of machine learning classification task effect evaluation indicators (including ROC and AUC)
1. OpenCV image basic operation
INSUFFICIENT_ ACCESS_ ON_ CROSS_ REFERENCE_ ENTITY APEX / SALESFORCE
RSA encryption and decryption (compatible with wechat applet environment)
Build a simple knowledge question and answer system
10 SQL optimization schemes summarized by Alibaba P8 (very practical)
2021.7.19笔记 DML
Mode= "widthfix" attribute in image tag
2021.7.18 notes MySQL data type
Nowcoder (5 choices)
[MIT 6.S081] Lab 7: Multithreading
阿里架构师耗时280个小时整理的1015页分布式全栈小册,轻松入手分布式系统
2021.7.13笔记 子查询
@Considerations for query of convert annotation in JPA
Modify placeholder style in input
虚拟偶像的歌声原来是这样生成的!
全身多功能按摩仪芯片-DLTAP602SD
Visual Studio Code安装教程(超详细)