shutil copy file to folder

from __future__ import print_function

import tensorflow as tf
import os
import shutil

tf_dir = '../generate_tfrecord_by_me_part'

tf_list = [os.path.join(tf_dir,f) for f in os.listdir(tf_dir) ]
print("tfrecord files are {}".format(tf_list))


def extract_tfrecords_features(tfrecords_file):
    """Extract features in a tfrecords file for parsing a series of tfrecords files."""
    tfrecords_iterator = tf.python_io.tf_record_iterator(tfrecords_file)

    for record in tfrecords_iterator:

            example = tf.train.Example()
            example.ParseFromString(record)

            features = example.features.feature
            #print("the features is:{}\n".format(features))

            tf_frame_id = features['frame/id'].bytes_list.value
            #print("the frame_id is:{}\n".format(tf_frame_id))

            frame_id = tf_frame_id[0]

            frame = '../' + frame_id + '.jpg'
            #print(frame)
            shutil.copy(frame,'./images')

            label = '../label/' + frame_id.split('/')[-1] + '.txt'
            #print(label)
            shutil.copy(label,'./labels')


if __name__ == '__main__':

    for t in tf_list:
        #print("current tfrecord file is {}".format(t))
        result = extract_tfrecords_features(t)

  

posted on 2020-01-06 15:50  cdekelon  阅读(95)  评论(0)    收藏  举报

导航