seresnet50训练自己的数据集_使用mask scoring RCNN训练自己的数据集

本文介绍了如何使用SerseNet50训练自定义数据集,包括数据集准备、环境搭建、训练前的参数配置、模型训练和预测。详细讲述了数据标注、COCO格式转换、PyTorch环境配置、模型训练和测试,以及预测代码的修改过程。
摘要由CSDN通过智能技术生成

本文主要参考下面两篇博文,并在部分细节处做了修改。

一、数据集准备

(训练集验证集测试集的数据分别准备)

1、标注数据集

大多数人会用labelme来标注数据集,然后用labelme将每张标注图片都生成一个json文件。labelme教程网上很多,这里不再赘述。

本人由于原图的标注目标很小,用labelme标注未免不精确,所以先用PS手动标注后再写代码把标注图转换成了labelme格式的json文件。

结果如图:

2、将这些json文件转换成coco格式

这一步我使用如下代码可成功转换。

#-*- coding:utf-8 -*-

importos, sysimportargparseimportjsonimportmatplotlib.pyplot as pltimportskimage.io as iofrom labelme importutilsimportnumpy as npimportglobimportPIL.ImageclassMyEncoder(json.JSONEncoder):defdefault(self, obj):ifisinstance(obj, np.integer):returnint(obj)elifisinstance(obj, np.floating):returnfloat(obj)elifisinstance(obj, np.ndarray):returnobj.tolist()else:returnsuper(MyEncoder, self).default(obj)classlabelme2coco(object):def __init__(self, labelme_json=[], save_json_path='./tran.json'):''':param labelme_json: 所有labelme的json文件路径组成的列表

:param save_json_path: json保存位置'''self.labelme_json=labelme_json

self.save_json_path=save_json_path

self.images=[]

self.categories=[]

self.annotations=[]#self.data_coco = {}self.label=[]

self.annID= 1self.height=0

self.width=0

self.save_json()defdata_transfer(self):for num, json_file inenumerate(self.labelme_json):

with open(json_file,'r') as fp:

data= json.load(fp) #加载json文件self.images.append(self.image(data, num))for shapes in data['shapes']:

label= shapes['label']if label not inself.label:

self.categories.append(self.categorie(label))

self.label.append(label)

points= shapes['points'] #这里的point是用rectangle标注得到的,只有两个点,需要转成四个点points.append([points[0][0], points[1][1]])

points.append([points[1][0], points[0][1]])

self.annotations.append(self.annotation(points, label, num))

self.annID+= 1

defimage(self, data, num):

image={}#img = utils.img_b64_to_arr(data['imageData']) # 解析原图片数据

#img=io.imread(data['imagePath']) # 通过图片路径打开图片

#img = cv2.imread(data['imagePath'], 0)

#height, width = img.shape[:2]height= data['imageHeight']

width= data['imageWidth']

image['height'] =height

image['width'] =width

image['id'] = num + 1image['file_name'] = data['imagePath'].split('/')[-1]

self.height=height

self.width=widthreturnimagedefcategorie(self, label):

categorie={}

categorie['supercategory'] = &#

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值