jakeret / tf_unet

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

could not broadcast input array from shape (400,500,3) into shape (400,500) #262

Open tz11 opened 5 years ago

tz11 commented 5 years ago

I want to segment an RGB image with two classes.And I have resized the image shape as (400,500,3). Here is my code demo: data_provider = ImageDataProvider("X:/XX/*.tif") net = unet.Unet(channels=3, n_class=2, layers=3, features_root=16)

BaseDataProvider: channels = 3 n_class = 2 def _process_labels(self, label): if self.n_class == 2: nx = label.shape[1] ny = label.shape[0] labels = np.zeros((ny, nx, self.n_class), dtype=np.float32) labels[..., 1] = label labels[..., 0] = ~label return labels return label

ImageDataProvider: def init(...): self.channels = 1 if len(img.shape) == 2 else img.shape[-1] self.n_class = 2

Error: labels[..., 1] = label ValueError: could not broadcast input array from shape (400,500,3) into shape (400,500) THANKS!