models icon indicating copy to clipboard operation
models copied to clipboard

Error to train on my data

Open bleedingfight opened this issue 8 years ago • 24 comments

My environment; cuda V9.0.176,cudnn 7.0,tensorflow-gpu 1.8,Titan X x8 My data:20000 num picture,2labels,object is lane(4 pixle width ),other is background.Every picture size is[512,512],segmentation annotation picture is grayscale picture,lane pix is 1,other's(background) is 0. my alter include:

splits_to_sizes={
    'train': 18000,
    'trainval': 20000,
    'val': 2000,
},
num_classes=2,
ignore_label=255,

)``` and add:

    'cityscapes': _CITYSCAPES_INFORMATION,
    'pascal_voc_seg': _PASCAL_VOC_SEG_INFORMATION,
    'lane_seg': _LANE_SEG_INFORMATION,
    'ade20k': _ADE20K_INFORMATION,
}

train:

NUM_ITERATIONS=10000
python "${WORK_DIR}"/train.py \
  --logtostderr \
  --initialize_last_layer=False \
  --num_clones=1 \
  --last_layers_contain_logits_only=False \
  --dataset='lane_seg' \
  --train_split="trainval" \
  --model_variant="xception_65" \
  --atrous_rates=6 \
  --atrous_rates=12 \
  --atrous_rates=18 \
  --output_stride=16 \
  --decoder_output_stride=4 \
  --train_crop_size=513 \
  --train_crop_size=513 \
  --train_batch_size=4 \
  --training_number_of_steps="${NUM_ITERATIONS}" \
  --fine_tune_batch_norm=true \
  --tf_initial_checkpoint="${INIT_FOLDER}/deeplabv3_pascal_train_aug/model.ckpt" \
  --train_logdir="${TRAIN_LOGDIR}" \
  --dataset_dir="${LANE_DATASET}"

python "${WORK_DIR}"/eval.py \
  --logtostderr \
  --eval_split="val" \
  --dataset="lane_seg" \
  --model_variant="xception_65" \
  --atrous_rates=6 \
  --atrous_rates=12 \
  --atrous_rates=18 \
  --output_stride=16 \
  --decoder_output_stride=4 \
  --eval_crop_size=513 \
  --eval_crop_size=513 \
  --checkpoint_dir="${TRAIN_LOGDIR}" \
  --eval_logdir="${EVAL_LOGDIR}" \
  --dataset_dir="${LANE_DATASET}" \
  --max_number_of_evaluations=1

python "${WORK_DIR}"/vis_lane.py \
  --logtostderr \
  --vis_split="val" \
  --dataset="lane_seg" \
  --model_variant="xception_65" \
  --atrous_rates=6 \
  --atrous_rates=12 \
  --atrous_rates=18 \
  --output_stride=16 \
  --decoder_output_stride=4 \
  --vis_crop_size=513 \
  --vis_crop_size=513 \
  --checkpoint_dir="${TRAIN_LOGDIR}" \
  --vis_logdir="${VIS_LOGDIR}" \
  --dataset_dir="${LANE_DATASET}" \
  --max_number_of_iterations=1

python "${WORK_DIR}"/export_model.py \
  --logtostderr \
  --checkpoint_path="${CKPT_PATH}" \
  --export_path="${EXPORT_PATH}" \
  --model_variant="xception_65" \
  --atrous_rates=6 \
  --atrous_rates=12 \
  --atrous_rates=18 \
  --output_stride=16 \
  --decoder_output_stride=4 \
  --num_classes=2 \
  --crop_size=513 \
  --crop_size=513 \
  --inference_scales=1.0

I alter the train_utils.py's exclude_list=['global_step',logits] when i train the dataset,i error list:

Input checkpoint '/home/models/research/deeplab/datasets/lane_seg/exp/train_on_trainval_set/train/model.ckpt-10000' doesn't exist!

my questions is:

when I vis the picture,The result is like:
i think it only use pretrain of voc to inference,so the result is so bad,Is my opinion right?

my dataset mybe the data samples may be strongly biased to background,How can i finetune the weight of loss ? Your num_classes should be greater than the max pixel value in the images Someone said that should finetune loss's weight,what I shold do,scale label 1's weight to 10x,100x,or change to 0.1,0.2or change label 0's weight?what others i need to finetune?

Thanks for your help!

bleedingfight avatar Jun 13 '18 17:06 bleedingfight

Not sure about your other questions, but did you verify that you have a set of three 10,000 iteration ckpt files in the specified location?

austinmw avatar Jun 13 '18 18:06 austinmw

@austinmw thanks for your help,the checkpoint proble i find my checkpoint file isn't exist,I shold use deeplab initial model instead it?or just train it from scrach?

bleedingfight avatar Jun 13 '18 18:06 bleedingfight

It looks like you're trying to set it to start at a 10000 iteration checkpoint whereas the pretrained weights that you download usually start off at checkpoint # 00000. I would spend a lot more time trying to configure usage of pretrained weights properly before considering training from scratch.

What class type are you trying to segment? The more the objects you want to segment are similar to the coco/imagenet classes the less you have to adjust them.

austinmw avatar Jun 13 '18 18:06 austinmw

@austinmw I try to train the models,but the loss oscillation about 0.8 even though I have tried it for 10w step,Have some suggestion to deal with it?(I have tried to decrease lr to 0.000001 but the loss as I just said)

bleedingfight avatar Jun 15 '18 05:06 bleedingfight

@bleedingfight Hey,I'm trying to train my own dataset just like your experiment(2 CLASS include backgroud).But I can just get mean_iou=1 after running eval.py and get a black output after running vis.py.I think I've made some error during making my training data .So, would you mind sharing your experience on making biclass training data ?Thanks a lot !

Citygity avatar Jun 18 '18 01:06 Citygity

@Citygity

 not_ignore_mask = tf.to_float(tf.equal(scaled_labels, 0)) * 1 + tf.to_float(tf.    equal(scaled_labels, 1)) * 500 + tf.to_float(tf.equal(scaled_labels, ignore_label))     * 0

bleedingfight avatar Jun 18 '18 02:06 bleedingfight

@bleedingfight thanks a lot ,I have added this part in train_utils.py .However it doesn't work ,I get same result( mean_iou=1 and black output) .My dataset is spacenet(a high-resolution remote sensing imagery dataset) and I made the label image by https://github.com/SpaceNetChallenge/utilities .The label image was a PNG format image with 2 color(0 for backround and 122 for building).So I'd like to know how did you build your own data's label?thanks a lot ! Happy Dragon Boat Festival! 端午节快乐!

Citygity avatar Jun 18 '18 03:06 Citygity

@Citygity I think yor should change building's pixel to 1 or 2,3,4..20 if you use it demo.sh.In this script,contain train,eval,vis,export_model,In vis you will use VOC's colormap if your havn't change the segmentation_colormap.py,but in the code,every colormap stand for a label(0-20),if you havn't pixel 0-20,the output maybe error I guessed.you can try change the pixel

bleedingfight avatar Jun 18 '18 03:06 bleedingfight

@bleedingfight Your method works, thanks a lot, I got bad result too as follow. 000192_image 000192_prediction

Citygity avatar Jun 18 '18 14:06 Citygity

@Citygity maybe you. shold train it more step to see the reault. my result is bad that miou is 0.46,i. don't know why!

bleedingfight avatar Jun 18 '18 14:06 bleedingfight

@bleedingfight I‘m trying to train 40000 steps ,I think I'd be able to get the result tomorrow morning. I'd share with you if I get any trick training this model.

Citygity avatar Jun 18 '18 15:06 Citygity

@Citugity thanks for your share

bleedingfight avatar Jun 18 '18 15:06 bleedingfight

@bleedingfight I got miou_1.0[0.81052655] after 40000 steps training.I changed the parameter in not_ignore_mask = tf.to_float(tf.equal(scaled_labels, 0)) * 1 + tf.to_float(tf. equal(scaled_labels, 1)) * 500 + tf.to_float(tf.equal(scaled_labels, ignore_label)) * 0 into not_ignore_mask = tf.to_float(tf.equal(scaled_labels, 0)) * 1 + tf.to_float(tf. equal(scaled_labels, 1)) * 5 + tf.to_float(tf.equal(scaled_labels, ignore_label)) * 0(changed 500 to 5) the result is just as follow: 000192_image 000192_prediction

Citygity avatar Jun 19 '18 01:06 Citygity

Hi

Currently I’m struggling with improving the results using deeplab trained on my own dataset. I’ve trained deeplab successfully a few times using different pretrained models from the model zoo, all based on xception_65, but my results keep staying in the same miou range, somewhere around this interval [10, 11]. I have only one GPU at my disposal with 11GB GPU memory. My dataset has 8 classes with various object sizes, from little to big, and is quite unbalanced. Here are the label weights: [1, 4, 4, 17, 42, 36, 19, 20]. In my dataset I have 757 instances for training and 100 validation. I’ve tried to adjust parameters like learning rate, last_layer_gradient_multiplier, weight decay. I’ve also tried some kind of weighting using the above weights in this formula

weights = tf.to_float(tf.equal(scaled_labels, 0)) * 1 + tf.to_float(tf.equal(scaled_labels, 1)) * 4 + tf.to_float(tf.equal(scaled_labels, 2)) * 4 + tf.to_float(tf.equal(scaled_labels, 3)) * 17 + tf.to_float(tf.equal(scaled_labels, 4)) * 42 + tf.to_float(tf.equal(scaled_labels, 5)) * 36 + tf.to_float(tf.equal(scaled_labels, 6)) * 19 + tf.to_float(tf.equal(scaled_labels, 7)) * 20 + tf.to_float(tf.equal(scaled_labels, ignore_label)) * 0.0

but it turns out the algorithm won’t converge. I’ve trained without fine tuning the batch normalization parameters. Although I tried training those parameters with a 321 crop size in order to be able to fit a batch size of 12 in my GPU. I’ve tried training on various sizes 321, 513, 769. The point being I need some tips to figure out what I can do to improve those results. What do you guys think? Do I need more data in order to increase my miou or hardware?

weehe91325 avatar Jun 19 '18 09:06 weehe91325

Someone else can chime in and probably help more, but I don't know if batch normalization is worth the time it takes for very small batch sizes used in mask rcnn models? Matterport mask r-cnn has it turned off by default. If you have the time you could plot a learning curve by repeating training with multiple data amounts to get a better idea if more data will help.

austinmw avatar Jun 19 '18 16:06 austinmw

@Citygity Hi, I had the same problem when I was training the model, and my trian image is png format too,Did you transform the train image from png to jpeg format?

trobr avatar Jul 23 '18 01:07 trobr

For others who have miou=1 and blank segmentation maps for binary classification, set the ignore_label parameter in segmentation_dataset.py to a number that is not present in your label images. My labels were 0 and 1 so I set ignore_label=255 and my segmentation maps are no longer blank.

@trobr I used PNG images so I don't think you need to change them to jpeg

kritiyer avatar Jul 24 '18 13:07 kritiyer

@kritiyer Thank you for your help!There ara 12 classification include background in my dataset,and i set the parameter _PASCAL_VOC_SEG_INFORMATION as shown below,but I get the problem too.And i have another confusion,Is the label image format in your dataset is np.uint8 or np.uint16.In my dataset,they are set to np.uint16,could this be the cause of the problem?I'm going to convert the label image format and retrain again.Thanks again for your suggest. image

trobr avatar Jul 25 '18 05:07 trobr

@trobr I used uint8 labels

kritiyer avatar Jul 25 '18 14:07 kritiyer

@kritiyer year!I think I had find out the cause of this problem,when I convert label to uint8 and I have got expected results.Thanks very much for your help!

trobr avatar Jul 26 '18 01:07 trobr