ValueError: could not broadcast input array from shape (256,256,3) into shape (512,512,3)

ValueError: could not broadcast input array from shape (256,256,3) into shape (512,512,3)

我正在尝试使用一些医学图像来实现 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。