benchmark mask训练自己的COCO数据集

本文档详细介绍了如何使用VIA工具制作COCO格式的数据集,并针对‘segmentation’字段的注意事项进行了说明。接着,通过编写getArea.py进行数据集验证。数据集可视化确保标注正确无误。在模型准备阶段,利用官方Dockerfile创建PyTorch 1.0.0 nightly环境,并调整配置文件以适应资源限制。训练时,选用e2e_mask_rcnn_R_101_FPN_1x.yaml配置文件,基于ResNet101-FPN的Mask R-CNN模型开始训练。
摘要由CSDN通过智能技术生成

1.COCO 数据集制作
采用VIA标注polygon导出相应的.csv数据。
注意:sgmentation是[[x0,y0,x1,y1,x2,y2,x3,y3,x4,y4]]
遇到的坑:”annotations“字段的"segmentation"是一个二维度的数组(大概是考虑到某个实例由不相连的好几个部分组成)

#!/usr/bin/env python3
import datetime
import json
import os
import re
import fnmatch
from PIL import Image
import numpy as np
import pandas as pd
import cv2
import getArea

#%%
ROOT_DIR = 'train'
IMAGE_DIR = '/media/ices18/Data/sms/shiyou_segment_model/data/JPEGImages'
#ANNOTATION_DIR = os.path.join(ROOT_DIR, "annotations")

INFO = {
    "description": "Example Dataset",
    "url": "https://github.com/waspinator/pycococreator",
    "version": "0.1.0",
    "year": 2019,
    "contributor": "mingshan",
    "date_created": datetime.datetime.utcnow().isoformat(' ')
}

LICENSES = [
    {
        "id": 1,
        "name": "Attribution-NonCommercial-ShareAlike License",
        "url": "http://creativecommons.org/licenses/by-nc-sa/2.0/"
    }
]
CATEGORIES_NAMES=['car','truck','build','collapse','river','dig','mound','brick','tube','pole']
TRUNCATED_NAMES=['10052.jpg','14191.jpg','14383.jpg','13285.jpg','12048.jpg']
CATEGORIES = [
    {
        'id': 1,
        'name': 'car',
        'supercategory': 'vehicle',
    },
    {
        'id': 2,
        'name': 'truck',
        'supercategory': 'vehicle',
    },
    {
        'id': 3,
        'name': 'build',
        'supercategory': 'engineer',
    },
    {
        'id': 4,
        'name': 'river',
        'supercategory': 'disaster',
    },
    {
        'id': 5,
        'name': 'collapse',
        'supercategory': 'disaster',
    },
    {
        'id': 6,
        'name': 'mound',
        'supercategory': 'engineer',
    },
    {
        'id': 7,
        'name': 'brick',
        'supercategory': 'engineer',
    },
    {
        'id': 8,
        'name': 'tube',
        'supercategory': 'engineer',
    },
    {
        'id': 9,
        'name': 'dig',
        'supercategory': 'engineer',
    },
    {
        'id': 10,
        'name': 'pole',
        'supercategory': 'engineer',
    }
]
#%%
def filter_for_jpeg(root, files):
    file_types = ['*.jpeg', '*.jpg']
    file_types = r'|'.join([fnmatch.translate(x) for x in file_types])
    files = [os.path.join(root, f) for f in files]
    files = [f for f in files if re.match(file_types, f)]   
    return files
#%% 
def get_segmenation(coord_x, coord_y):
    seg = []
    for x, y in zip(coord_x, coord_y):
        seg.append(x)
        seg.append(y)
    return [seg]

def create_image_info(image_id, file_name, image_size, 
                      date_captured=datetime.datetime.utcnow().isoformat(' '),
                      license_id=1, coco_
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值