jakeret / tf_unet

Generic U-Net Tensorflow implementation for image segmentation
GNU General Public License v3.0
1.9k stars 748 forks source link

ValueError: could not broadcast input array from shape (300,300,2) into shape (300,300) #238

Closed mfrohman123 closed 5 years ago

mfrohman123 commented 5 years ago

Hello,

Thank you for providing an implementation for this network! I am trying to train the network on 300*300 images with two classes. I understand your implementation expects one hot encoding images, which I believe I am doing so via:

def sample(self, mask):
    hot = np.zeros((mask.shape[0], mask.shape[1], self.n_class))
    hot[:, :, 1] = (mask[:, :, 1]==255).astype(int)
    hot[..., 0] = (mask[:, :, 1]==0).astype(int)
    return hot

This function converts the masks to one hot before they are loaded. I am using the provided ImageDataProvider class. Self.n_classes equals 2, but during training I am getting the error 'could not broadcast input array from shape (300,300,2) into shape (300,300).'

Thank you in advance.

jakeret commented 5 years ago

not sure where you use this function. The ImageDataProvider automatically creates a one-hot encoding if n_classes==2

mfrohman123 commented 5 years ago

I figured it out; this function was used to convert the training labels to one-hot before being loaded in the ImageDataProvider class. Thanks!