用Mask-RCNN训练自定义大小的数据集

一、目前情况
用Mask-RCNN训练自己的数据集时,需要制定图片的长度和宽度,即

IMAGE_MIN_DIM = 448
IMAGE_MAX_DIM = 640
而在Mask_RCNN/mrcnn目录下model.py文件中第1815行到1819行代码

h, w = config.IMAGE_SHAPE[:2]
        if h / 2**6 != int(h / 2**6) or w / 2**6 != int(w / 2**6):
            raise Exception("Image size must be dividable by 2 at least 6 times "
                            "to avoid fractions when downscaling and upscaling."
                            "For example, use 256, 320, 384, 448, 512, ... etc. ")
需要将图像处理成指定长宽比例的图像然后才可以用于训练,并且训练集中的图像需要长度和宽度都需一致。

若训练集中的图像有长度和宽度不同时则不能训练,这样极不方便。

二、更改Mask-RCNN代码
在训练数据集的代码train_shapes.ipynb中,在load_shapes()中添加更改代码:

for i in range(count):
            # 获取图片宽和高
            filestr = imglist.split(".")[0]
            mask_path = mask_floder + "/" + filestr + ".png"
            yaml_path = dataset_root_path + "total/" + filestr + "_json/info.yaml"
            print(dataset_root_path + "total/" + filestr + "_json/img.png")
            cv_img = cv2.imread(dataset_root_path + "total/" + filestr + "_json/img.png")

            self.add_image("shapes", image_id=i, path=img_floder + "/" + imglist,
                           width=cv_img.shape[1], height=cv_img.shape[0],
                           mask_path=mask_path, yaml_path=yaml_path)
在代码中

width=cv_img.shape[1], height=cv_img.shape[0]
便是自动获取图像的长度和宽度。

三、处理图像
        在train_shapes.ipynb代码中可以自动获取图片的长度和宽度,但是若需要将长度和宽度大小不一致的图像分别规范到一样大小,则可用python处理,代码可以参见之前的博客:

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值