tensorflow生成多个tfrecord文件实例

  

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

        进口tensorflow特遣部队   从公益诉讼导入图像   进口matplotlib。pyplot作为plt   进口numpy np   进口操作系统   我=0   j=0   num_shards=100 #总共写入的文件个数   instances_per_shard=2 #每个文件中的数据个数   税=tf.InteractiveSession ()   慢性消耗?" F:/寒假/谷歌——数据/新建文件夹/?图片数据所在目录位置(读者自己去改就好了)   类={“黛西”,“玫瑰”}#预先自己定义的类别,根据自己的需要修改         def _int64_feature(值):#生成整数型的属性   返回tf.train.Feature (int64_list=tf.train.Int64List(值=https://www.yisu.com/zixun/(价值)))      def _bytes_feature(值):#生成字符串型的属性   返回tf.train.Feature (bytes_list=tf.train.BytesList(值=(价值)))      指数,在列举(类):#枚举函数   class_path=慢性消耗病+名称+“/?选取具体数据目录   在os.listdir img_name (class_path): #遍历文件列表   img_path=class_path + img_name #图片路径   img=Image.open (img_path)   img=img。调整((299、299)#图像重塑大小设置,根据自己的需要修改   img_raw=img.tobytes ()      示例=tf.train.Example(特性=tf.train.Features(特性={   “标签”:_int64_feature(指数),   “img_raw”: _bytes_feature (img_raw),   “我”:_int64_feature(我),   “j”: _int64_feature (j)   }))   文件名=(“F:/寒假/谷歌——数据/data.tfrecords - % .5d-of % .5d”%(我num_shards))   如果j==instances_per_shard-1:   我+=1   j +=1   如果j==instances_per_shard:   j=0   作家=tf.python_io.TFRecordWriter(文件名)      writer.write (example.SerializeToString()) #将一个例子写入tfrecord文件   writer.close ()      之前      

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

tensorflow生成多个tfrecord文件实例