【MaskRCNN】用benchmark-maskrcnn训练和测试自己的数据集

项目源码:https://github.com/facebookresearch/maskrcnn-benchmark

包含faster rcnn、mask rcnn等等框架的库,非常强大。自己摸索了一下如何用自己定义的Dataset来训练。

参考资料:

介绍了一些核心py文件的作用:https://hellozhaozheng.github.io/z_post/PyTorch-MaskrcnnBenchmark-tools/

使用pytorch mask-rcnn进行目标检测/分割训练 - Slumbers的文章 - 知乎 https://zhuanlan.zhihu.com/p/57603975(最后介绍了关于重设学习率的问题)

 


使用自己的数据集训练maskrcnn需要做的几步(持续更新ing)

1. 配置环境:

参考项目里面给的步骤安装一下必要的包,具体步骤见下图:

https://github.com/facebookresearch/maskrcnn-benchmark/blob/master/INSTALL.md

配置一下很重要,据网上资料说如果maskrcnn_benchmark文件夹里的内容有更改的话还需要重新生成一下!

配置好了之后可以检测测试一下,直接写在项目第一级文件夹里就可以,例如下面demo.py(demo文件夹里需要加一个__init__.py文件,内容为空就可以,不然会报错):

from maskrcnn_benchmark.config import cfg
from demo.predictor import COCODemo
from skimage import io
import cv2

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 = io.imread('test.jpg')
predictions = coco_demo.run_on_opencv_image(image)
cv2.imshow("detect",predictions)
cv2.waitKey(0)
cv2.destroyAllWindows()

成功的话就可以看到网络输出的结果啦!

 

2. 写自己的Dataset

这里项目里面也给出了示例,形式类似下面这种:

from maskrcnn_benchmark.structures.bounding_box import BoxList

class 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 = 
  • 1
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值