0

How I can implement a single shot detector with only one anchor box per feature map cell? I have used ssd mobilenet coco 2018 v1 and I have changed the anchor generator part in config file I.e num layers = 1 in ssd anchor generator. Will that be okay??

https://github.com/tensorflow/models/blob/master/research/object_detection/samples/configs/ssd_mobilenet_v1_coco.config

anchor_generator { ssd_anchor_generator { num_layers: 6 min_scale: 0.2 max_scale: 0.95 aspect_ratios: 1.0 aspect_ratios: 2.0 aspect_ratios: 0.5 aspect_ratios: 3.0 aspect_ratios: 0.3333

Machavity
  • 30,841
  • 27
  • 92
  • 100
  • Pure code-writing requests are off-topic on Stack Overflow — we expect questions here to relate to *specific* programming problems — but we will happily help you write it yourself! Tell us [what you've tried](https://stackoverflow.com/help/how-to-ask), and where you are stuck. This will also help us answer your question better. – rizerphe May 13 '20 at 07:26
  • Basically I am making changes in the ssd_mobilenet_v1 config file – user9631198 May 13 '20 at 07:34

1 Answers1

0

Changing num_layers won't help you in this case.
SSD has several detection branches - each branch derived from different feature map resolution For example - for mobilenet_v1_ssd found in TF OD API there are 6 branches.
branch 0 - 19x19
branch 1 - 10x10
branch 2 - 5x5
branch 3 - 3x3
branch 4 - 2x2
branch 5 - 1x1

So the argument - num_layers will actually change the number of branches but not the number of anchors per pixel.

In case you want to have only one anchor box per pixel you will have to change the several things (read until the end :) ):

  1. Aspect ratios - By changing the number of aspect ratios you change the number of anchors per layer. so:
    anchor_generator {
      ssd_anchor_generator {
        num_layers: 6
        min_scale: 0.2
        max_scale: 0.95
        aspect_ratios: 1.0
        aspect_ratios: 2.0
        aspect_ratios: 0.5
        aspect_ratios: 3.0
        aspect_ratios: 0.3333
      }
    }

So by removing but 1.0, for example, will leave you almost with one anchor. 2. Why almost? SSD (https://arxiv.org/abs/1512.02325), see the paper, add another anchor box with a scale of a geometric mean between current branch scale to next branch scale. So you will actually have 2 anchors per pixel for branches 1-5. In order to disable it you should change a parameter named - interpolated_scale_aspect_ratio to 0.
enter image description here
You can do it by adding this argument to the config file (see the protobuf of ssd anchors - https://github.com/tensorflow/models/blob/2ad3e213838f71e92af198d917ac5574c9d60294/research/object_detection/protos/ssd_anchor_generator.proto) so under anchor_generator add:

interpolated_scale_aspect_ratio: 0
  1. If you followed 1 and 2, you will see that you have 1 anchor per pixel per branch but for branches 1-5. But for some reason you will have 3 anchors for the first branch... This is because the first branch is getting three anchors by default. You can disable it by using the following argument:
    enter image description here
reduce_boxes_in_lowest_layer: false
Tamir Tapuhi
  • 406
  • 3
  • 8