最近用到图像转成TFRecord格式,记录一下:
代码如下:
import os
import tensorflow as tf
tfrecordfilename = ('traindata.tfrecords-%.3d'% recordfilenum)
writer = tf.python_io.TFRecordWriter(filepath+tfrecordfilename) #filepath+tfrecordfilename为存放tfrecord格式数据路径
train = os.listdir(train_path) #train_path训练图像路径
label = os.listdir(label_path) #label_path目标图像路径
for number in range(0,bestnum):
if num>bestnum :
num = 1