SSD-MobileNetv2之获取featureMapShapes

该博客介绍了如何在Tensorflow Object Detection API中使用SSD锚框(SSD anchors)来获取不同尺度的特征图形状。通过示例代码展示了针对不同输入尺寸(如300x300, 512x512, 608x608, 416x416, 416x234, 608x342)的特征图分辨率。这对于理解和优化目标检测模型的性能至关重要。
摘要由CSDN通过智能技术生成

相关参考:
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)]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值