tensorflow / models

Models and examples built with TensorFlow
Other
77.22k stars 45.75k forks source link

SSD anchors in Tensorflow detection API #7536

Open wulungching opened 5 years ago

wulungching commented 5 years ago

System information

Describe the problem Default SSD_mobilenet_V2_config is below.

anchor_generator {
  ssd_anchor_generator {
    num_layers: 6
    min_scale: 0.2
    max_scale: 0.9
    aspect_ratios: 1.0
    aspect_ratios: 2.0
    aspect_ratios: 0.5
    aspect_ratios: 3.0
    aspect_ratios: 0.33
    }
}
image_resizer {
      fixed_shape_resizer {
        height: 300
        width: 300
      }
}

If I set image_resizer {width:600, height:450} (4:3 input size), would base_anchor_size be set square or rectangle? link

image_resizer {
      fixed_shape_resizer {
        height: 450
        width: 600
      }
}

I trace the ssd_anchor_create func code, it seems to set rectangle-like base_anchor_size, right?

    min_im_shape = tf.minimum(im_height, im_width)
    scale_height = min_im_shape / im_height
    scale_width = min_im_shape / im_width
    base_anchor_size = [
        scale_height * self._base_anchor_size[0],
        scale_width * self._base_anchor_size[1]
    ]

I want to ask how could I set specific size of anchor box for each layer? How to check details of anchor bboxes after training model? Thanks a lot

tensorflowbutler commented 5 years ago

Thank you for your post. We noticed you have not filled out the following field in the issue template. Could you update them if they are relevant in your case, or leave them as N/A? Thanks. What is the top-level directory of the model you are using Bazel version Exact command to reproduce

wulungching commented 5 years ago

Thank you for your post. We noticed you have not filled out the following field in the issue template. Could you update them if they are relevant in your case, or leave them as N/A? Thanks. What is the top-level directory of the model you are using Bazel version Exact command to reproduce

Sorry I forgot this, I used mobileNetV2 SSD of object_detection API.

netanel-s commented 5 years ago

Note that you have two more parameters in the config file that can help you out: base_anchor_height, base_anchor_weight (both with default of 1.0). _base_anchors_size consists of these two. If I'm not wrong, the fact that you have the same base_anchor_height and base_anchor_width would mean that the resulting anchors (with aspect_ratio=1) would be square. For example, in your case, the resulting base_anchor_size would be [1.0, 0.75], which relative to image of (450, 600) exactly means that the base anchor is square.

If you want to specify yourself anchor scale for each layer, then you shouldn't use ssd_anchor_generator (which sets scales linearly), use grid_anchor_generator instead.

wulungching commented 5 years ago

Hi @netanel-s , Thanks for your reply. I have some confusions about config setting,

    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
        base_anchor_height: 1.0
        base_anchor_width: 0.75
      }
    }
    image_resizer {
      fixed_shape_resizer {
        height: 450
        width: 600
      }
    }

If I set above config, would ssd_anchor_generator generate square anchor box (n pixels x n pixels) ? I am not sure how to set configuration of detector, if the above setting has mistakes please correct me. Thanks.

hochthom commented 4 years ago

The function description of ssd_anchor_generator says:

base_anchor_size: base anchor size as [height, width]. The height and width values are normalized to the minimum dimension of the input height and width, so that when the base anchor height equals the base anchor width, the resulting anchor is square even if the input image is not square.

From this I guess the above config would not generate a squared base anchor.