MarvinTeichmann / tensorflow-fcn

An Implementation of Fully Convolutional Networks in Tensorflow.
MIT License
1.1k stars 432 forks source link

_summary_reshape #2

Closed weiliu620 closed 8 years ago

weiliu620 commented 8 years ago

Can you briefly explain why you need this function and how it works? I got an error from this function when I tried to train the model with a function that I wrote myself. I used PASCAL VOC so I define num_class = 21, including background. Here is the error stack

  /home/weiliu/projects/tensorflow-fcn/fcn32_vgg.py(106)build()
    104             self.score_fr = self._fc_layer(self.fc7, "score_fr",
    105                                            num_classes=num_classes,
--> 106                                            relu=False)
    107 
    108         self.pred = tf.argmax(self.score_fr, dimension=3)

  /home/weiliu/projects/tensorflow-fcn/fcn32_vgg.py(165)_fc_layer()
    163                                 message='Shape of %s' % name,
    164                                 summarize=4, first_n=1)
--> 165             return bias
    166 
    167     def _score_layer(self, bottom, name, num_classes):

  /home/weiliu/projects/tensorflow-fcn/fcn32_vgg.py(340)get_fc_weight_reshape()
    338         if num_classes is not None:
    339             weights = self._summary_reshape(weights, shape,
--> 340                                             num_new=num_classes)
    341         init = tf.constant_initializer(value=weights,
    342                                        dtype=tf.float32)

> /home/weiliu/projects/tensorflow-fcn/fcn32_vgg.py(298)_summary_reshape()
    296             avg_idx = start_idx//n_averaged_elements
    297             avg_fweight[:, :, :, avg_idx] = np.mean(
--> 298                 fweight[:, :, :, start_idx:end_idx], axis=3)
    299         return avg_fweight
    300 

And the error message is: IndexError: index 21 is out of bounds for axis 3 with size 21 Thanks for help!

MarvinTeichmann commented 8 years ago

Sry, a one-of error in cases where num_classes does not divide 1000 evenly. Commit 83608ed fixes the issue. Also added some Description. _summary_reshape is used to reduce the 1000 output classes of VGG to num_classes many for segmentation.

If you do fine-tuning also consider to set random_init_fc8=True. This will avoid the reshape. Hope this helps.