ValueError:无法从形状(256,256,3)广播输入数组到形状(512,512,3) &g



我试图用一些医学图像实现UNet模型。我试图创建一个函数来训练数据,但我不断得到一个重塑错误。

def create_train_data(self):
i = 0
print('-'*30)
print('Creating training images...')
print('-'*30)
imgs = glob.glob(self.data_path+"/*."+self.img_type)
print(len(imgs))
imgdatas = np.ndarray((len(imgs),self.out_rows,self.out_cols,3), dtype=np.uint8)
imglabels = np.ndarray((len(imgs),self.out_rows,self.out_cols,1), dtype=np.uint8)
for imgname in imgs:
midname = imgname[imgname.rindex("/")+1:]
img = load_img(self.data_path + "/" + midname)
label = load_img(self.label_path + "/" + midname,grayscale = True)
img = img_to_array(img)
label = img_to_array(label)
#img = cv2.imread(self.data_path + "/" + midname,cv2.IMREAD_GRAYSCALE)
#label = cv2.imread(self.label_path + "/" + midname,cv2.IMREAD_GRAYSCALE)
#img = np.array([img])
#label = np.array([label])
imgdatas[i] = img
imglabels[i] = label
if i % 100 == 0:
print('Done: {0}/{1} images'.format(i, len(imgs)))
i += 1
print('loading done')
np.save(self.npy_path + '/imgs_train.npy', imgdatas)
np.save(self.npy_path + '/imgs_mask_train.npy', imglabels)
print('Saving to .npy files done.')

我得到这个错误

ValueError                                Traceback (most recent call last)
<ipython-input-16-8a77190ab57c> in <module>
236     #aug.splitTransform()
237     mydata = dataProcess(512,512)
--> 238     mydata.create_train_data()
239     mydata.create_test_data()
<ipython-input-16-8a77190ab57c> in create_train_data(self)
172             #img = np.array([img])
173             #label = np.array([label])
--> 174             imgdatas[i] = img
175             imglabels[i] = label
176             if i % 100 == 0:
ValueError: could not broadcast input array from shape (256,256,3) into shape (512,512,3)
有谁能帮我一下吗?

尝试将outrowsoutcols从256更改为512。

相关内容

  • 没有找到相关文章

最新更新