常春岛资源网 Design By www.syssdc.com

我就废话不多说了,直接上代码吧!

import tensorflow as tf
from PIL import Image
import matplotlib.pyplot as plt
import numpy as np
import os
i = 0
j = 0
num_shards = 100#总共写入的文件个数
instances_per_shard = 2#每个文件中的数据个数
sess=tf.InteractiveSession()
cwd = "F:/寒假/google--data/新建文件夹/" #图片数据所在目录位置(读者自己去改就好了)
classes = {'daisy','rose'} #预先自己定义的类别,根据自己的需要修改


def _int64_feature(value):#生成整数型的属性
   return tf.train.Feature(int64_list=tf.train.Int64List(value=[value]))

def _bytes_feature(value):#生成字符串型的属性
   return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value]))
   
for index, name in enumerate(classes):#枚举函数
  class_path = cwd + name + "/"#选取具体数据目录
  for img_name in os.listdir(class_path):#遍历文件列表
    img_path = class_path + img_name#图片路径
    img = Image.open(img_path)
    img = img.resize((299, 299)) #图像reshape大小设置,根据自己的需要修改
    img_raw = img.tobytes()
      
    example = tf.train.Example(features=tf.train.Features(feature={
          'label': _int64_feature(index),
          'img_raw': _bytes_feature(img_raw),
          'i': _int64_feature(i),
          'j': _int64_feature(j)
        }))
    filename = ("F:/寒假/google--data/data.tfrecords-%.5d-of-%.5d"%(i,num_shards))
    if j == instances_per_shard-1:
      i+=1
    j+=1
    if j == instances_per_shard:
      j=0
    writer = tf.python_io.TFRecordWriter(filename)
      
    writer.write(example.SerializeToString())#将一个example写入tfrecord文件
writer.close()

以上这篇tensorflow生成多个tfrecord文件实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

标签:
tensorflow,生成,tfrecord文件

常春岛资源网 Design By www.syssdc.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
常春岛资源网 Design By www.syssdc.com

P70系列延期,华为新旗舰将在下月发布

3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。

而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?

根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。