相关理解:
RCNN到fast rcnn演变的过程中,(改变rois的产生方式,根据在原图上利用选择性搜索产生的roi 和在feature map上产生roi是成比例的,所以需要一个映射的过程,这样做的原始是在feature map 产生的roi 节约了大量的时间,这是到fast rcnn 的一个进化过程)
roi pooling 本质是 roi取值产生的维度 由需要设定
fast rcnn 代替选择性行搜索使用rpn区域提议网络,因为选择性搜索浪费时间;区域提议网络的思想:利用cnn产生的feature map ,在上面每个点 会产生不同比例的anchor ,0.5 1 1.5 这个可以自行设定,在每个anchor检测是否有物体,如果有物体就为1 否0;训练阶段,这样就会产生很多anchor,通过ground truth box 和anchor的IOU值,这样测试阶段就可以预测相似大小的anchor预测相似大的物体;
faster rcnn是为单尺度网络,对物体的大小不鲁邦,因为只利用单尺度的feature map,比如层数比较多 产生的featuremap 虽然视野比较大,语言信息强 ,在这个阶段 小物体可能就是一个点,或者消失了,所以这个单尺度的网络不能高效的检测小物体
解决上述单尺度的问题,提出了很多方法:比如说 特征图像金字塔 , 金字塔特征分层(ssd上用到的),特征金字塔网络FPN(高层特征和低层特征进行融合)很好的解决这个问题
FPN:分为从底到上 从上到下 两个阶段,上采样 可以反卷积和双线性差值 反卷积比较耗时点,
mask rcnn:使用了resnet -fpn网络 通道数量减少使用1*1卷积, 3*3卷积可以有效解决混叠效应。)
fpn网络会产生4个feature map,然而在rpn区域提议网络中 产生anchor ,在哪个feature map上取特定的anchor 取决于一个公式 k=k0+log2(根号下wh/224) 这个公式写的不准确,大家自己去查询一下就好
mask branch 输入为roi 使用的全卷积网络,在每个像素进行分类,比如说产生的维度为28*28*80 80为类别数量
roi pooling 到roi align,产生anchor可能不是整数、在取特定维度的时候 也会产生小数的 ,改进的地方就是改进的地方,利用双线性插值
mask loss function定义:传统的像素点的softmax 分类,产生每个类型的概率值。mask rcnn使用的是 训练的时候,在算损失的时候只算一类,如果低于阈值则不考虑,测试的时候bbox坐标和分类,根据这个分类进行预测就可以了。例如 Bbox预测的类为dog 这里只预测dog 的概率 这样避免了类别间的竞争。
1、代码来源link :https://download.csdn.net/download/weixin_44576543/15879025
2、代码构成:
3、首先看一下 utils.py 看一下模型定义
from mrcnn import utils
#因为model中导入utils.py 先看一下工具类型 如何定义函数的
def extract_bboxes(mask): 输入为mask 提取每个实例的bbox用于训练和监督
返回 bbox
def compute_iou(box, boxes, box_area, boxes_area):
"""Calculates IoU of the given box with the array of the given boxes.
box: 1D vector [y1, x1, y2, x2]
boxes: [boxes_count, (y1, x1, y2, x2)]
box_area: float. the area of 'box'
boxes_area: array of length boxes_count.
分别输入真实和预测的bbox 和面积
输出iou
def compute_overlaps(boxes1, boxes2):
"""Computes IoU overlaps between two sets of boxes.
boxes1, boxes2: [N, (y1, x1, y2, x2)].
计算两个bbox之间的重叠
选择重叠度较高的那个bbox
def compute_overlaps_masks(masks1, masks2):
'''Computes IoU overlaps between two sets of masks.
计算mask 重叠
def non_max_suppression(boxes, scores, threshold):
"""Performs non-maximum supression and returns indicies of kept boxes.
boxes: [N, (y1, x1, y2, x2)]. Notice that (y2, x2) lays outside the box.非极大值抑制
def apply_box_deltas(boxes, deltas):
"""Applies the given deltas to the given boxes.
boxes: [N, (y1, x1, y2, x2)]. Note that (y2, x2) is outside the box.应用bbox的偏移
def box_refinement_graph(box, gt_box):
"""Compute refinement needed to transform box to gt_box.
计算bbox和真实值的差距
def box_refinement(box, gt_box):
"""Compute refinement needed to transform box to gt_box.
box and gt_box are [N, (y1, x1, y2, x2)]. (y2, x2) is
assumed to be outside the box.
"""
dataset类的数据处理包括.
def __init__(self, class_map=None):
self._image_ids = []
self.image_info = []
# Background is always the first class
self.class_info = [{"source": "", "id": 0, "name": "BG"}]
self.source_class_ids = {}
def add_class(self, source, class_id, class_name):
assert "." not in source, "Source name cannot contain a dot" 添加类 类名 类id ,背景为0 BG
def add_image
def image_reference(self, image_id):
def prepare(self, class_map=None):
def map_sourc