Write tfrecord

import os
import tensorflow as tf
from PIL import Image
import matplotlib.pyplot as plt
import numpy as np
import glob

def convert_tfrecord_dataset():
   cwd = os.getcwd()
   writer= tf.python_io.TFRecordWriter("train.tfrecords")

   class_path = cwd

   img_path = './Screenshot.png'
   #img_path = './27434_20180523_EU_NCAP_Part1.png'
   #img_path = './49494_20180612_EU_NCAP_Part4_increment1.png'
   img = Image.open(img_path)
   print(img)

   #img = img.resize((64,64))
   print(img)
   image = img.tobytes()

   example = tf.train.Example(features=tf.train.Features(feature={
            'image': tf.train.Feature(bytes_list=tf.train.BytesList(value=[image]))
            }))
   writer.write(example.SerializeToString())

   writer.close()

if __name__ == '__main__':
    print('start...')
    convert_tfrecord_dataset()

  

posted on 2019-01-23 14:45  cdekelon  阅读(89)  评论(0)    收藏  举报

导航