tensorflow:使用mask-RCNN训练自己的数据集

一:所需环境
numpy
scipy
Pillow
cython
matplotlib
scikit-image
tensorflow>=1.3.0
keras>=2.0.8
opencv-python
h5py
imgaug
IPython[all]

快速安装tensorflow-gpu链接:
https://blog.csdn.net/m0_49100031/article/details/119534426?spm=1001.2014.3001.5502

二:准备数据
labelme数据标注工具安装,这个网上一堆教程
使用labelme标注完以后是json格式的文件,需要把json格式的文件批量转换。
目录下只留一个名字为json的文件夹即可,会生成四个文件夹:cv2_mask, labelme_sjon ,pic, json
批量转换代码:

import json
import os
import os.path as osp
import warnings
from shutil import copyfile
import PIL.Image
import yaml
from labelme import utils
import time


def main():
    json_file = r'D:\2021年技术积累\mask-rcnn分割\train_data\json'

    list = os.listdir(json_file)
    if not os.path.exists(json_file + '/' + 'pic'):
        os.makedirs(json_file + '/' + 'pic')
    if not os.path.exists(json_file + '/' + 'cv_mask'):
        os.makedirs(json_file + '/' + 'cv_mask')
    if not os.path.exists(json_file + '/' + 'labelme_json'):
        os.makedirs(json_file + '/' + 'labelme_json')
    if not os.path.exists(json_file + '/' + 'json'):
        os.makedirs(json_file + '/' + 'json')

    for i in range(0, len(list)):

        path = os.path.join(json_file, list[i])
        if os.path.isfile(path):

            copyfile(path, json_file + '/json/' + list[i])
            data = json.load(open(path))
            img = utils.img_b64_to_arr(data['imageData'])
            lbl, lbl_names = utils.labelme_shapes_to_label(img.shape, data['shapes'])

            captions = ['%d: %s' % (l, name) for l, name in enumerate(lbl_names)]
            lbl_viz = utils.draw_label(lbl, img, captions)
            out_dir = osp.basename(list[i]).replace('.', '_')
            out_dir = osp.join(osp.dirname(list[i]), out_dir)

            filename = out_dir[:-5]

            out_dir = json_file + "/" + 'labelme_json' + "/" + out_dir
            out_dir1 = json_file + "/" + 'pic'
            out_dir2 = json_file + "/" + 'cv_mask'

            if not osp.exists(out_dir):
                os.mkdir(out_dir)

            PIL.Image.fromarray(img).save(osp.join(out_dir, 'img' + '.png'))
            PIL.Image.fromarray(img).save(osp.join(out_dir1, str(filename) + '.png'))

            utils.lblsave(osp.join(out_dir, 'label.png'), lbl)
            utils.lblsave(osp.join(out_dir2, str(filename) + '.png'), lbl)

            PIL.Image.fromarray
  • 1
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
Mask R-CNN是一种基于Faster R-CNN的端到端的目标检测和实例分割模型,可以同时完成目标检测和实例分割任务。如果你想使用Mask R-CNN训练自己的数据集,可以按照以下步骤进行: 1. 收集数据集 首先,你需要收集足够的数据集训练模型。数据集应包括足够数量的图像和其相应的标签,包括每个目标的位置和类别。你可以使用各种图像标注工具,如LabelImg或VGG Image Annotator,来标注图像。 2. 准备数据集 一旦你获得了标注过的数据集,你需要将其转换为Mask R-CNN模型所需的格式。通常,你需要将标注数据转换为COCO格式或VOC格式。你可以使用相应的转换工具来执行这个任务。 3. 配置环境 在开始训练之前,你需要配置你的环境。你需要安装PythonTensorFlowMask R-CNN代码库。你可以在GitHub上克隆Mask R-CNN代码库,并按照说明进行安装。 4. 配置训练参数 在开始训练之前,你需要配置训练参数。这些参数包括学习率、批量大小、最大迭代次数等等。你可以通过修改配置文件来进行配置。 5. 开始训练 一旦你完成了配置,你可以开始训练你的模型。你需要运行训练脚本,并指定训练数据集的路径和其他参数。训练过程可能需要一些时间,具体取决于你的数据集大小和计算资源。 6. 模型评估和微调 训练完成后,你可以对模型进行评估,并微调模型以进一步提高性能。你可以使用验证数据集来评估模型的准确性和召回率,并根据结果进行微调。 7. 部署模型 一旦你完成了训练和微调,你可以部署你的模型。你可以将训练好的模型保存为HDF5文件,并使用它来进行目标检测和实例分割。 总之,使用Mask R-CNN训练自己的数据集需要一定的技术和计算资源,但它可以帮助你建立一个高性能的目标检测和实例分割系统。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值