Retrain detectnet v2 model

Hello,
I am new on TLT. I have trained model as mentioned in detectnet_v2.ipynb till the model pruning and I am able to detect the objects(car,person,bicycle) but now I want to detect the object (car,person,bicycle and auto-rickshaw) so I want to add one more class auto-rickshaw and want to retrain on the weights generated by pruning so what should I add in this configuration file mentioned below. should I remove all the classes mention in this configuration file and add only auto-rickshaw class and before that will have to generate again tfrecords for only auto-rickshaw class.

random_seed: 42
dataset_config {
  data_sources {
    tfrecords_path: "/workspace/tlt-experiments/tfrecords/kitti_trainval/*"
    image_directory_path: "/workspace/tlt-experiments/data/training"
  }
  image_extension: "png"
  target_class_mapping {
    key: "car"
    value: "car"
  }
  target_class_mapping {
    key: "cyclist"
    value: "cyclist"
  }
  target_class_mapping {
    key: "pedestrian"
    value: "pedestrian"
  }
  target_class_mapping {
    key: "person_sitting"
    value: "pedestrian"
  }
  target_class_mapping {
    key: "van"
    value: "car"
  }
  validation_fold: 0
}
augmentation_config {
  preprocessing {
    output_image_width: 1248
    output_image_height: 384
    min_bbox_width: 1.0
    min_bbox_height: 1.0
    output_image_channel: 3
  }
  spatial_augmentation {
    hflip_probability: 0.5
    zoom_min: 1.0
    zoom_max: 1.0
    translate_max_x: 8.0
    translate_max_y: 8.0
  }
  color_augmentation {
    hue_rotation_max: 25.0
    saturation_shift_max: 0.20000000298
    contrast_scale_max: 0.10000000149
    contrast_center: 0.5
  }
}
postprocessing_config {
  target_class_config {
    key: "car"
    value {
      clustering_config {
        coverage_threshold: 0.00499999988824
        dbscan_eps: 0.20000000298
        dbscan_min_samples: 0.0500000007451
        minimum_bounding_box_height: 20
      }
    }
  }
  target_class_config {
    key: "cyclist"
    value {
      clustering_config {
        coverage_threshold: 0.00499999988824
        dbscan_eps: 0.15000000596
        dbscan_min_samples: 0.0500000007451
        minimum_bounding_box_height: 20
      }
    }
  }
  target_class_config {
    key: "pedestrian"
    value {
      clustering_config {
        coverage_threshold: 0.00749999983236
        dbscan_eps: 0.230000004172
        dbscan_min_samples: 0.0500000007451
        minimum_bounding_box_height: 20
      }
    }
  }
}
model_config {
  pretrained_model_file: "/workspace/tlt-experiments/experiment_dir_pruned/resnet18_nopool_bn_detectnet_v2_pruned.tlt"
  num_layers: 18
  use_batch_norm: true
  load_graph: true
  activation {
    activation_type: "relu"
  }
  objective_set {
    bbox {
      scale: 35.0
      offset: 0.5
    }
    cov {
    }
  }
  training_precision {
    backend_floatx: FLOAT32
  }
  arch: "resnet"
}
evaluation_config {
  validation_period_during_training: 10
  first_validation_epoch: 1
  minimum_detection_ground_truth_overlap {
    key: "car"
    value: 0.699999988079
  }
  minimum_detection_ground_truth_overlap {
    key: "cyclist"
    value: 0.5
  }
  minimum_detection_ground_truth_overlap {
    key: "pedestrian"
    value: 0.5
  }
  evaluation_box_config {
    key: "car"
    value {
      minimum_height: 20
      maximum_height: 9999
      minimum_width: 10
      maximum_width: 9999
    }
  }
  evaluation_box_config {
    key: "cyclist"
    value {
      minimum_height: 20
      maximum_height: 9999
      minimum_width: 10
      maximum_width: 9999
    }
  }
  evaluation_box_config {
    key: "pedestrian"
    value {
      minimum_height: 20
      maximum_height: 9999
      minimum_width: 10
      maximum_width: 9999
    }
  }
  average_precision_mode: INTEGRATE
}
cost_function_config {
  target_classes {
    name: "car"
    class_weight: 1.0
    coverage_foreground_weight: 0.0500000007451
    objectives {
      name: "cov"
      initial_weight: 1.0
      weight_target: 1.0
    }
    objectives {
      name: "bbox"
      initial_weight: 10.0
      weight_target: 10.0
    }
  }
  target_classes {
    name: "cyclist"
    class_weight: 8.0
    coverage_foreground_weight: 0.0500000007451
    objectives {
      name: "cov"
      initial_weight: 1.0
      weight_target: 1.0
    }
    objectives {
      name: "bbox"
      initial_weight: 10.0
      weight_target: 1.0
    }
  }
  target_classes {
    name: "pedestrian"
    class_weight: 4.0
    coverage_foreground_weight: 0.0500000007451
    objectives {
      name: "cov"
      initial_weight: 1.0
      weight_target: 1.0
    }
    objectives {
      name: "bbox"
      initial_weight: 10.0
      weight_target: 10.0
    }
  }
  enable_autoweighting: true
  max_objective_weight: 0.999899983406
  min_objective_weight: 9.99999974738e-05
}
training_config {
  batch_size_per_gpu: 4
  num_epochs: 120
  learning_rate {
    soft_start_annealing_schedule {
      min_learning_rate: 5e-06
      max_learning_rate: 5e-04
      soft_start: 0.10000000149
      annealing: 0.699999988079
    }
  }
  regularizer {
    type: NO_REG
    weight: 0.0
  }
  optimizer {
    adam {
      epsilon: 9.99999993923e-09
      beta1: 0.899999976158
      beta2: 0.999000012875
    }
  }
  cost_scaling {
    initial_exponent: 20.0
    increment: 0.005
    decrement: 1.0
  }
  checkpoint_interval: 10
}
bbox_rasterizer_config {
  target_class_config {
    key: "car"
    value {
      cov_center_x: 0.5
      cov_center_y: 0.5
      cov_radius_x: 0.40000000596
      cov_radius_y: 0.40000000596
      bbox_min_radius: 1.0
    }
  }
  target_class_config {
    key: "cyclist"
    value {
      cov_center_x: 0.5
      cov_center_y: 0.5
      cov_radius_x: 1.0
      cov_radius_y: 1.0
      bbox_min_radius: 1.0
    }
  }
  target_class_config {
    key: "pedestrian"
    value {
      cov_center_x: 0.5
      cov_center_y: 0.5
      cov_radius_x: 1.0
      cov_radius_y: 1.0
      bbox_min_radius: 1.0
    }
  }
  deadzone_radius: 0.400000154972
}

Please help me out.
Thanks

Hi pritam,
If you want to add a new class, i.e, (car,person,bicycle and auto-rickshaw), you need to add auto-rickshaw’s images into your dataset. And also add corresponding labels files. Then generate tfrecords again.
Modify the training spec for the new class. Trigger train again.

Thanks for your response.
So I need to replace resnet18.hdf5 with resnet18_nopool_bn_detectnet_v2_pruned.tlt in detectnet_v2_train_resnet18_kitti.txt file and then have to make configuration file for single class that is auto-rickshaw and start training. and the output weight will give me the result of all four class (car,person,bicycle and auto-rickshaw).
actually I want incremental learning add new class over previous weights without adding previous dataset.

Hi pritam,
Actually I did not trigger similar experiment as you mentioned. I am not sure it works. You can try it.
If not working, please follow my previous comment to train.

More, do your previous dataset’s images have auto-rickshaw?

no previous dataset’s does not have auto-rickshaw.
suppose i have only weights which detect n number of object i don’t have their dataset’s but now i want to add 2 classes and want to use that weights and make training so that i will able to detect (n+2) objects from the new weights. or can we append new weights over previous weights it is possible ?

Actually the problem is with me that I have already trained my model for the classes and training took more than 5-6 or more days but now i want to add only one class and only want to use new data set for which i want to train and not want to use previous data set for training but want to result for all the classes including previous and want to save my 5-6 days of training.

Please help me out.
thanks

Your idea seems to be not working. Because if you want to get the result of (n+2) objects, you must set (n+2) class in the training spec. And also the dataset of these (n+2) classes should be available.

To save your training time, I suggest you select parts of all the class’ dataset, make each class balance as much as possible.
For example, if you have 100K images/labels, you can select 20K to trigger test.
Do not make class’ data too unbalanced.

Thaks Morganh I will try your suggestion.

suppose if I have trained my model for 99 classes and in future I will have to add one more class so i will have to again train model for 100 class ?
if there is any approach to train model incrementally so please let me know.
thanks.