博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
gluoncv rpn 正负样本
阅读量:5336 次
发布时间:2019-06-15

本文共 2415 字,大约阅读时间需要 8 分钟。

https://github.com/dmlc/gluon-cv/blob/master/gluoncv/model_zoo/rpn/rpn_target.py

def forward(self, ious):        """RPNTargetSampler is only used in data transform with no batch dimension.        Parameters        ----------        ious: (N, M) i.e. (num_anchors, num_gt).        Returns        -------        samples: (num_anchors,) value 1: pos, -1: neg, 0: ignore.        matches: (num_anchors,) value [0, M).        """        matches = mx.nd.argmax(ious, axis=1)        # samples init with 0 (ignore)        ious_max_per_anchor = mx.nd.max(ious, axis=1)        samples = mx.nd.zeros_like(ious_max_per_anchor)        # set argmax (1, num_gt)        ious_max_per_gt = mx.nd.max(ious, axis=0, keepdims=True)        # ious (num_anchor, num_gt) >= argmax (1, num_gt) -> mark row as positive        mask = mx.nd.broadcast_greater(ious + self._eps, ious_max_per_gt)        # reduce column (num_anchor, num_gt) -> (num_anchor)        mask = mx.nd.sum(mask, axis=1)        # row maybe sampled by 2 columns but still only matches to most overlapping gt        samples = mx.nd.where(mask, mx.nd.ones_like(samples), samples)        # set positive overlap to 1        samples = mx.nd.where(ious_max_per_anchor >= self._pos_iou_thresh,                              mx.nd.ones_like(samples), samples)        # set negative overlap to -1        tmp = (ious_max_per_anchor < self._neg_iou_thresh) * (ious_max_per_anchor >= 0)        samples = mx.nd.where(tmp, mx.nd.ones_like(samples) * -1, samples)        # subsample fg labels        samples = samples.asnumpy()        num_pos = int((samples > 0).sum())        if num_pos > self._max_pos:            disable_indices = np.random.choice(                np.where(samples > 0)[0], size=(num_pos - self._max_pos), replace=False)            samples[disable_indices] = 0  # use 0 to ignore        # subsample bg labels        num_neg = int((samples < 0).sum())        # if pos_sample is less than quota, we can have negative samples filling the gap        max_neg = self._num_sample - min(num_pos, self._max_pos)        if num_neg > max_neg:            disable_indices = np.random.choice(                np.where(samples < 0)[0], size=(num_neg - max_neg), replace=False)            samples[disable_indices] = 0        # convert to ndarray        samples = mx.nd.array(samples, ctx=matches.context)        return samples, matches

 

转载于:https://www.cnblogs.com/TreeDream/p/10192410.html

你可能感兴趣的文章
他山之石:加载图片的一个小问题
查看>>
shell - 常识
查看>>
mssql sqlserver 使用sql脚本 清空所有数据库表数据的方法分享
查看>>
分层图最短路【bzoj2763】: [JLOI2011]飞行路线
查看>>
linux下编译复数类型引发的错误:expected unqualified-id before '(' token
查看>>
codeforces 1041A Heist
查看>>
字典常用方法
查看>>
Spring Cloud Stream消费失败后的处理策略(三):使用DLQ队列(RabbitMQ)
查看>>
bzoj1048 [HAOI2007]分割矩阵
查看>>
Java中的编码
查看>>
PKUWC2018 5/6
查看>>
As-If-Serial 理解
查看>>
洛谷P1005 矩阵取数游戏
查看>>
在Silverlight中使用HierarchicalDataTemplate为TreeView实现递归树状结构
查看>>
无线通信基础(一):无线网络演进
查看>>
如何在工作中快速成长?阿里资深架构师给工程师的10个简单技巧
查看>>
WebSocket 时时双向数据,前后端(聊天室)
查看>>
关于python中带下划线的变量和函数 的意义
查看>>
linux清空日志文件内容 (转)
查看>>
安卓第十三天笔记-服务(Service)
查看>>