database - How to create TFRecords file from png images -


i'm started working tensorflow week ago, , have basic problems.

the major 1 didn't find way create tfrecords contains data. understood process necessary in order train own network few millions 32x32 pixels images.

i've found lot of tutorials , lot of documentations referring "input_pipeline", none of tutorials explained how create own database, own images.

i have few major folders , sub-folders, ~300,000 png images each, label in name of image (0 or 1 - binary classification).

the way images trough (glob) lines:

"/home/roishik/desktop/database/train/exp*/*png" "/home/roishik/desktop/database/train/exp*/tot*/*png" 

so question is:

how create tfrecords file contains images , labels?

i'll appreciate help! i'm stuck problem 2 days, , found specific answers mnit , imagenet.

thanks!

millions of 32x32 images? sounds cifar. check out tensorflow models, have script download cifar10 , convert tfrecords: download_and_convert_data.py. if data not cifar, check out code anyway, you.

the code loads cifar10 looks this:

with tf.graph().as_default():     image_placeholder = tf.placeholder(dtype=tf.uint8)     encoded_image = tf.image.encode_png(image_placeholder)      tf.session('') sess:         j in range(num_images):             [...] # load image , label disk             image = [...]             label = [...]              png_string = sess.run(encoded_image,                                   feed_dict={image_placeholder: image})              example = dataset_utils.image_to_tfexample(                 png_string, 'png', _image_size, _image_size, label)             tfrecord_writer.write(example.serializetostring())             [...] 

the image_to_tfexample() function looks this:

def image_to_tfexample(image_data, image_format, height, width, class_id):     return tf.train.example(features=tf.train.features(feature={         'image/encoded': bytes_feature(image_data),         'image/format': bytes_feature(image_format),         'image/class/label': int64_feature(class_id),         'image/height': int64_feature(height),         'image/width': int64_feature(width),     })) 

and int_64_feature() function looks (the bytes_feature() function similar):

def int64_feature(values):     if not isinstance(values, (tuple, list)):         values = [values]     return tf.train.feature(int64_list=tf.train.int64list(value=values)) 

edit

a few more details:

  • the tfrecordwriter created (this creates file):

    with tf.python_io.tfrecordwriter(training_filename) tfrecord_writer:     [...] # use tfrecord_writer 
  • the documentation tf.image.encode_png() says image should have shape [height, width, channels], channels = 1 grayscale, channels = 2 grayscale + alpha, 3 rgb color, , channels = 4 rgb color + alpha (rgba).


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -