DrSleep / tensorflow-deeplab-resnet

DeepLab-ResNet rebuilt in TensorFlow
MIT License
1.25k stars 429 forks source link

Finetuning on the frontground/background of VOC2012 #40

Closed Fansiee closed 7 years ago

Fansiee commented 7 years ago

I want to change the VOC2012 semantic segmentation task(21-class, include background) to a frontground/background task(2-class, all the class is assigned to frontground). I don't want to change the png image. I want to change the code to achieve the effect.

I changed the code as the following:

  1. In deeplab_resnet/image_reader.py, I add the code in the line 122:

    line 121:       label = tf.image.decode_png(label_contents, channels=1)
    line 122:       label = tf.cast(tf.not_equal(label, 0), tf.int8) 

    ps: I want to change all the non-background label to 1, and all the background label is 0.

  2. In train.py: n_classes = 2

  3. In deeplab_resnet/model.py: I replace 21 with 2 in the calls to atrous convolution.(as you said in #12)

  4. In train.py:

    
    restore_var = [v for v in trainable if not v.name.startswith('fc1_voc12_c')]
    not_restore_var = [v for v in trainable if v.name.startswith('fc1_voc12_c')]

optim = optimiser.minimize(reduced_loss, var_list=not_restore_var)

saver = tf.train.Saver(var_list=restore_var, max_to_keep=40) if args.restore_from is not None: load(saver, sess, args.restore_from)



The code is same as [#12](https://github.com/DrSleep/tensorflow-deeplab-resnet/issues/12)

However, it can't converge.
step 0  loss = 76.737
step 1   loss = 42903.938
step 3  loss = 16467024.000
step 4 loss = nan
step 5 loss = nan
step 6 loss = nan
step 7 loss = nan
...

I run it 6000 steps, but the loss is still nan.

If you don't mind, could you please help me with this problem?
I have spent a dozen of hours to read the code and try to realize this function.
I am almost crazy.......orz orz orz orz orz

update: I find that the `utils.py` should to be changed, and the `image_reader.py` should not.
              And I am trying it. And it is so hard.....orz
Fansiee commented 7 years ago

I think I know how to change the labels: In the line 163 of train.py, I add the code:

line 161                   gt = tf.cast(tf.gather(raw_gt, indices), tf.int32)
line 162                  prediction = tf.gather(raw_prediction, indices)
line 163                  gt = tf.cast(tf.not_equal(gt, 0), tf.int32)  #### added line

Does it right?

DrSleep commented 7 years ago

Hi I don't have access to the code at the moment, so can only give you some tips: 1) check the summary output and make sure that your images are being read correctly: i.e., there are 2 colours - black (background) + something else (foreground); 2) try to reduce the learning rate by some factor (e.g. 0.1) until the training stops diverging.

And I think you don't need to change the line 163 if you are using the most recent code. On 25 Feb 2017 9:30 pm, "Fansiee" notifications@github.com wrote:

I think I know how to change the labels: In the line 163 of train.py, I add the code:

line 161 gt = tf.cast(tf.gather(raw_gt, indices), tf.int32) line 162 prediction = tf.gather(raw_prediction, indices) line 163 gt = tf.cast(tf.not_equal(gt, 0), tf.int32) #### added line

Does it right?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/DrSleep/tensorflow-deeplab-resnet/issues/40#issuecomment-282481040, or mute the thread https://github.com/notifications/unsubscribe-auth/AHemmPYdEnIDPDG27lbBwVWSeofgLGqOks5rgB7egaJpZM4ML7fQ .

DrSleep commented 7 years ago

https://github.com/DrSleep/tensorflow-deeplab-resnet#using-your-dataset