SSD-MobileNetv2之获取featureMapShapes

相关参考:
Tensorflow检测API中的SSD锚定
https://github.com/tensorflow/models
安装Tensorflow Object Detection API后在models/research/object_detection下新建getFeatureMapShapes.py

import tensorflow as tf 
from object_detection.anchor_generators.multiple_grid_anchor_generator import create_ssd_anchors
from object_detection.models.ssd_mobilenet_v2_feature_extractor_tf1_test import SsdMobilenetV2FeatureExtractorTest

def get_feature_map_shapes(image_height, image_width):
    """
    :param image_height: height in pixels
    :param image_width: width in pixels
    :returns: list of tuples containing feature map resolutions
    """
    feature_extractor = SsdMobilenetV2FeatureExtractorTest()._create_feature_extractor(
        depth_multiplier=1,
        pad_to_multiple=1,
    )
    image_batch_tensor = tf.zeros([1, image_height, image_width, 1])

    return [tuple(feature_map.get_shape().as_list()[1:3])
            for feature_map in feature_extractor.extract_features(image_batch_tensor)]
print(get_feature_map_shapes(300, 300))     
例如:
# for your inputsize 300*300 [(19, 19), (10, 10), (5, 5), (3, 3), (2, 2), (1, 1)]  
# for your inputsize 512*512 [(32, 32), (16, 16), (8, 8), (4, 4), (2, 2), (1, 1)]
# for your inputsize 608*608 [(38, 38), (19, 19), (10, 10), (5, 5), (3, 3), (2, 2)]
# for your inputsize 416*416 [(26, 26), (13, 13), (7, 7), (4, 4), (2, 2), (1, 1)]
# for your inputsize 416*234 [(26, 15), (13, 8), (7, 4), (4, 2), (2, 1), (1, 1)]
# for your inputsize 608*342 [(38, 22), (19, 11), (10, 6), (5, 3), (3, 2), (2, 1)]

你可能感兴趣的:(目标检测,python,tensorflow,深度学习,SSD,MobilenetV2)