物体检测--Mask_RCNN系列:(三)训练自己的数据集与代码详解

        写下前面:前面我们对mask rcnn进行了解释,其中很多参考和引用了其他朋友的经验和资源,并对开源代码进行了实例测试,这里再给出mask rcnn项目开源地址:https://github.com/matterport/Mask_RCNN.后面我会就如何训练自己的数据集进行简要的总结,并将自己对训练和测试部分的代码注释和理解分享给大家,包括训练数据。

训练自己的数据集要用到数据标注工具:这里建议基于开源项目图片标记工具:https://github.com/wkentaro/labelme ,

这里有关数据标记工具labelme的使用可以参考这篇博客:https://blog.csdn.net/shwan_ma/article/details/77823281

利用标注工具准备好数据集:

将标注好的数据分别放在四个文件夹下:文件夹

《一》:cv2_mask:

0

《二》:json:

00

《三》:labelme_json\1_json

0

《四》:pic:

0

====》ok --- 训练数据准备完成:

下面新建train_selfdata.py脚本:添加如下代码:

# -*- coding: utf-8 -*-
import os
import sys
import random
import math
import re
import time
import numpy as np
import cv2
import matplotlib
import matplotlib.pyplot as plt
import tensorflow as tf
from mrcnn.config import Config
# import utils
from mrcnn import model as modellib, utils
from mrcnn import visualize
import yaml
from mrcnn.model import log
from PIL import Image




# os.environ["CUDA_VISIBLE_DEVICES"] = "0"
# Root directory of the project
ROOT_DIR = os.getcwd()

# ROOT_DIR = os.path.abspath("../")
# Directory to save logs and trained model
MODEL_DIR = os.path.join(ROOT_DIR, "logs")

iter_num = 0


# Local path to trained weights file
COCO_MODEL_PATH = os.path.join(ROOT_DIR, "mask_rcnn_coco.h5")
# Download COCO trained weights from Releases if needed
if not os.path.exists(COCO_MODEL_PATH):
    utils.download_trained_weights(COCO_MODEL_PATH)


class ShapesConfig(Config):
    """Configuration for training on the toy shapes dataset.
    Derives from the base Config class and overrides values specific
    to the toy shapes dataset.
    """
    # Give the configuration a recognizable name
    NAME = "shapes"

    # Train on 1 GPU and 8 images per GPU. We can put multiple images on each
    # GPU because the images are sm
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值