https://gluon-cv.mxnet.io/build/examples_datasets/detection_custom.html

官方提供两种方案,一种是lst文件,一种是xml文件(voc的格式);

voc 格式的标注有标注工具,但是你如果是json文件标注的信息,或者其他格式的,你就要转成voc格式的。

于是就选择第一种数据格式lst序列文件格式,格式很简单。

根据你自己的json或者其他格式文件转换一下。

import json
import os
import cv2
import numpy as np def write_line(img_path, im_shape, boxes, ids, idx):
h, w, c = im_shape
# for header, we use minimal length 2, plus width and height
# with A: 4, B: 5, C: width, D: height
A = 4
B = 5
C = w
D = h
# concat id and bboxes
labels = np.hstack((ids.reshape(-1, 1), boxes)).astype('float')
# normalized bboxes (recommanded)
labels[:, (1, 3)] /= float(w)
labels[:, (2, 4)] /= float(h)
# flatten
labels = labels.flatten().tolist()
str_idx = [str(idx)]
str_header = [str(x) for x in [A, B, C, D]]
str_labels = [str(x) for x in labels]
str_path = [img_path]
line = '\t'.join(str_idx + str_header + str_labels + str_path) + '\n'
return line files = os.listdir('train_front')
json_url = []
cnt = 0
for file in files:
tmp = os.listdir('train_front/'+file)
for js in tmp:
if js.endswith('json'):
json_url.append('train_front/'+file+'/'+js)
cnt+=1
print(cnt) fwtrain = open("train.lst","w")
fwval = open("val.lst","w") first_flag = []
flag = True cnt = 0
cnt1 = 0
cnt2 = 0
for json_url_index in json_url:
file = open(json_url_index,'r')
for line in file:
js = json.loads(line) if 'person' in js:
boxes = []
ids = []
for i in range(len(js['person'])):
if js['person'][i]['attrs']['ignore'] == 'yes' or js['person'][i]['attrs']['occlusion']== 'heavily_occluded' or js['person'][i]['attrs']['occlusion']== 'invisible':
continue bbox = js['person'][i]['data']
url = '/mnt/hdfs-data-4/data/jian.yin/'+json_url_index[:-5]+'/'+js['image_key']
width = js['width']
height = js['height']
boxes.append(bbox)
ids.append(0) print(url)
print(bbox) if len(boxes) > 0:
if flag:
flag = False
first_flag = boxes
ids = np.array(ids) if cnt < 27853//2: line = write_line(url,(height,width,3),boxes,ids,cnt1)
fwtrain.write(line)
cnt1+=1 if cnt >= 27853//2:
line = write_line(url, (height, width, 3), boxes, ids, cnt2)
fwval.write(line)
cnt2+=1 cnt += 1 fwtrain.close()
fwval.close()
print(first_flag)

lst文件就转换好了。

然后添加自己的数据集:

https://github.com/dmlc/gluon-cv/blob/master/scripts/detection/faster_rcnn/train_faster_rcnn.py#L73

这里不能直接套用前面的导入数据的过程。

按照教程给出的方式添加。投机取巧的验证方式,直接引用前面的。

或者不验证:https://github.com/dmlc/gluon-cv/blob/master/scripts/detection/faster_rcnn/train_faster_rcnn.py#L393 部分注释掉。

    elif dataset.lower() == 'pedestrian':
lst_dataset = LstDetection('train_val.lst',root=os.path.expanduser('.'))
print(len(lst_dataset))
first_img = lst_dataset[0][0] print(first_img.shape)
print(lst_dataset[0][1]) train_dataset = LstDetection('train.lst',root=os.path.expanduser('.'))
val_dataset = LstDetection('val.lst',root=os.path.expanduser('.'))
classs = ('pedestrian',)
val_metric = VOC07MApMetric(iou_thresh=0.5,class_names=classs)

训练参数:

https://github.com/dmlc/gluon-cv/blob/master/scripts/detection/faster_rcnn/train_faster_rcnn.py#L73

添加自己的训练参数或者直接套用。

    if args.dataset == 'voc' or args.dataset == 'pedestrian':
args.epochs = int(args.epochs) if args.epochs else 20
args.lr_decay_epoch = args.lr_decay_epoch if args.lr_decay_epoch else '14,20'
args.lr = float(args.lr) if args.lr else 0.001
args.lr_warmup = args.lr_warmup if args.lr_warmup else -1
args.wd = float(args.wd) if args.wd else 5e-4

model_zoo.py添加自己的数据集映射方案。这里如果是pip install gluoncv ,就要到site-package里面改。

https://github.com/dmlc/gluon-cv/blob/master/gluoncv/model_zoo/model_zoo.py#L32

'faster_rcnn_resnet50_v1b_pedestrian': faster_rcnn_resnet50_v1b_voc,

gluoncv 目标检测,训练自己的数据集的更多相关文章

  1. 目标检测网络之 YOLOv2

    YOLOv1基本思想 YOLO将输入图像分成SxS个格子,若某个物体 Ground truth 的中心位置的坐标落入到某个格子,那么这个格子就负责检测出这个物体. 每个格子预测B个bounding b ...

  2. 目标检测之YOLO V2 V3

    YOLO V2 YOLO V2是在YOLO的基础上,融合了其他一些网络结构的特性(比如:Faster R-CNN的Anchor,GooLeNet的\(1\times1\)卷积核等),进行的升级.其目的 ...

  3. 目标检测网络之 YOLOv3

    本文逐步介绍YOLO v1~v3的设计历程. YOLOv1基本思想 YOLO将输入图像分成SxS个格子,若某个物体 Ground truth 的中心位置的坐标落入到某个格子,那么这个格子就负责检测出这 ...

  4. Faster-rcnn实现目标检测

      Faster-rcnn实现目标检测 前言:本文浅谈目标检测的概念,发展过程以及RCNN系列的发展.为了实现基于Faster-RCNN算法的目标检测,初步了解了RCNN和Fast-RCNN实现目标检 ...

  5. 可变卷积Deforable ConvNet 迁移训练自己的数据集 MXNet框架 GPU版

    [引言] 最近在用可变卷积的rfcn 模型迁移训练自己的数据集, MSRA官方使用的MXNet框架 环境搭建及配置:http://www.cnblogs.com/andre-ma/p/8867031. ...

  6. 【转】目标检测之YOLO系列详解

    本文逐步介绍YOLO v1~v3的设计历程. YOLOv1基本思想 YOLO将输入图像分成SxS个格子,若某个物体 Ground truth 的中心位置的坐标落入到某个格子,那么这个格子就负责检测出这 ...

  7. CenterNet算法笔记(目标检测论文)

    论文名称:CenterNet: Keypoint Triplets for Object Detectiontection 论文链接:https://arxiv.org/abs/1904.08189 ...

  8. 动手创建 SSD 目标检测框架

    参考:单发多框检测(SSD) 本文代码被我放置在 Github:https://github.com/XinetAI/CVX/blob/master/app/gluoncvx/ssd.py 关于 SS ...

  9. 第三十二节,使用谷歌Object Detection API进行目标检测、训练新的模型(使用VOC 2012数据集)

    前面已经介绍了几种经典的目标检测算法,光学习理论不实践的效果并不大,这里我们使用谷歌的开源框架来实现目标检测.至于为什么不去自己实现呢?主要是因为自己实现比较麻烦,而且调参比较麻烦,我们直接利用别人的 ...

随机推荐

  1. Python-常用模块及简单的案列

    1.模块   函数的优点之一,就是可以使用函数将代码块与主程序分离,通过给函数指定一个描述性的名称,并将函数存储在被称为模块的独立文件中,再将模块导入主程序中,通过import语句允许在当前运行的程序 ...

  2. 常用工具说明--Git和GitHub简明教程

    一.Git的主要功能:版本控制 版本:想想你平时用的软件,在软件升级之后,你用的就是新版本的软件.你应该见过这样的版本号:v2.0 或者 1511(表示发布时为15年11月),如下图:那么如果你修改并 ...

  3. MYSQL常用函数以及分组操作

    SELECT CONVERT(",SIGNED); SELECT CAST(" AS SIGNED); SELECT ; SELECT LENGTH("姜浩真帅!&quo ...

  4. 连锁咖啡厅B/S架构点餐系统开发

    需求号:5255128 http://task.zhubajie.com/5255128/ 具体要求: 网站用途:连锁咖啡厅B/S架构点餐系统开发开发周期:1.5个月功能要求: 支持触摸屏点菜.无线P ...

  5. 在WPF中UserControl

    在这里我们将将打造一个UserControl(用户控件)来逐步讲解如何在WPF中自定义控件,并将WPF的一些新特性引入到自定义控件中来.我们制作了一个带语音报时功能的钟表控件, 效果如下: 在VS中右 ...

  6. FusionCharts数据展示成饼状图、柱状图和折线图

    FusionCharts数据展示成饼状图.柱状图和折线图 本文以展示柱状图为例进行介绍,当然这仅仅是一种方法而已:还有很多方法可以用于展示图表,例如echarts,自定义图表标签.使用jfreecha ...

  7. 在linux命令行利用SecureCRT上传下载文件

    一般来说,linux服务器大多是通过ssh客户端来进行远程的登陆和管理的,使用ssh登陆linux主机以后,如何能够快速的和本地机器进行文件的交互呢,也就是上传和下载文件到服务器和本地?与ssh有关的 ...

  8. JBPM学习第4篇:10分钟熟悉Eclipse

    http://download.jboss.org/jbpm/videos/7.0.0.Final_eclipse_getting_started.swf 打开视频练习 1.导入 evaluation ...

  9. 小任务之Canvas绘制时钟

    背景图的绘制(大圆.数字.小圆点) 掌握基础知识:圆的绘制(arc方法),关于圆的弧度的计算,数学中关于sin cos的用法 圆的弧度为2*Math.PI 12个数字分得弧度每个为2*Math.PI/ ...

  10. Flink Flow

    1. Create environment for stream computing StreamExecutionEnvironment env = StreamExecutionEnvironme ...