赞
踩
使用Efficientdet的Pytorch官方源码训练自己的数据集
1.先从官网下载代码efficientdet源码
2.再将自己的数据集都放入datasets中。我自己的数据集格式是Pascal VOC的xml格式,这个代码需要的格式是json格式,所以在网上找了好久找到了一个适合的转换代码,这里我放上来
# coding=utf-8 import xml.etree.ElementTree as ET import os import json voc_clses = ['D00', 'D01', 'D10', 'D11', 'D20', 'D40', 'D43', 'D44', 'D50'] # 这里换成自己数据集的类别.... categories = [] for iind, cat in enumerate(voc_clses): cate = { } cate['supercategory'] = cat cate['name'] = cat cate['id'] = iind categories.append(cate) def getimages(xmlname, id): sig_xml_box = [] tree = ET.parse(xmlname) root = tree.getroot() images = { } for i in root: # 遍历一级节点 if i.tag == 'filename': file_name = i.text # 0001.jpg # print('image name: ', file_name) images['file_name'] = file_name if i.tag == 'size': for j in i: if j.tag == 'width': width = j.text images['width'] = width if j.tag == 'height': height = j.text images['height'] = height if i.tag == 'object': for j in i: if j.tag == 'name': cls_name = j.text cat_id = voc_clses.index(cls_name) + 1 if j.tag == 'bndbox': bbox = [] xmin = 0 ymin = 0 xmax = 0 ymax = 0 for r in j: if r.tag == 'xmin': xmin = eval(r.text) if r.tag == 'ymin': ymin = eval(r.text) if r.tag == 'xmax': xmax = eval(r.text) if r.tag == 'ymax': ymax = eval(r.text) bbox.append(xmin) bbox.append(ymin) bbox.append(xmax - xmin) bbox.append(ymax - ymin) bbox.append(id) # 保存当前box对应的image_id bbox.append(cat_id) # anno area bbox.append((xmax - xmin) * (ymax - ymin)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。