I would like to customize deeplab for image segmentation using my own dataset ? Is this achievable by retraining ?
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.
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.
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
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With