Search code examples
pythontensorflowobject-detection-api

Can the BoxClassifier in the Faster RCNN Inception v2 Model Be Frozen?


I am using the TensorFlow Object Detection API for retraining a COCO-pretrained Faster RCNN Inception v2 model on my custom dataset and recently noticed that several of my models BoxClassifierLoss get worse over the duration of the training (from e.g. 0.17 loss up to 0.38 and after 100 epochs down to 0.24 (thereafter getting worse again or fluctuating without improvement)).

Therefore I am interested in freezing the BoxClassifier to preserve the initial weights that apparently work better.

I read that there is a 'freeze_variables' parameter in the train.proto, but I am unsure as to what variables to freeze exactly.


Solution

  • You can freeze model.ckpt meta (checkpoint files) files which are stored in following location:

    C:\tensorflow1\models\research\object_detection\training
    

    These checkpoint files are stored frequently during training, so you can check the detail of this file when your error reduces then freeze the same checkpoint to your final model.

    For freezing the model, you can use following command:

    python export_inference_graph.py --input_type image_tensor --pipeline_config_path training/faster_rcnn_inception_v2_pets.config --trained_checkpoint_prefix training/model.ckpt-XXXX --output_directory inference_graph
    

    Where, XXXX is the number in file name model.ckpt-XXXX.meta. In my case it is model.ckpt-1970.meta, XXXX = 1970.

    Checkout my folder structure in the following image.