1
votes

i want to read my mask to use them as an input for my training process my masks are located in a folder named mask (the shape of my images (128,128,4)) I used this code

path_folder = "" # the path to the folder containing masks 

mask_path= path_folder + '/masks/'
mask_file = os.listdir(mask_path)
y_train = np.zeros((len(mask_file), 128, 128, 1), dtype=np.bool)# this is the nump array where Iwant to put my masks 
ctr =0 
for n, id_ in tqdm(enumerate(mask_file), total=len(mask_file)):
   mask = imread(mask_path + mask_file[n])
   y_train[ctr] = mask
   ctr = ctr +1 

I got this error ValueError: could not broadcast input array from shape (128,128,4) into shape (128,128,1) Have you any idea what should I do

2

2 Answers

0
votes

I think the issue might be here:

mask = imread(mask_path + mask_file[n])

Try loading the image as grasycale (I assume you're using OpenCV). This will give you an image with shape (128,128), and then add a new dimension using unsqueeze.

mask = imread(mask_path + mask_file[n], 0)
0
votes

the problem is that you are trying to fit a cube in a surface, either you use just one layer from the last dimention(of 3), or to convert your image to grayscale.

one way to do it with opencv is

y_train[ctr] = cv2.imread('file_path',0)

this function it reads ur image and convert it to the shape 124,124,1