前言:
在目标检测的深度网络中最后一个步骤就是RoI层,其中RoI Pooling会实现将RPN提取的各种形状的边框进行池化,从而形成统一尺度的特征层,这一工程中将涉及到ROIAlign操作。Pool中的Scale是一个数组,代表原始图片变换到FPN的各个特征层需要的变换比例,比如到Stage2是1/4, 以此类推。其代码详解为:
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
import torch
import torch.nn.functional as F
from torch import nn
from maskrcnn_benchmark.layers import ROIAlign
from .utils import cat
class LevelMapper(object):
"""Determine which FPN level each RoI in a set of RoIs should map to based
on the heuristic in the FPN paper.
"""
"""
LevelMapper函数的作用是获得某个特征区域将会从网络的那一层特征上进行提取,面积越大的目标区往往会在高层进行提取,小目标则在低层卷基层
上进行特征提取。本函数的主要目标就是确定某个目标最好从那一层上进行提取。
实现FPN论文里的公式
"""
def __init__(self, k_min, k_max, canonical_scale=224, canonical_level=4, eps=1e-6):
"""
Arguments:
k_min (int)
k_max (int)
canonical_scale (int)
canonical_level (int)
eps