zhixuhao / unet

unet for image segmentation
MIT License
4.6k stars 2k forks source link

Error when checking input: expected input_14 to have 4 dimensions, but got array with shape (1, 256, 256, 4, 1) #210

Open 1651061080 opened 4 years ago

1651061080 commented 4 years ago

I think the code is wrong but I don't know how to fix it. I have made color images and color grids. After the above step to test the error. Hope everyone can help. def testGenerator(test_path,num_image = 21,target_size = (256,256),flag_multi_class = False,as_gray = True): for i in range(num_image): img = io.imread(os.path.join(test_path,"%d.png"%i),as_gray = as_gray) img = img / 255 img = trans.resize(img,target_size) img = np.reshape(img,img.shape+(1,)) if (not flag_multi_class) else img img = np.reshape(img,(1,)+img.shape) yield img

pythonLiNM commented 3 years ago

May I ask if you have solved it? I also made a mistake in the RGB network report

ningningshide commented 3 years ago

img = np.reshape(img,img.shape+(1,)) if (not flag_multi_class) else img改为img = np.reshape(img,img.shape) if (not flag_multi_class) else img

Sisyphka commented 10 months ago

img = np.reshape(img,img.shape+(1,)) if (not flag_multi_class) else img改为img = np.reshape(img,img.shape) if (not flag_multi_class) else img

actually it can also be deleted , then the net will work