重磅资源|Pytorch1.0版本的Mask R-CNN的Facebook的官方实现
【导读】Facebook刚刚放出的基于Pytorch1.0版本的Faster R-CNN,Mask R-CNN的benchmark,比detectron更快,准确率更高。
项目地址:
https://github.com/facebookresearch/maskrcnn-benchmark
Faster R-CNN and Mask R-CNN in PyTorch 1.0
这个项目目的是为使用Pytorch1.0的用户提供一个简单的搭建检测和分割模型的必要的底层模块。
要点
网络摄像头和 Jupyter notebook的demo
我们提供了简单的网络摄像头的demo,为你演示如何使用maskrcnn_benchmark
进行推理:
cd demo# by default, it runs on the GPU# for best results, use min-image-size 800python webcam.py --min-image-size 800# can also run it on the CPUpython webcam.py --min-image-size 300 MODEL.DEVICE cpu# or change the model that you want to usepython webcam.py --config-file ../configs/caffe2/e2e_mask_rcnn_R_101_FPN_1x_caffe2.py --min-image-size 300 MODEL.DEVICE cpu# in order to see the probability heatmaps, pass --show-mask-heatmapspython webcam.py --min-image-size 300 --show-mask-heatmaps MODEL.DEVICE cpu# by default, it runs on the GPU
# for best results, use min-image-size 800
python webcam.py --min-image-size 800
# can also run it on the CPU
python webcam.py --min-image-size 300 MODEL.DEVICE cpu
# or change the model that you want to use
python webcam.py --config-file ../configs/caffe2/e2e_mask_rcnn_R_101_FPN_1x_caffe2.py --min-image-size 300 MODEL.DEVICE cpu
# in order to see the probability heatmaps, pass --show-mask-heatmaps
python webcam.py --min-image-size 300 --show-mask-heatmaps MODEL.DEVICE cpu
这个demo在 demo/Mask_R-CNN_demo.ipynb可以找到。
安装
查看 INSTALL.md 的安装指令。
模型库和基线版本
预训练模型,基线版本以及和Detectron和mmdetection的对比在MODEL_ZOO.md中。
几行代码实现推理
我们提供了一个帮助类来简化使用预训练模型实现推理的pipline。下面是如何实现,可以在 demo
文件夹中运行:
from maskrcnn_benchmark.config import cfgfrom predictor import COCODemoconfig_file = "../configs/caffe2/e2e_mask_rcnn_R_50_FPN_1x_caffe2.yaml"# update the config options with the config filecfg.merge_from_file(config_file)# manual override some optionscfg.merge_from_list(["MODEL.DEVICE", "cpu"])coco_demo = COCODemo( cfg, min_image_size=800, confidence_threshold=0.7,)# load image and then run predictionimage = ...predictions = coco_demo.run_on_opencv_image(image)config_file = "../configs/caffe2/e2e_mask_rcnn_R_50_FPN_1x_caffe2.yaml"# update the config options with the config file
cfg.merge_from_file(config_file)
# manual override some options
cfg.merge_from_list(["MODEL.DEVICE", "cpu"])coco_demo = COCODemo(cfg,min_image_size=800,confidence_threshold=0.7,
)
# load image and then run prediction
image = ...
predictions = coco_demo.run_on_opencv_image(image)
在COCO数据集上训练的表现
需要先安装 maskrcnn_benchmark
,后面的例子才能运行。
需要先下载COCO数据集。我们推荐将coco数据集的软链接放到datasets/
里,如下:
我们使用 Detectron中的 minival
and valminusminival
设置
# symlink the coco datasetcd ~/github/maskrcnn-benchmarkmkdir -p datasets/cocoln -s /path_to_coco_dataset/annotations datasets/coco/annotationsln -s /path_to_coco_dataset/train2014 datasets/coco/train2014ln -s /path_to_coco_dataset/test2014 datasets/coco/test2014ln -s /path_to_coco_dataset/val2014 datasets/coco/val2014
cd ~/github/maskrcnn-benchmark
mkdir -p datasets/coco
ln -s /path_to_coco_dataset/annotations datasets/coco/annotations
ln -s /path_to_coco_dataset/train2014 datasets/coco/train2014
ln -s /path_to_coco_dataset/test2014 datasets/coco/test2014
ln -s /path_to_coco_dataset/val2014 datasets/coco/val2014
你也可以自己设置数据集的路径。那样的话,你需要修改maskrcnn_benchmark/config/paths_catalog.py
指向你自己的数据集. 你也可以创建一个新的 paths_catalog.py
实现同样的两个类,然后在训练的时候作为一个配置参数传到 PATHS_CATALOG
中。
单GPU训练
python /path_to_maskrnn_benchmark/tools/train_net.py --config-file "/path/to/config/file.yaml""/path/to/config/file.yaml"
多GPU训练
我们使用内置的 torch.distributed.launch
实现多GPU的训练。.这个Pytorch中的函数会创建和我们需要使用的GPU数量一样多的进程,每个Python进程使用一个GPU。
export NGPUS=8python -m torch.distributed.launch --nproc_per_node=$NGPUS /path_to_maskrcnn_benchmark/tools/train_net.py --config-file "path/to/config/file.yaml"
python -m torch.distributed.launch --nproc_per_node=$NGPUS /path_to_maskrcnn_benchmark/tools/train_net.py --config-file "path/to/config/file.yaml"
摘要
更多的我们的实现相关的摘要信息,见 ABSTRACTIONS.md.
增加你自己的数据集
这个实现增加了对COCO风格的数据集的支持。在训练时增加新的数据集的支持需要像下面这样做:
from maskrcnn_benchmark.structures.bounding_box import BoxListclass MyDataset(object): def __init__(self, ...): # as you would do normally def __getitem__(self, idx): # load the image as a PIL Image image = ... # load the bounding boxes as a list of list of boxes # in this case, for illustrative purposes, we use # x1, y1, x2, y2 order. boxes = [[0, 0, 10, 10], [10, 20, 50, 50]] # and labels labels = torch.tensor([10, 20]) # create a BoxList from the boxes boxlist = BoxList(boxes, size=image.size, mode="xyxy") # add the labels to the boxlist boxlist.add_field("labels", labels) if self.transforms: image, boxlist = self.transforms(image, boxlist) # return the image, the boxlist and the idx in your dataset return image, boxlist, idx def get_img_info(self, idx): # get img_height and img_width. This is used if # we want to split the batches according to the aspect ratio # of the image, as it can be more efficient than loading the # image from disk return {"height": img_height, "width": img_width}
class MyDataset(object):def __init__(self, ...):# as you would do normallydef __getitem__(self, idx):# load the image as a PIL Imageimage = ...# load the bounding boxes as a list of list of boxes# in this case, for illustrative purposes, we use# x1, y1, x2, y2 order.boxes = [[0, 0, 10, 10], [10, 20, 50, 50]]# and labelslabels = torch.tensor([10, 20])# create a BoxList from the boxesboxlist = BoxList(boxes, size=image.size, mode="xyxy")# add the labels to the boxlistboxlist.add_field("labels", labels)if self.transforms:image, boxlist = self.transforms(image, boxlist)# return the image, the boxlist and the idx in your datasetreturn image, boxlist, idxdef get_img_info(self, idx):# get img_height and img_width. This is used if# we want to split the batches according to the aspect ratio# of the image, as it can be more efficient than loading the# image from diskreturn {"height": img_height, "width": img_width}
内容就是这些。你也可以在boxlist中增加额外的字段,例如分割的掩模(使用structures.segmentation_mask.SegmentationMask
), 或者你自己的实例类型。
完整的如何实现 COCODataset
的例子,参见 maskrcnn_benchmark/data/datasets/coco.py
.
注意:
上面提到的例子是训练用的,我们还利用cocoApi来计算测试时的准确率,测试数据集目前需要按照cocoApi的要求。
License
maskrcnn-benchmark is released under the MIT license. See LICENSE for additional details.
重磅资源|Pytorch1.0版本的Mask R-CNN的Facebook的官方实现相关推荐
- 最新翻译的官方PyTorch简易入门教程(PyTorch1.0版本)
"PyTorch 深度学习:60分钟快速入门"为PyTorch官网教程,网上已经有部分翻译作品,随着PyTorch1.0版本的公布,这个教程有较大的代码改动,本人对教程进行重新翻译 ...
- faster-rcnn.pytorch-1.0的jwyang当前最火版本代码复现与讲解
文章目录 一.faster-rcnn.pytorch-1.0 1.下载代码与权重文件 2.先安装所有环境 3.相关库函数版本以及安装 4.创建软连接 5.编译CUDA依赖环境 6.改bug 7.训练 ...
- 华为云AOM 2.0版本发布
摘要:AOM作为华为云面向租户的统一运维门户,将在7月1日重磅发布2.0版本. 本文分享自华为云社区<华为云AOM发布2.0版本,3大特性亮相>,作者:华为云PaaS小助手. 6月16日华 ...
- OpenKruise v0.9.0 版本发布:新增 Pod 重启、删除防护等重磅功能
作者 | 王思宇(酒祝) Photo Creidt@ 王思宇(酒祝) 背景 OpenKruise 是阿里云开源的云原生应用自动化管理套件,也是当前托管在 Cloud Native Computin ...
- 重磅丨云和恩墨zCloud数据库云管平台2.0版本发布
重磅丨云和恩墨zCloud数据库云管平台2.0版本发布 7月,大家可能正在忍受着酷暑天气,或者在暴雨中奔走,但不变的是DBA对用户数据库及数据保障依然十分关心.在此期间,云和恩墨发布了zCloud数据 ...
- 要闻君说:重磅!阿里巴巴发布了机器学习平台PAI 3.0版本;厉害!三星推出了业界首款HBM2E内存;Google也做云游戏平台...
关注并标星星CSDN云计算 每周三次,打卡即read 更快.更全了解泛云圈精彩news go go go 偶是要闻君.最近圈儿内的大型活动真是挤满台历,例如阿里云一年一度的大峰会,这不就在北京开上了! ...
- springboot2.0版本后配置拦截器会导致静态资源被拦截
转载:https://blog.csdn.net/wangfuxu14/article/details/80670648 springboot2.0版本后配置拦截器会导致静态资源被拦截 解决办法: 分 ...
- R︱Rstudio 1.0版本尝鲜(R notebook、下载链接、sparkR、代码时间测试profile)
每每以为攀得众山小,可.每每又切实来到起点,大牛们,缓缓脚步来俺笔记葩分享一下吧,please~ --------------------------- 2016年11月1日,RStudio 1.0版 ...
- 配置faster-rcnn pytorch1.0.0版本实现faster R-CNN
在GitHub - jwyang/faster-rcnn.pytorch at pytorch-1.0下载项目. (切记:一定是1.0分支下,不是master主分支下,因为只有1.0分支下才支持pyt ...
最新文章
- Datawhale赛事大满贯来了!
- centos卸载harbor_【Harbor】Harbor镜像仓库的安装与历史版本镜像的清理
- 我在兰亭这三年之第一个项目
- Hibernate.cfg.xml配置文件结构详解
- OpenCV使用VideoWriter和VideoCapture的实例(附完整代码)
- node --- 游走在客户端和服务器间的http
- 安装并配置ROS环境
- java stream 多个filter_如何在Java Stream上应用多个过滤器?
- matlab std函数_如何利用Matlab进行小波分析
- BZOJ2689 : 堡垒
- 解决微信小程序开发中wxss中不能用本地图片
- Zend Studio12.0配置Xdebug
- android设计个人简历页面_Android程序员个人简历模板下载(Word格式)
- EXCEL实战技巧与数据分析(二)数据透视表
- 硬盘分区表故障和丢失的原因
- Python 支付宝红包二维码制作步骤分享
- MapReduce中文版论文
- android 支持最低版本是多少g,手机需要多少G的运行内存,才真正够用?
- 数学建模更新13(MATLAB绘制三维图【上】)
- 日常学习记录——目前学习记录总结
热门文章
- boost::type_index模块实现一个类型中获得简短的和人类可读的类型名称
- boost::mpl模块实现copy_if相关的测试程序
- boost::locale::calendar用法的测试程序
- boost::gil模块实现cmyka转rgba的测试程序
- Boost:双图和boost assign的测试程序
- Boost:传输文件的测试程序
- ITK:在向量容器上迭代
- DCMTK:搜索助手类的测试程序
- VTK:Texture之TextureCutSphere
- VTK:Picking之HighlightWithSilhouette