jakeret / tf_unet

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

Value ERROR in training at random times #218

Closed ghost closed 5 years ago

ghost commented 5 years ago

I get a value error about input array broadcasting at random times. Is this a bug?

I am using a dataset with around 18000 Images.

ValueError                                Traceback (most recent call last)
<ipython-input-51-416cd3021374> in <module>()
      1 output_path = './train_model/'
----> 2 path = trainer.train(data_provider, output_path, training_iters=32, epochs=20)

~/PycharmProjects/tf_unet/tf_unet/unet.py in train(self, data_provider, output_path, training_iters, epochs, dropout, display_step, restore, write_graph, prediction_path)
    430                 total_loss = 0
    431                 for step in range((epoch * training_iters), ((epoch + 1) * training_iters)):
--> 432                     batch_x, batch_y = data_provider(self.batch_size)
    433 
    434                     # Run optimization op (backprop)

~/PycharmProjects/tf_unet/tf_unet/image_util.py in __call__(self, n)
     85 
     86     def __call__(self, n):
---> 87         train_data, labels = self._load_data_and_label()
     88         nx = train_data.shape[1]
     89         ny = train_data.shape[2]

~/PycharmProjects/tf_unet/tf_unet/image_util.py in _load_data_and_label(self)
     48 
     49         train_data = self._process_data(data)
---> 50         labels = self._process_labels(label)
     51 
     52         train_data, labels = self._post_process(train_data, labels)

~/PycharmProjects/tf_unet/tf_unet/image_util.py in _process_labels(self, label)
     62             ny = label.shape[0]
     63             labels = np.zeros((ny, nx, self.n_class), dtype=np.float32)
---> 64             labels[..., 1] = label
     65             labels[..., 0] = ~label
     66             return labels

ValueError: could not broadcast input array from shape (512,512,3) into shape (512,512)
jakeret commented 5 years ago

hmmm I'm wondering if all the input images have the same shape. Have you checked that?

ghost commented 5 years ago

Yes, all the images have the same input shape.

jakeret commented 5 years ago

Sorry for the late reply. Is the value for n_class in the data_provider maybe set to 2 but the label acutally has more than 2 classes?

ghost commented 5 years ago

There are only 2 classes and its set to 2. So don't think that's the problem.

yanzistudio commented 5 years ago

Hi @shbsafi, did you solve this problem?