Mask_RCNN学习记录(matterport版本)
资源链接
- Mask R-CNN论文
- matterport版本的GitHub 基于Keras和Tensorflow,关于程序的安装与使用,readme文件中写得很清楚
- GitHub上还有Facebook的官方实现版本:Detectron maskrcnn-benchmark
安装
- 参考matterport版本的GitHub的README.md中requirements
- 另外如果要在MS COCO数据集上训练、测试,还需pycocotools
相关博客
学习Mask RCNN网络结构,并构建颜色填充器应用
该版本以ResNet101 + FPN为backbone,heads包括检测和Mask预测两部分,其中检测部分包括类别预测和bbox回归。
English Version 中文版
网络介绍
Mask R-CNN是用于实例分割和目标检测的,在目标检测网络Faster R-CNN基础上增加Mask预测分支

(图片来源:https://blog.csdn.net/linolzhang/article/details/71774168)
Mask RCNN改进
- Mask Scoring R-CNN: 给Mask也打个分
- Faster Training of Mask R-CNN by Focusing on Instance Boundaries: 利用实例边缘信息加速训练:训练过程中,对预测的Mask和GT的Mask进行边缘检测,计算两者的均方误差(Mean Square Error, MSE),将其作为损失函数的一部分(我把Paper中Edge Argument Head简单实现了)。我个人理解是:该文章更多是加速了网络训练的速度,因此精度有一定的提高(在训练过程中用边缘信息指明了一条道路,因此在梯度下降的过程中快了一些)
Code is Here: 点击查看详细内容
在mrcnn/model.py中添加edge_loss函数项
def mrcnn_edge_loss_graph(target_masks, target_class_ids, pred_masks):
"""Edge L2 loss for mask edge head
target_masks: [batch, num_rois, height, width].
A float32 tensor of Value 0 or 1(boolean?). Use zero padding to fill array
target_class_ids: [batch, num_rois]. Integer class IDs. Zeros padded.
pred_masks: [batch, proposal, height, width, num_classes] float32 tensor
with value from 0 to 1(soft mask)(more information)
"""
# Reshape for simplicity. Merge first two dimensions into one
# 即将batch 和 num_rois 合并为一项
target_class_ids = K.reshape(target_class_ids, (-1,))
mask_shape = tf.shape(target_masks)
target_masks = K.reshape(target_masks, (-1, mask_shape[2], mask_shape[3]))
pred_shape = tf.shape(pred_masks)
pred_masks = K.reshape(pred_masks,
(-1, pred_shape[2], pred_shape[3], pred_shape[4]))
#Permute predicted masks to [N, num_classes, height, width]
pred_masks = tf.transpose(pred_masks, [0, 3, 1, 2])
# Only positive ROIs contribute to the loss. (正的ROI是相对BG而言吗)
# And only the class specific mask of each ROI
# tf.where 获得索引值
# tf.gather 根据索引值从张量中获得元素构成新张量Tensor
# tf.cast 类型转换
# tf.stack
positive_ix = tf.where(target_class_ids > 0)[:, 0]
positive_class_ids = tf.cast(
tf.gather(target_class_ids, positive_ix), tf.int64)
indices = tf.stack([positive_ix, positive_class_ids], axis=1)
# Gather the masks (predicted and true) that contribute to loss
y_true = tf.gather(target_masks, positive_ix)
y_pred = tf.gather_nd(pred_masks, indices)
# shape: [batch * rois, height, width, 1]
y_true = tf.expand_dims(y_true, -1)
y_pred = tf.expand_dims(y_pred, -1)
y_true = 255 * y_true
y_pred = 255 * y_pred
# shape: [3, 3, 1, 2]
sobel_kernel = tf.constant([[[[1, 1]], [[0, 2]], [[-1, 1]]],
[[[2, 0]], [[0, 0]], [[-2, 0]]],
[[[1,-1]], [[0,-2]], [[-1,-1]]]], dtype=tf.float32)
# Conv2D with kernel
edge_true = tf.nn.conv2d(y_true, sobel_kernel, strides=[1, 1, 1, 1], padding="SAME")
edge_pred = tf.nn.conv2d(y_pred, sobel_kernel, strides=[1, 1, 1, 1], padding="SAME")
# abs and clip
edge_true = tf.clip_by_value(abs(edge_true), 0, 255)
edge_pred = tf.clip_by_value(abs(edge_pred), 0, 255)
# Mean Square Error(MSE) Loss
return tf.reduce_mean(tf.square(edge_true/255. - edge_pred/255.))</code> </pre>
说明
- Keras中fit函数中,每个Epoch训练的数目是 batch_size × steps per epoch,故每个Epoch不一定是把整个train_set全部训练一遍。原帖子
- 使用conda install命令安装tensorflow-gpu教程
- 如果用不习惯.ipynb文件,可以用Jupyter NoteBook将其保存为.py文件
命令行输入jupyter notebook启动,打开文件后Download as Python(.py) - 另外,感觉有一个idea还是不够的,而且还要做充分的实验进行验证(比如说为什么边缘检测用的是Sobel,而是Laplace或是Canny)(又有点实践指导理论的意思。。。)。
- 最后,欢迎批评指正!
Mask_RCNN学习记录(matterport版本)的更多相关文章
- Java 静态内部类与非静态内部类 学习记录.
目的 为什么会有这篇文章呢,是因为我在学习各种框架的时候发现很多框架都用到了这些内部类的小技巧,虽然我平时写代码的时候基本不用,但是看别人代码的话至少要了解基本知识吧,另外到底内部类应该应用在哪些场合 ...
- Python学习记录day6
title: Python学习记录day6 tags: python author: Chinge Yang date: 2016-12-03 --- Python学习记录day6 @(学习)[pyt ...
- AndroidStudio学习记录
AndroidStudio学习记录 1. 插件的使用. plugins.jetbrains.com插件网站. 2. 目录介绍: 1.Studio中有Project和Module的概念,前面说到Stud ...
- 开源项目Material Calendar View 学习记录 (一)
开源项目Material Calendar View 学习记录 Github: https://github.com/prolificinteractive/material-calendarview ...
- Vue学习记录第一篇——Vue入门基础
前面的话 Vue中文文档写得很好,界面清爽,内容翔实.但文档毕竟不是教程,文档一上来出现了大量的新概念,对于新手而言,并不友好.个人还是比较喜欢类似于<JS高级程序设计>的风格,从浅入深, ...
- 我的Spring学习记录(四)
虽然Spring管理这我们的Bean很方便,但是,我们需要使用xml配置大量的Bean信息,告诉Spring我们要干嘛,这还是挺烦的,毕竟当我们的Bean随之增多的话,xml的各种配置会让人很头疼. ...
- ElasticSearch 学习记录之 分布式文档存储往ES中存数据和取数据的原理
分布式文档存储 ES分布式特性 屏蔽了分布式系统的复杂性 集群内的原理 垂直扩容和水平扩容 真正的扩容能力是来自于水平扩容–为集群添加更多的节点,并且将负载压力和稳定性分散到这些节点中 ES集群特点 ...
- Git学习记录--git仓库
Git是一款强大的版本控制工具,与svn相比git的分布式提交,本地仓库等在使用时确实比较方便.当然两者之间各有优劣,我在这里不多做比较.由于之前少有接触git,只是零星大致地了解一点,所以找时间系统 ...
- java开源项目之IQQ学习记录之项目环境搭建与启动
本文链接地址:http://blog.csdn.net/sushengmiyan/article/details/18779727 作者:sushengmiyan 现在就码字说说今天晚上搞定的一个项目 ...
随机推荐
- 2018-2019 ACM-ICPC, Asia East Continent Finals I. Misunderstood … Missing(dp)
题目链接: http://codeforces.com/gym/102056/problem/I 题意: 人物有l两个属性分别是$A,D$ 每个回合人物$A\pm D$ 每个回合有三个选择分别是: 1 ...
- zoj 3601
链接 [https://vjudge.net/contest/293343#problem/B] 题意 就是n男m女.然后给出他们喜欢那些人 再给出q次询问 每次参加party的人 让你找出某个人满足 ...
- 解决android studio引用远程仓库下载慢(JCenter下载慢)
使用开源中国的maven库 阿里云的(速度飞快):http://maven.aliyun.com/nexus/content/groups/public/ 替换项目根目录下build.gradle中的 ...
- CSS3 border-radius 圆角
圆角border-radius,其css如下 IE9+支持(就是ie6,ie7,ie8都不支持),默认值是0,不继承,可以像下面那样设置4个角的值,也可以单独设置,如 border-top-left- ...
- vue-cli3相关
此时做的一个vue-cli3项目build后,app.js达到了10M,主要为elementui.quill等组件: 最开始使用“compression-webpack-plugin”插件根据网上的说 ...
- Add AI feature to Xamarin.Forms app
Now, AI is one of important technologies.Almost all platforms have API sets of AI. Following list is ...
- 读取导入csv csv报错iterable expected, not float
示例代码import pandas as pdimport reimport csv data = pd.read_csv('nuojia.csv', encoding='utf-8')# print ...
- [BJOI2019]排兵布阵——分组背包
题目链接: [BJOI2019]排兵布阵 对于每座堡垒,将$s$个对手排序,显然如果安排的兵力能打败第$i$个对手就一定能打败前$i-1$个. 那么对于第$i$座城堡,可以看做有$s+1$个物品(可以 ...
- Apache POI 示例
Apache POI 3.17 Javadocs 用Java编写的免费开源的跨平台的 Java API,Apache POI提供API给Java程式对Microsoft Office(Excel.WO ...
- 关于ajax 进行post提交 json数据到controller
首选需要参考的两个博客: www.cnblogs.com/Benjamin/archive/2013/09/11/3314576.html http://www.cnblogs.com/quanyon ...