tensorflow / tensorflow/models

High Evaluation Loss (with train dataset) while Train Loss is low using Tensorflow Object Detection API

Open
#9,056 1 comment 1 reaction 3 assignees View on GitHub

@pkulzc is already working on this.

Since Sep 7, 2020.

models:research:odapi type:bug
Dominant language
Python
Stars
77.7k
Forks
44.8k
PR merge metrics
No merged PRs in 30d

Description

1. The entire URL of the file you are using

https://github.com/tensorflow/models/blob/master/research/object_detection/model_main.py

2. Describe the bug

When finetunning Faster RCNN model using model_main.py script, I deliberately set evaluation dataset to be the same as training dataset (TF_DATA) and expect to see the same loss in evaluation as in training. However, evaluation losses are (after 4000 epochs):

Loss/BoxClassifierLoss/classification_loss = 20588.025
Loss/BoxClassifierLoss/localization_loss = 9474.761
Loss/RPNLoss/localization_loss = 0.10792526
Loss/RPNLoss/objectness_loss = 0.4256882
Loss/total_loss = 30063.021
loss = 30063.021

While the training total loss is:

I0804 14:01:57.539440 139956088792960 basic_session_run_hooks.py:260] loss = 0.27122372, step = 4200 (24.047 sec)

3. Steps to reproduce

RESIZE_SHAPE = (300, 300)
EVALUATE_EVERY = 10000
EPOCHS = 100000

NMS_SCORE_THRESHOLD = 0.1
IOU_THRESHOLD = 0.7
IOU_THRESHOLD2 = 0.6
NMS_SCORE_THRESHOLD2 = 0.01
LR_INIT = 0.0001
BATCH_SIZE = 3
AUGMENTATIONS = ''''''

model {
  faster_rcnn {
    num_classes: 1
    image_resizer {
      fixed_shape_resizer {
        height: '''+str(RESIZE_SHAPE[0])+'''
        width: '''+str(RESIZE_SHAPE[1])+'''
      }
    }
    feature_extractor {
      type: 'faster_rcnn_resnet101'
      first_stage_features_stride: 16
    }
    first_stage_anchor_generator {
      grid_anchor_generator {
        scales: [0.25, 0.5, 1.0, 2.0]
        aspect_ratios: [0.5, 1.0, 2.0]
        height_stride: 16
        width_stride: 16
      }
    }
    first_stage_box_predictor_conv_hyperparams {
      op: CONV
      regularizer {
        l2_regularizer {
          weight: 0.0
        }
      }
      initializer {
        truncated_normal_initializer {
          stddev: 0.01
        }
      }
    }
    first_stage_nms_score_threshold: '''+str(NMS_SCORE_THRESHOLD)+'''
    first_stage_nms_iou_threshold: '''+str(IOU_THRESHOLD)+'''
    first_stage_max_proposals: 300
    first_stage_localization_loss_weight: 2.0
    first_stage_objectness_loss_weight: 1.0
    initial_crop_size: 14
    maxpool_kernel_size: 2
    maxpool_stride: 2
    second_stage_box_predictor {
      mask_rcnn_box_predictor {
        use_dropout: true
        dropout_keep_probability: 0.5
        fc_hyperparams {
          op: FC
          regularizer {
            l2_regularizer {
              weight: 0.0
            }
          }
          initializer {
            variance_scaling_initializer {
              factor: 1.0
              uniform: true
              mode: FAN_AVG
            }
          }
        }
      }
    }
    second_stage_post_processing {
      batch_non_max_suppression {
        score_threshold: '''+str(NMS_SCORE_THRESHOLD2)+'''
        iou_threshold: '''+str(IOU_THRESHOLD2)+'''
        max_detections_per_class: 100
        max_total_detections: 300
      }
      score_converter: SOFTMAX
    }
    second_stage_localization_loss_weight: 2.0
    second_stage_classification_loss_weight: 1.0
  }
}

train_config: {
  batch_size: '''+str(BATCH_SIZE)+'''
  optimizer {
    momentum_optimizer: {
      learning_rate: {
        manual_step_learning_rate {
          initial_learning_rate: '''+str(LR_INIT)+'''
          schedule {
            step: 900000
            learning_rate: '''+str(LR_INIT)+'''
          }
          schedule {
            step: 1200000
            learning_rate: '''+str(LR_INIT)+'''
          }
        }
      }
      momentum_optimizer_value: 0.9
    }
    use_moving_average: false
  }
  gradient_clipping_by_norm: 10.0
  fine_tune_checkpoint: "'''+MODEL_TO_USE+'''/model.ckpt"
  from_detection_checkpoint: true

  #https://stackoverflow.com/questions/50014129/tensorflow-object-detection-api-mis-classifying-objects
  load_all_detection_checkpoint_vars: false

  '''+AUGMENTATIONS+'''
}

train_input_reader: {
  tf_record_input_reader {
    input_path: "'''+TF_DATA+'''" 
  }
  label_map_path: "'''+CLASS_LABELS+'''"
  shuffle: true 
}

eval_config: {
  num_examples: '''+str(len(test_dataset))+'''
  max_evals: '''+str(EPOCHS // EVALUATE_EVERY)+'''
  min_score_threshold: '''+str(NMS_SCORE_THRESHOLD2)+'''
}

eval_input_reader: {
  tf_record_input_reader {
    input_path: "'''+TF_DATA+'''" 
  }
  label_map_path: "'''+CLASS_LABELS+'''" 
  shuffle: true
}

4. Expected behavior

Same/similar loss in both evaluation and trainign

6. System information

Using Google Colab
Tensroflow version 1.15

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.