Git Product home page Git Product logo

tfrecordcreator-tfrecordloarder's Introduction

Tfrecord Creator and Loader

  • Convenient functions for converting datasets to tfrecord and loading it.

Features

  1. Support classification, regression and multiple label tasks.
  2. Support image encoding (jpg or png) and decoding, which makes the tfrecord file smaller.
  3. Support preprocessing functions for data and labels.

Usage

  • create a tfrecord and add a sample

    writer = tfrecord.ImageLablePairTfrecordCreator(
        save_path='classification_tfrecord',
        encode_type='jpg',
        data_name='img',
        compression_type=0)
    
    writer.add(np.array(img), {"class": np.array(label)})
  • load a tfrecord and get a batch

    TR = tfrecord.TfrecordData(
        tfrecord_path='classification_tfrecord',
        batch_size=5,
        shuffle=True,
        num_threads=4)
    
    for i in range(iter):
        img_batch, class_batch = TR.batch(['img', 'class'])
    
    or
    
    for batch in TR:
        img_batch, class_batch = batch['img'], batch['class']
    • preprocessing
      def img_preprecess_fn(img):
          img = tf.image.resize_images(img, [256, 128])
          img = img / 255
          return img
      
      TR = tfrecord.TfrecordData(
          tfrecord_path='classification_tfrecord',
          batch_size=5,
          shuffle=True,
          num_threads=4,
          preprocess_fns={
              'img': img_preprecess_fn
          })
      
      img_batch, class_batch = TR.batch(['img', 'class'])
  • More examples are in examples_create.py and examples_load.py, just run it!

Prerequisites

  • tensorflow >= r1.2
  • python 2.7

tfrecordcreator-tfrecordloarder's People

Contributors

lynnho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

tfrecordcreator-tfrecordloarder's Issues

assert isinstance(data, str), '`data` should be byte string!'

hi lynnho

thanks for this solution. i tried this solution for making tfr

but i have this alert 'assert isinstance(data, str), 'data should be byte string!''

I never did not modify the code. i just run the code

my system is
os : windows7, python 3.6.3, tensorflow

thanks for comment

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.