Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can i finetune deeplab to a custom dataset in tensorflow?

I would like to customize deeplab for image segmentation using my own dataset ? Is this achievable by retraining ?

like image 698
mrBean Avatar asked Apr 19 '18 07:04

mrBean


People also ask

How do you create a dataset for semantic segmentation?

Preparing Segmentation dataset To create a segmentation dataset, we need to label the data considering each pixel, we need to draw to the exact shape of the object, and then we need to label it similar to object detection.

What is Deeplab v3+?

DeepLabv3+ is a state-of-art deep learning model for semantic image segmentation [3], where the goal is to assign semantic labels (such as a person, a dog, a cat and so on) to every pixel in the input image.


2 Answers

On Deeplab official tutorial page, the training commands looks like this:

python deeplab/train.py \
    --logtostderr \
    --training_number_of_steps=30000 \
    --train_split="train" \
    --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=1 \
    --dataset="pascal_voc_seg" \
    --tf_initial_checkpoint=${PATH_TO_INITIAL_CHECKPOINT} \
    --train_logdir=${PATH_TO_TRAIN_DIR} \
    --dataset_dir=${PATH_TO_DATASET}

By changing dataset_dir and dataset and a few lines in segmentation_dataset.py, you can train on your own dataset.

  • dataset_dir: path points to your tfrecord folder.

    Inside this folder, you should have train-%05d-of-%05d.tfrecord and val-%05d-of-%05d.tfrecord created by build_voc2012_data.py or other scripts in datasets.

    Accordingly, if you want to use train.tfrecord for training, set train_split to train; if you want to evaluate on your evaluation data, set train_split to val.

  • dataset: any self defined name, say "donkey_monkey"

  • Inside segmentation_dataset.py

    create DatasetDescriptor for your own dataset:

    _DONKEY_MONKEY_INFORMATION = DatasetDescriptor(
    splits_to_sizes={
        'train': 1464,  # number of training examples in train data
        'trainval': 2913,  # number of examples for train+eval
        'val': 1449,  # number of eval examples 
        },
        num_classes=21, # note: should be number of class + background
        ignore_label=255,  # label pixels to ignore
    )
    
    

    change below code (line 112)

    _DATASETS_INFORMATION = {
        'cityscapes': _CITYSCAPES_INFORMATION,
        'pascal_voc_seg': _PASCAL_VOC_SEG_INFORMATION,
        'ade20k': _ADE20K_INFORMATION,
        'donkey_monkey': _DONKEY_MONKEY_INFORMATION, # newly added
     }
    
    
like image 53
Yoyo Avatar answered Sep 29 '22 05:09

Yoyo


Yes you should follow one of these tutorials, depending on the dataset format you have, where you get how to convert datasets to TFrecord format, and train model.

If you use Pascal voc 2012 format, there is a complete example here, including all the steps for training, evaluation, visualize results, and export model.

like image 36
RomRoc Avatar answered Sep 29 '22 07:09

RomRoc