https://pan.baidu.com/s/19n-l9hg9v0pfdBAEhS5E3A
提取码: r7ec

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jun  9 12:08:34 2021@author: ledi
"""import tensorflow as tfdef transform_images(x_train, size):x_train = tf.image.resize(x_train, (size, size))x_train = x_train / 255return x_train# https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/using_your_own_dataset.md#conversion-script-outline-conversion-script-outline
# Commented out fields are not required in our project
IMAGE_FEATURE_MAP = {# 'image/width': tf.io.FixedLenFeature([], tf.int64),# 'image/height': tf.io.FixedLenFeature([], tf.int64),# 'image/filename': tf.io.FixedLenFeature([], tf.string),# 'image/source_id': tf.io.FixedLenFeature([], tf.string),# 'image/key/sha256': tf.io.FixedLenFeature([], tf.string),'image/encoded': tf.io.FixedLenFeature([], tf.string),# 'image/format': tf.io.FixedLenFeature([], tf.string),'image/object/bbox/xmin': tf.io.VarLenFeature(tf.float32),'image/object/bbox/ymin': tf.io.VarLenFeature(tf.float32),'image/object/bbox/xmax': tf.io.VarLenFeature(tf.float32),'image/object/bbox/ymax': tf.io.VarLenFeature(tf.float32),'image/object/class/text': tf.io.VarLenFeature(tf.string),# 'image/object/class/label': tf.io.VarLenFeature(tf.int64),# 'image/object/difficult': tf.io.VarLenFeature(tf.int64),# 'image/object/truncated': tf.io.VarLenFeature(tf.int64),# 'image/object/view': tf.io.VarLenFeature(tf.string),
}def parse_tfrecord(tfrecord, class_table, size):x = tf.io.parse_single_example(tfrecord, IMAGE_FEATURE_MAP)x_train = tf.image.decode_jpeg(x['image/encoded'], channels=3)x_train = tf.image.resize(x_train, (size, size))print( x_train)class_text = tf.sparse.to_dense(x['image/object/class/text'], default_value='')labels = tf.cast(class_table.lookup(class_text), tf.float32)y_train = tf.stack([tf.sparse.to_dense(x['image/object/bbox/xmin']),tf.sparse.to_dense(x['image/object/bbox/ymin']),tf.sparse.to_dense(x['image/object/bbox/xmax']),tf.sparse.to_dense(x['image/object/bbox/ymax']),labels], axis=1)# print('FLAGS.yolo_max_boxes=',FLAGS.yolo_max_boxes)paddings = [[0, 100 - tf.shape(y_train)[0]], [0, 0]]# paddings = [[0, FLAGS.yolo_max_boxes - tf.shape(y_train)[0]], [0, 0]]y_train = tf.pad(y_train, paddings)return x_train, y_train"""
count=0
for k in files:if count<10:print(k)count+=1
"""def load_tfrecord_dataset(file_pattern, class_file, size=416):#file_pattern, class_file, size='./data/voc2012_train.tfrecord','./dataLINE_NUMBER = -1  # TODO: use tf.lookup.TextFileIndex.LINE_NUMBERclass_table = tf.lookup.StaticHashTable(tf.lookup.TextFileInitializer(class_file, tf.string, 0, tf.int64, LINE_NUMBER, delimiter="\n"), -1)files = tf.data.Dataset.list_files(file_pattern)dataset = files.flat_map(tf.data.TFRecordDataset)return dataset.map(lambda x: parse_tfrecord(x, class_table, size))train_dataset = load_tfrecord_dataset('./data/voc2012_train.tfrecord','./data/voc2012.names', 416)count=0
for k in train_dataset:if count<3:print(k)count+=1 
输出结果如下
(<tf.Tensor: shape=(416, 416, 3), dtype=float32, numpy=
array([[[255.      , 255.      , 255.      ],[255.      , 255.      , 255.      ],[255.      , 255.      , 255.      ],...,[201.51099 , 204.51099 , 247.51099 ],[202.67535 , 205.67535 , 248.67535 ],[202.96875 , 205.96875 , 248.96875 ]],[[255.      , 255.      , 255.      ],[255.      , 255.      , 255.      ],[255.      , 255.      , 255.      ],...,[202.375   , 205.375   , 248.375   ],[202.30965 , 205.30965 , 248.17892 ],[202.19696 , 205.19696 , 248.00946 ]],[[255.      , 255.      , 255.      ],[255.      , 255.      , 255.      ],[255.      , 255.      , 255.      ],...,[205.84375 , 209.      , 251.21875 ],[205.36447 , 208.52072 , 249.56303 ],[204.39767 , 207.55392 , 248.08517 ]],...,[ 79.83946 ,  75.82988 ,  70.3127  ],[ 75.77214 ,  72.77214 ,  65.72856 ],[ 80.510895,  77.510895,  70.448395]]], dtype=float32)>, <tf.Tensor: shape=(100, 5), dtype=float32, numpy=
array([[ 0.106     ,  0.19683258,  0.942     ,  0.95022625, 12.        ],[ 0.316     ,  0.09954751,  0.578     ,  0.37782806, 14.        ],[ 0.        ,  0.        ,  0.        ,  0.        ,  0.        ],[ 0.        ,  0.        ,  0.        ,  0.        ,  0.        ],[ 0.        ,  0.        ,  0.        ,  0.        ,  0.        ],[ 0.        ,  0.        ,  0.        ,  0.        ,  0.        ],[ 0.        ,  0.        ,  0.        ,  0.        ,  0.        ],....[ 0.        ,  0.        ,  0.        ,  0.        ,  0.        ],[ 0.        ,  0.        ,  0.        ,  0.        ,  0.        ],[ 0.        ,  0.        ,  0.        ,  0.        ,  0.        ],[ 0.        ,  0.        ,  0.        ,  0.        ,  0.        ],[ 0.        ,  0.        ,  0.        ,  0.        ,  0.        ]],dtype=float32)>)

yolov3 -tf 解析数据相关推荐

  1. AlexeyAB DarkNet YOLOv3框架解析与应用实践(六)

    AlexeyAB DarkNet YOLOv3框架解析与应用实践(六) Tiny Darknet 听过很多人谈论SqueezeNet. SqueezeNet很酷,但它只是优化参数计数.当大多数高质量的 ...

  2. AlexeyAB DarkNet YOLOv3框架解析与应用实践(五)

    AlexeyAB DarkNet YOLOv3框架解析与应用实践(五) RNNs in Darknet 递归神经网络是表示随时间变化的数据的强大模型.为了更好地介绍RNNs,我强烈推荐Andrej K ...

  3. AlexeyAB DarkNet YOLOv3框架解析与应用实践(二)

    AlexeyAB DarkNet YOLOv3框架解析与应用实践(二) 版本3有什么新功能? YOLOv3使用了一些技巧来改进训练和提高性能,包括:多尺度预测.更好的主干分类器等等.全部细节都在我们的 ...

  4. AlexeyAB DarkNet YOLOv3框架解析与应用实践(四)

    AlexeyAB DarkNet YOLOv3框架解析与应用实践(四) Nightmare 从前,在一所大学的大楼里,西蒙尼亚.维达第和齐瑟曼有一个很好的主意,几乎和你现在坐的大楼完全不同.他们想,嘿 ...

  5. AlexeyAB DarkNet YOLOv3框架解析与应用实践(三)

    AlexeyAB DarkNet YOLOv3框架解析与应用实践(三) ImageNet分类 您可以使用Darknet为1000级ImageNet挑战赛分类图像.如果你还没有安装Darknet,你应该 ...

  6. AlexeyAB DarkNet YOLOv3框架解析与应用实践(一)

    AlexeyAB DarkNet YOLOv3框架解析与应用实践(一) Darknet: C语言中的开源神经网络 Darknet是一个用C和CUDA编写的开源神经网络框架.它速度快,易于安装,支持CP ...

  7. 【Python爬虫学习笔记4】结合Xpath与lxml库解析数据

    在之前的学习中了解了如何使用爬虫向目标服务器发送请求并获取响应,而此后便是要对响应进行处理,这里的处理在爬虫中通常指的是数据解析,即将相应内容数据化以方便我们进行有效数据的提取.在此过程中,有许多解析 ...

  8. 一起来开发Android的天气软件(四)——使用Gson解析数据

    离上一篇文章过去才4.5天,我们赶紧趁热打铁继续完成该系列的天气软件的开发.承接上一章的内容使用Volley实现网络的通信,返回给我们的是这一串Json数据{"weatherinfo&quo ...

  9. python爬虫用途-Python爬虫入门知识:解析数据篇

    首先,让我们回顾一下入门Python爬虫的四个步骤吧: 而解析数据,其用途就是在爬虫过程中将服务器返回的HTML源代码转换为我们能读懂的格式.那么,接下来就正式进入到解析数据篇的内容啦. Part 1 ...

最新文章

  1. Java中普通代码块,构造代码块,静态代码块区别
  2. 群晖 设置 php 服务器,群晖NAS服务器iSCSI管理器配置连接及使用说明
  3. VTK:图片之ImageMagnitude
  4. html中所有的标签,HTML中的所有标签及其做用!
  5. 开源软件使用_消费开源软件:如何使用和购买
  6. 1700x关闭超线程超频_转发分享一个超频技术新手知识BIOS设置指南
  7. 问题解决——OpenGL超级宝典 关于gltDrawTorus的错误解决
  8. 【回归预测】基于matlab灰狼算法优化ELMAN神经网络回归预测【含Matlab源码 1782期】
  9. js清空浏览器cokie缓存_JS设置cookie,删除cookie
  10. Python语言翻译包translate,支持翻译多语种
  11. 哈佛幸福课23集观后感
  12. 拼音打字时不定时出现重复字母
  13. 绿色版软件 tomcat+eclipse的使用
  14. nrf51822代码流程(从main展开)
  15. 利用七牛云作为图片服务器
  16. chrome 显示IP地址
  17. 如何在IntelliJ IDEA 中新建一个项目Project
  18. 解决IDEA 前端返回值乱码问题
  19. 基于Hadoop的企业人力资源管理
  20. 关于redis做秒杀库存扣减的生产实践及思考

热门文章

  1. C++类与static关键字
  2. rabbitmqctl status报错
  3. Django环境的搭建以及最简示例
  4. 马士兵java note 5
  5. 关于plsql连接oracle数据库session失效时间设置
  6. 性能计数器取网卡流量
  7. cocos2d-x学习笔记 动作 CCCallFunc家族(回调函数包装器)
  8. 大话WiFi省电模式
  9. 802.1X的wpa认证流程-------4-way handshake过程分析
  10. PAT甲级1151 LCA in a Binary Tree (30 分):[C++题解]LCA、最低公共祖先、哈希表映射