models icon indicating copy to clipboard operation
models copied to clipboard

Maybe a big bug in object_detection API, when I add data augmentation options on config files, then the model quickly divergences, mAP on testset would be 0.

Open MetaPeak opened this issue 9 years ago • 21 comments

I am training with "ssd_inception_v2" on coco datasets, when I use the default data augmentation options in config file, which is

  data_augmentation_options {
    random_horizontal_flip {
    }
  }
  data_augmentation_options {
    ssd_random_crop {
    }
  }

the model convergences rightly. It works very well. However, when I add one data augmentation options which is defined in objection_detection/coco/preprocessor, only add one random_adjust_hue option or
random_adjust_saturation et.al. The model would divergence quickly, even in a pretrained model, and mAP on testset would decline to 0 quickly. I add data augmentation options on config files, which looks like this format

  data_augmentation_options {
    random_horizontal_flip {
    }
  }
  data_augmentation_options {
    ssd_random_crop {
    }
  }

  data_augmentation_options {
    random_adjust_saturation {
    }
  }

image I tried ssd_inception_v2 on pascal data with the all scripts in Tensorflow Object Detection API, I met the same problem. Without random_adjust_brightness or any of hue, contrast. et.al, the model works quite well, when add random_adjust_brightness or any of hue, contrast. et.al. It's mAP on validation set quickly decline to 0. I wonder whether those methods on core/preporcessor.py loss the bboxes or labels when they are applied?

MetaPeak avatar Jul 29 '17 03:07 MetaPeak

@jch1 @ali01 @derekjchow @akssri @leVirve

MetaPeak avatar Aug 02 '17 05:08 MetaPeak

@derekjchow could you please take a look.

shivaniag avatar Aug 03 '17 17:08 shivaniag

This is because of the clipping there. It seems that models need input to be in fixed point representation (see the preprocess function).

In fact, all tf.image.random_* function make sure the output is valid so this clip operation is not needed. I removed them and made a pull request here : #2146.

drauh avatar Aug 07 '17 10:08 drauh

Thanks very much. Maybe the object detection framework first preprocess the original pixel value (0~255) in the preprocessor.py, because I set the parameters in clip value to image = tf.clip_by_value(image, clip_value_min=0, clip_value_max=255), the model works normally. However, in the source code (image_ops_impl.py,) the pixel value is in [0,1), so those adjust function maybe are invalid, because one value in [0,255) add one value in (-max_delta, max_delta), it is close to the original value.

MetaPeak avatar Aug 10 '17 03:08 MetaPeak

If the input is in true fixed point representation (if you look at the create_*_tf_record.py scripts, image are encoded as bytes = uint8 if I am not mistaken. So at least at the beginning the are in fixed point), then the adjust_* functions take care of the conversion to float, apply adjustment and then convert them back to fixed point (and also saturate them). So the delta is not applied in fixed point representation. Maybe you can try max_delta=5, if it is applied in fixed point it will not change much but if is it in float it will prevent the learning.

drauh avatar Aug 10 '17 19:08 drauh

Also on the saturation : if the input (which never append I object_detection api) is in float then it will never be saturated by the the adjust_* functions. Maybe that's a problem to have different behavior to two dtypes. One solution would be to convert everything to fixed point before doing anything since the preprocessing functions assume that dtype (or more precisely that scale, the type is not important).

drauh avatar Aug 10 '17 20:08 drauh

I have encountered the same problem. I used your MR, https://github.com/tensorflow/models/pull/2146/files, and the model works. Thank you so much! @drauh

irmowan avatar Aug 21 '17 11:08 irmowan

@irmowan Does the extra data augmentation steps works better?

sczhengyabin avatar Aug 28 '17 08:08 sczhengyabin

@sczhengyabin For my experiments, the improvement of performance with distort color steps is minimal, just FYI.

irmowan avatar Aug 29 '17 08:08 irmowan

I noticed this problem too, adding some augmentation options causes my training to stop converging.

timothykassis avatar Sep 12 '17 00:09 timothykassis

if num_train_sets = batch_size*train_steps,does 'num_train_sets' include the augmentation data?

CODEJY avatar Oct 27 '17 06:10 CODEJY

This is a so essential bug, many many people get frustrated by it! Please check the pull request and merge it (if nothing else gets broken of course...)

plieningerweb avatar Jan 12 '18 10:01 plieningerweb

I have hit this issue too. I even tried adding just:

  data_augmentation_options {
    random_adjust_brightness {
      max_delta: 0.0001
    }
  }

even tried max_delta: 0., which should end up with identity (i.e., no augmentation). The faster-rccn-resnet101 model (initialized from the pre-trained model) that otherwise trains well does not start learning at all, and the mAP/APs remain close to zero. This indicates, that adding the brightness augmentation severely breaks something in the object_detection API.

lcerman avatar Feb 05 '18 18:02 lcerman

Hi all, I already remove the clip of [0, 1] and the input of preprocessor.py is in the range of [0, 255]. Then the output, when I add some random augmentation, would be out of [0, 255], e.g., [-20, 300] Should I clip this back to be compatible with (2.0 / 255.0) * resized_inputs - 1.0 ?

zengyu714 avatar Mar 27 '18 09:03 zengyu714

should a mirror image return the same score as the same regular image when random_horizontal_flip is used? I've discovered that if I flip a test image i get a dramatically different score when detecting

funkysandman avatar Mar 27 '18 23:03 funkysandman

Is this the issue for a behaviour like this?:

INFO:tensorflow:global step 265: loss = 0.1965 (0.155 sec/step)
INFO:tensorflow:global step 266: loss = 0.1991 (0.155 sec/step)
INFO:tensorflow:global step 267: loss = 0.1896 (0.154 sec/step)
INFO:tensorflow:global step 268: loss = 0.1847 (0.154 sec/step)
INFO:tensorflow:global step 269: loss = 0.1858 (0.153 sec/step)
INFO:tensorflow:global step 270: loss = 0.1864 (0.151 sec/step)
INFO:tensorflow:global step 271: loss = 0.1861 (0.158 sec/step)
INFO:tensorflow:global step 272: loss = 0.2479 (0.158 sec/step)
INFO:tensorflow:global step 273: loss = 0.3874 (0.159 sec/step)
INFO:tensorflow:global step 274: loss = 0.2599 (0.158 sec/step)
INFO:tensorflow:global step 275: loss = 27207767073038008320.0000 (0.155 sec/step)
INFO:tensorflow:global step 276: loss = 363770730445224804352.0000 (0.154 sec/step)
INFO:tensorflow:global step 277: loss = 2319587573063963639808.0000 (0.157 sec/step)
INFO:tensorflow:global step 278: loss = 9538479895582634672128.0000 (0.155 sec/step)
INFO:tensorflow:global step 279: loss = 35610680577759077466112.0000 (0.153 sec/step)
INFO:tensorflow:global step 280: loss = 93008970008403315261440.0000 (0.153 sec/step)

I train a faster-rcnn + resnet + coco + (my dataset) in summer 2017 and worked well. Nowadays after some updates I get THIS.

bugerry87 avatar Mar 29 '18 16:03 bugerry87

@pkulzc have these changes been made in your repository which is gcp 1.2 ready? I am getting a similar error.

jashshopin avatar May 14 '18 16:05 jashshopin

Sorry they are not merged to my branch. My branch is for temporary use only and not guaranteed to sync. We are migrating to new interfaces with can be run on CMLE runtime 1.6 very soon. So you can edit your own repo as a temp fix and use our new interface later on.

pkulzc avatar May 14 '18 17:05 pkulzc

Subbing, cause i might be running into this issue.

aysark avatar Jun 06 '18 00:06 aysark

hello @bugerry87 , I have the same issue, could you please inform me how can I solve this strange behavior of the model. Thanks in advance.

kerolos avatar Jul 04 '18 12:07 kerolos