运行程序报错:
RuntimeError: output with shape [1, 224, 224] doesn’t match the broadcast shape [3, 224, 224]
报错原因:原模型输入的图片为RGB三通道,我输入的为单通道灰度图片。
解决:将单通道灰度图片转成RGB三通道图片。
pathdir = 'K:/LIDC-IDIR/Xuezhang-Method-haveif/Data_2_origin/1/';%文件路径
format = 'bmp';%文件格式
files = dir(strcat(pathdir,'*.',format));
% dir 列出当前文件夹中的文件和文件夹。
% strcat 水平串联字符串
% 列出文件夹中后缀为.bmp的文件
steps = 100;
hwait = waitbar(0,'准备开始');
disp(numel(files))
for n = 1:numel(files)
filename = strcat(pathdir,files(n).name);
disp(files(n).name)
img = imread(filename);
x = repmat(img,[1,1,3]);%将单通道图片转换为三通道图片
imwrite(x,filename,'bmp');
str = '正在运行中....';
waitbar(n/numel(files),hwait,str)
end
close(hwait);