models icon indicating copy to clipboard operation
models copied to clipboard

[object_detection] Masks correct bounding boxes incorrect position

Open D-K-E opened this issue 7 years ago • 5 comments

System information

What is the top-level directory of the model you are using: object_detection

Have I written custom code (as opposed to using a stock example script provided in TensorFlow): no

OS Platform and Distribution (e.g., Linux Ubuntu 16.04): ubuntu 16.04

TensorFlow installed from (source or binary): binary

TensorFlow version (use command below): 1.12.0

Bazel version (if compiling from source):

CUDA/cuDNN version: nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2015 NVIDIA Corporation Built on Tue_Aug_11_14:27:32_CDT_2015 Cuda compilation tools, release 7.5, V7.5.17

GPU model and memory: N/A

Exact command to reproduce:

Here is my config file:

model {
  faster_rcnn {
    number_of_stages: 3
    num_classes: 1
    image_resizer {
      keep_aspect_ratio_resizer {
        min_dimension: 800
        max_dimension: 1365
      }
    }
    feature_extractor {
      type: "faster_rcnn_inception_v2"
      first_stage_features_stride: 16
    }
    first_stage_anchor_generator {
      grid_anchor_generator {
        height_stride: 16
        width_stride: 16
        scales: 0.25
        scales: 0.5
        scales: 1.0
        scales: 2.0
        aspect_ratios: 0.5
        aspect_ratios: 1.0
        aspect_ratios: 2.0
      }
    }
    first_stage_box_predictor_conv_hyperparams {
      op: CONV
      regularizer {
        l2_regularizer {
          weight: 0.0
        }
      }
      initializer {
        truncated_normal_initializer {
          stddev: 0.009999999776482582
        }
      }
    }
    first_stage_nms_score_threshold: 0.0
    first_stage_nms_iou_threshold: 0.699999988079071
    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 {
        fc_hyperparams {
          op: FC
          regularizer {
            l2_regularizer {
              weight: 0.0
            }
          }
          initializer {
            variance_scaling_initializer {
              factor: 1.0
              uniform: true
              mode: FAN_AVG
            }
          }
        }
        use_dropout: false
        dropout_keep_probability: 1.0
        conv_hyperparams {
          op: CONV
          regularizer {
            l2_regularizer {
              weight: 0.0
            }
          }
          initializer {
            truncated_normal_initializer {
              stddev: 0.009999999776482582
            }
          }
        }
        predict_instance_masks: true
        mask_prediction_conv_depth: 2
        mask_height: 15
        mask_width: 15
      }
    }
    second_stage_post_processing {
      batch_non_max_suppression {
        score_threshold: 0.0
        iou_threshold: 0.6000000238418579
        max_detections_per_class: 100
        max_total_detections: 100
      }
      score_converter: SOFTMAX
    }
    second_stage_localization_loss_weight: 2.0
    second_stage_classification_loss_weight: 1.0
    second_stage_mask_prediction_loss_weight: 4.0
  }
}
train_config {
  batch_size: 1
  data_augmentation_options {
    random_horizontal_flip {
    }
  }
  optimizer {
    momentum_optimizer {
      learning_rate {
        manual_step_learning_rate {
          initial_learning_rate: 0.00019999999494757503
          schedule {
            step: 900000
            learning_rate: 1.9999999494757503e-05
          }
          schedule {
            step: 1200000
            learning_rate: 1.9999999949504854e-06
          }
        }
      }
      momentum_optimizer_value: 0.8999999761581421
    }
    use_moving_average: false
  }
  gradient_clipping_by_norm: 10.0
  from_detection_checkpoint: false
  num_steps: 110
}
train_input_reader {
  label_map_path: "/home/user/Data7510/GitProjects/objects-ancient/main/data/EgyptianKingName/EgyptianKingName.pbtxt"
  load_instance_masks: true
  tf_record_input_reader {
    input_path: "/home/user/Data7510/GitProjects/objects-ancient/main/data/EgyptianKingName/train/train.record"
  }
  mask_type: PNG_MASKS
}
eval_config {
  num_examples: 10
  max_evals: 10
  visualization_export_dir: "/home/user/Data7510/GitProjects/objects-ancient/main/models/EgyptianKingName/mask_rcnn_inception_v2/conf-time--2019-02-07T04:45:05--id--72b5078f-724e-4128-81bb-c8cbedc0e40c/session/visu"
  metrics_set: "pascal_voc_detection_metrics"
}
eval_input_reader {
  label_map_path: "/home/user/Data7510/GitProjects/objects-ancient/main/data/EgyptianKingName/EgyptianKingName.pbtxt"
  shuffle: false
  num_readers: 1
  load_instance_masks: true
  tf_record_input_reader {
    input_path: "/home/user/Data7510/GitProjects/objects-ancient/main/data/EgyptianKingName/eval/eval.record"
  }
  mask_type: PNG_MASKS
}

Describe the problem

The problem is in the tensorboard eval output, the bounding boxes are incorrectly placed where as the masks are correctly placed. I am guessing that this is a problem that occurs due to the random horizontal flip option in train_config. edit: I used a new config file without the random_horizontal_flip option and the result did not change. But if anyone has any other suggestions, they are welcomed as well

D-K-E avatar Feb 07 '19 04:02 D-K-E

For anyone dealing with this issue: I think I misinterpreted the tensorboard output. The masks indicate the location of the ground truth, whereas the bounding boxes probably indicate inferred detections. Still it would be great if someone from the team can confirm this is the case

D-K-E avatar Feb 13 '19 16:02 D-K-E

Are your bounding boxes normalized when you store them in the TFRecord? I am using a Mask-RCNN inception v2 and my evaluations have the correct position for the boxes in the ground truth, as well as for the masks.

Renart-fox avatar Feb 22 '19 15:02 Renart-fox

This was due to my misinterpretation of PIL's image size output, and numpy array's shape. PIL outputs width which corresponds to matrix column number of the numpy array, first, then height which is matrix row number. This is the inverse of numpy's shape output which is row first, column second. I was transposing axes whenever I was exchanging between handlers.

Once I corrected this the results were fine. But I am not sure at what stage my misinterpretation played a role to have incorrect outputs.

D-K-E avatar Feb 25 '19 00:02 D-K-E

@D-K-E Can you give more detailed answer please? PIL image size and numpy arrays in what file?

TheFlashover avatar Feb 26 '19 09:02 TheFlashover

@TheFlashover Sure. The problem was the following when you call size attribute of PIL's Image module, it gives an output like (200, 400). The 200 is for the width of the image, and 400 is for the height of the image. When you are dealing with numpy which was my library of choice for dealing with image arrays, the width of the image is represented as the matrix column, and the height of the image is represented as the matrix row. In order to see the number of columns and rows in a matrix, one calls shape attribute of an ndarray, the data structure that holds the image matrix. The output of the shape attribute starts with row number instead of column number, so it would be (400, 200) for the above example. I have read somewhere, not sure where exactly though, that during the transformation of an image instantiated as Image of PIL, to a numpy array one should transpose the axes of the resulting array to get the correct shape. However this proved to be wrong, because one can simply use the result of np.array(Image.open('path/to/image.png'), dtype=np.uint8) as is to do further processing.

D-K-E avatar Feb 26 '19 16:02 D-K-E