目标检测 的标注数据 .xml 转为 tfrecord 的格式用于 TensorFlow 训练
将目标检测 的标注数据 .xml 转为 tfrecord 的格式用于 TensorFlow 训练。
import xml.etree.ElementTree as ET
import numpy as np
import os
import tensorflow as tf
from PIL import Image classes = ["aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow", "diningtable",
"dog", "horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor"] def convert(size, box):
dw = 1./size[0]
dh = 1./size[1]
x = (box[0] + box[1])/2.0
y = (box[2] + box[3])/2.0
w = box[1] - box[0]
h = box[3] - box[2]
x = x*dw
w = w*dw
y = y*dh
h = h*dh
return [x, y, w, h] def convert_annotation(image_id):
in_file = open('F:/xml/%s.xml'%(image_id)) tree = ET.parse(in_file)
root = tree.getroot()
size = root.find('size')
w = int(size.find('width').text)
h = int(size.find('height').text)
bboxes = []
for i, obj in enumerate(root.iter('object')):
if i > 29:
break
difficult = obj.find('difficult').text
cls = obj.find('name').text
if cls not in classes or int(difficult) == 1:
continue
cls_id = classes.index(cls)
xmlbox = obj.find('bndbox')
b = (float(xmlbox.find('xmin').text), float(xmlbox.find('xmax').text), float(xmlbox.find('ymin').text), float(xmlbox.find('ymax').text))
bb = convert((w, h), b) + [cls_id]
bboxes.extend(bb)
if len(bboxes) < 30*5:
bboxes = bboxes + [0, 0, 0, 0, 0]*(30-int(len(bboxes)/5)) return np.array(bboxes, dtype=np.float32).flatten().tolist() def convert_img(image_id):
image = Image.open('F:/snow leopard/test_im/%s.jpg' % (image_id))
resized_image = image.resize((416, 416), Image.BICUBIC)
image_data = np.array(resized_image, dtype='float32')/255
img_raw = image_data.tobytes()
return img_raw filename = os.path.join('test'+'.tfrecords')
writer = tf.python_io.TFRecordWriter(filename)
# image_ids = open('F:/snow leopard/test_im/%s.txt' % (
# year, year, image_set)).read().strip().split() image_ids = os.listdir('F:/snow leopard/test_im/')
# print(filename)
for image_id in image_ids:
print (image_id)
image_id = image_id.split('.')[0]
print (image_id) xywhc = convert_annotation(image_id)
img_raw = convert_img(image_id) example = tf.train.Example(features=tf.train.Features(feature={
'xywhc':
tf.train.Feature(float_list=tf.train.FloatList(value=xywhc)),
'img':
tf.train.Feature(bytes_list=tf.train.BytesList(value=[img_raw])),
}))
writer.write(example.SerializeToString())
writer.close()
Python读取文件夹下图片的两种方法:
import os
imagelist = os.listdir('./images/') #读取images文件夹下所有文件的名字
import glob
imagelist= sorted(glob.glob('./images/' + 'frame_*.png')) #读取带有相同关键字的图片名字,比上一中方法好
参考:
https://blog.csdn.net/CV_YOU/article/details/80778392
https://github.com/raytroop/YOLOv3_tf
目标检测 的标注数据 .xml 转为 tfrecord 的格式用于 TensorFlow 训练的更多相关文章
- 训练自己数据-xml文件转voc格式
首先我们有一堆xml文件 笔者是将mask-rcnn得到的json标注文件转为xml的 批量json转xml方法:https://www.cnblogs.com/bob-jianfeng/p/1112 ...
- yolo系列目标检测+自标注数据集进行目标识别
1. yolov1的识别原理 参考:https://blog.csdn.net/u010712012/article/details/85116365 https://blog.csdn.net/gb ...
- [AI开发]目标检测之素材标注
算力和数据是影响深度学习应用效果的两个关键因素,在算力满足条件的情况下,为了到达更好的效果,我们需要将海量.高质量的素材数据喂给神经网络,训练出高精度的网络模型.吴恩达在深度学习公开课中提到,在算力满 ...
- (转)如何用TensorLayer做目标检测的数据增强
数据增强在机器学习中的作用不言而喻.和图片分类的数据增强不同,训练目标检测模型的数据增强在对图像做处理时,还需要对图片中每个目标的坐标做相应的处理.此外,位移.裁剪等操作还有可能使得一些目标在处理后只 ...
- 第三十二节,使用谷歌Object Detection API进行目标检测、训练新的模型(使用VOC 2012数据集)
前面已经介绍了几种经典的目标检测算法,光学习理论不实践的效果并不大,这里我们使用谷歌的开源框架来实现目标检测.至于为什么不去自己实现呢?主要是因为自己实现比较麻烦,而且调参比较麻烦,我们直接利用别人的 ...
- 【目标检测实战】目标检测实战之一--手把手教你LMDB格式数据集制作!
文章目录 1 目标检测简介 2 lmdb数据制作 2.1 VOC数据制作 2.2 lmdb文件生成 lmdb格式的数据是在使用caffe进行目标检测或分类时,使用的一种数据格式.这里我主要以目标检测为 ...
- 平均精度均值(mAP)——目标检测模型性能统计量
在机器学习领域,对于大多数常见问题,通常会有多个模型可供选择.当然,每个模型会有自己的特性,并会受到不同因素的影响而表现不同. 每个模型的好坏是通过评价它在某个数据集上的性能来判断的,这个数据集通常被 ...
- 目标检测模型的性能评估--MAP(Mean Average Precision)
目标检测模型中性能评估的几个重要参数有精确度,精确度和召回率.本文中我们将讨论一个常用的度量指标:均值平均精度,即MAP. 在二元分类中,精确度和召回率是一个简单直观的统计量,但是在目标检测中有所不同 ...
- 【目标检测】SSD:
slides 讲得是相当清楚了: http://www.cs.unc.edu/~wliu/papers/ssd_eccv2016_slide.pdf 配合中文翻译来看: https://www.cnb ...
随机推荐
- Linux实现多线程高速下载
使用Wget下载,有时候速度挺慢的. 有没有好办法呢? 一.解决方案 安装axel 安装方法: yum -y install epel-release .el7.x86_64.rpm rpm -ivh ...
- 【Fanvas技术解密】HTML5 canvas实现脏区重绘
先说明一下,fanvas是笔者在企鹅公司开发的,即将开源的flash转canvas工具. 脏区重绘(dirty rectangle)并不是一门新鲜的技术了,这在最早2D游戏诞生的时候就已经存在. 复杂 ...
- Oracle Data Integrator 12c-第一个映射
一.创建"项目" 设计器->项目,点击插入项目图标, 在项目对话框的"定义"标签下输入项目名称如ODI_Exercise ,保存 二.导入知识模块 项目→ ...
- 【Linux】常见Linux默认的shell
常见的操作系统下的shell: Linux下默认的shell是Bourne Again shell(bash) Solaris和FreeBSD下默认的是Bourne shell(sh) AIX系统下默 ...
- log4j2的xml的配置样例
log4j2.xml <?xml version="1.0" encoding="UTF-8"?> <Configuration status ...
- Zuul Timeouts
19.13 Zuul Timeouts 19.13.1 Service Discovery Configuration If Zuul is using service discovery there ...
- NRF24L01无线模块的使用
NRF2401芯片pin定义 NRF24L01模块pin定义 VCC 脚接电压范围为 1.9V~3.6V 之间, 不能在这个区间之外, 超过 3.6V 将会烧毁模块, 推荐电压 3.3V 左右 除电源 ...
- Libevent例子(一)
服务器端 #include<stdio.h> #include<string.h> #include<errno.h> #include<event.h> ...
- HttpServer发送数据到kafka
文件夹 1.需求 2.框架结构图和步鄹图 3.代码结构 4.代码展现 ------------------------ 1.需求 1.1.解析路径,将路径的最后一个字符串作为Appkey: 1.2.数 ...
- -webkit-line-clamp下多行文字溢出点点点...显示实例页面
overflow : hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box ...