gluoncv 目标检测,训练自己的数据集
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 npdef 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: heightA = 4B = 5C = wD = h# concat id and bboxeslabels = np.hstack((ids.reshape(-1, 1), boxes)).astype('float')# normalized bboxes (recommanded)labels[:, (1, 3)] /= float(w)labels[:, (2, 4)] /= float(h)# flattenlabels = 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 linefiles = 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 = Truecnt = 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':continuebbox = 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 = Falsefirst_flag = boxesids = np.array(ids)if cnt < 27853//2:line = write_line(url,(height,width,3),boxes,ids,cnt1)fwtrain.write(line)cnt1+=1if cnt >= 27853//2:line = write_line(url, (height, width, 3), boxes, ids, cnt2)fwval.write(line)cnt2+=1cnt += 1fwtrain.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 20args.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.001args.lr_warmup = args.lr_warmup if args.lr_warmup else -1args.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,
转载于:https://www.cnblogs.com/TreeDream/p/10174899.html
gluoncv 目标检测,训练自己的数据集相关推荐
- MMdetection3d环境搭建、使用MMdetection3d做3D目标检测训练自己的数据集、测试、可视化,以及常见的错误
MMdetection3d环境搭建.使用MMdetection3d做3D目标检测训练自己的数据集.测试.可视化,以及常见的错误 1 mmdetection3d环境搭建与测试 1.1 从docker开始 ...
- PASCAL VOC训练集制作(从原始视频到目标检测训练数据集)
本文目的:实验用CCD采集到5个视频,需在5个视频中采集有效图片,并将这些图片利用LableImg软件进行标注,用来制备VOC格式的目标检测训练数据集. 第一步:有效视频截取 将采集到的视频利用ban ...
- 自动驾驶深度多模态目标检测和语义分割:数据集、方法和挑战
自动驾驶深度多模态目标检测和语义分割:数据集.方法和挑战 原文地址:https://arxiv.org/pdf/1902.07830.pdf Deep Multi-Modal Object Detec ...
- 目标检测训练时候的不平衡问题
目标检测训练时候的不平衡问题 先放大佬链接(https://mp.weixin.qq.com/s/K1HTRjSLAM8mME4g1eNHtA) 当前主流的物体检测算法,如Faster RCNN和SS ...
- 【目标检测】基于yolov5海上船舶目标检测(附代码和数据集)
Hello,大家好,我是augustqi.今天给大家分享的目标检测项目是:基于yolov5海上船舶目标检测(附代码和数据集) Part1 前言 传统的海上目标检测是通过雷达来实现,但是随着技术的发展, ...
- tensorflow精进之路(二十五)——Object Detection API目标检测(下)(VOC数据集训练自己的模型进行目标检测)
1.概述 上一讲,我们使用了别人根据COCO数据集训练好的模型来做目标检测,这一讲,我们就来训练自己的模型. 2.下载数据集 为了方便学习,我们先使用别人整理好的数据集来训练---VOC 2012数据 ...
- tensorflow精进之路(二十四)——Object Detection API目标检测(中)(COCO数据集训练的模型—ssd_mobilenet_v1_coco模型)
1.概述 上一讲简单的讲了目标检测的原理以及Tensorflow Object Detection API的安装,这一节继续讲Tensorflow Object Detection API怎么用. 2 ...
- ssd目标检测训练自己的数据_目标检测Tensorflow object detection API之训练自己的数据集...
构建自己的模型之前,推荐先跑一下Tensorflow object detection API的demo JustDoIT:目标检测Tensorflow object detection APIzh ...
- 目标检测训练trick超级大礼包—不改模型提升精度,值得拥有
点击我爱计算机视觉标星,更快获取CVML新技术 昨日新上arXiv的一篇论文<Bag of Freebies for Training Object Detection Neural Netwo ...
- 收藏 | 3D目标检测综述:从数据集到2D和3D方法
点上方蓝字计算机视觉联盟获取更多干货 在右上方 ··· 设为星标 ★,与你不见不散 仅作学术分享,不代表本公众号立场,侵权联系删除 转载于:机器之心 AI博士笔记系列推荐 周志华<机器学习> ...
最新文章
- 终于有人把 SpringBoot 项目的Http客户端工具说清楚了!
- ystem.Windows.Forms.SplitContainer : ContainerControl, ISupportInitialize
- Java的重写和重载机制
- 2.3.5 操作系统之信号量机制实现进程的互斥、同步与前驱关系
- java访问权限 public private protected
- 王道408数据结构——第七章 查找
- 《C++之那些年踩过的坑(附录一)》
- RHEL 8 - 用OpenSCAP工具对容器镜像进行漏洞安全合规扫描,并修复
- MacPE+WinPE-黑苹果之路
- “21天好习惯”第一期-15
- 中科院-杨力祥视频教程	02课程
- 12306模拟登陆-超级鹰
- unreal编译源码搭建dedicated server的流水账——但是细
- 【计算机组成原理】码距怎么计算
- Adobe的后期摄影图片处理软件Photoshop Lightroom(Lr) 6.2版本下载与安装教程
- MYSQL计算日期差和时间差的函数
- 文件夹的隐藏选项为灰色勾选,无法更改或删除
- 线性滤波、非线性滤波区别
- bzoj4755: [Jsoi2016]扭动的回文串 manacher+二分+Hash
- 乐教乐学显示服务器故障怎么了,乐教乐学常见问题有哪些,如何解决闪退问题...