maskrcnn_benchmark理解记录——modeling\roi_heads\keypoint_head\loss.py

本文详细记录了在maskrcnn_benchmark库中,针对模型的roi_heads关键点头部(loss.py)的实现和损失计算过程,深入探讨关键点检测任务中的损失函数及其在深度学习模型训练中的作用。
这里是keypoint的label的处理和损失计算

1.Matcher 
返回matches (Tensor[int64]):
其中N[i]在gt中[0,M-1]中有匹配返回N张量,,或者预测i不能匹配,返回负值。可以根据是张量还是负值简单判断是否匹配
    该类为每个预测的“element”(例如,框)分配ground-truth元素。 每个预测元素将具有正好零或一个匹配; 
    每个ground-truth元素可以被分配给零个或多个预测元素。
    匹配基于MxN match_quality_matrix,其表征每个(ground-truth, predicted)对的匹配程度。 
    例如,如果元素是框,则矩阵可以包含框IoU重叠值。
    匹配器返回大小为N的张量,其包含与预测n匹配的ground-truth元素m的索引。 如果没有匹配项,则返回负值。

2.BalancedPositiveNegativeSampler 用于平衡正负样本比例的 一般是1:3,这里是1:4
记录下参数:            
1)MODEL.ROI_HEADS.BATCH_SIZE_PER_IMAGE = 512 是每张图片选择的element数
 RoI minibatch size *per image* (number of regions of interest [ROIs])
 每个训练的minibatch的总RoIs=TRAIN.BATCH_SIZE_PER_IM * TRAIN.IMS_PER_BATCH
 TRAIN.IMS_PER_BATCH=2    #E.g., 1 gpu 512*2*1=1024
 TRAIN.IMS_PER_BATCH=images per batch*GPU一般为 IMS_PER_BATCH=2*num_gpu
 那其实TRAIN.IMS_PER_BATCH是设定的(一般一个gpu对应2),gpu是已知的,来但反向计算images per batch=2

2)MODEL.ROI_HEADS.POSITIVE_FRACTION = 0.25  每个batch中正样本/elements的比例
RoI minibatch的目标分数高于0.25标记为前景(即class> 0)

3.loss_evaluator = KeypointRCNNLossComputation(matcher, fg_bg_sampler, resolution)

import torch
from torch.nn import functional as F

from maskrcnn_benchmark.modeling.matcher import Matcher

from maskrcnn_benchmark.modeling.balanced_positive_negative_sampler import (
    BalancedPositiveNegativeSampler,
)
from maskrcnn_benchmark.structures.boxlist_ops import boxlist_iou
from maskrcnn_benchmark.modeling.utils import cat
from maskrcnn_benchmark.layers import smooth_l1_loss
from maskrcnn_benchmark.structures.boxlist_ops import cat_boxlist

from maskrcnn_benchmark.structures.keypoint import keypoints_to_heat_map


def project_keypoints_to_heatmap(keypoints, proposals, discretization_size):
    proposals = p
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值