python - How to stack channels in Tensorflow input pipeline? -


i started working tf few weeks ago , struggling input queue right now. want following: have folder 477 temporal, greyscale images. want e.g. take first 3 images , stack them (=> 600,600,3), single example 3 channels. next want take fourth image , use label (just 1 channel => 600,600,1). want pass both tf.train.batch , create batches.

i think found solution, see code below. wondering if there more fashionable solution.

my actual question is: happens @ end of queue. since i'm picking 4 images queue (3 input, 1 label) , have 477 images in queue, things not working out. tf fill queue again , continues (so if there 1 image left in queue, takes image, fills queue again , take 2 more images desired 3 images?). or need number of images divisible 4 in folder if want proper solution?

def read_image(filename_queue):   reader = tf.wholefilereader()   _, value = reader.read(filename_queue)   image = tf.image.decode_png(value, dtype=tf.uint8)   image = tf.cast(image, tf.float32)   image = tf.image.resize_images(image, [600, 600])   return image  def input_pipeline(file_names, batch_size, num_epochs=none):    filename_queue = tf.train.string_input_producer(file_names, num_epochs=num_epochs, shuffle=false)   image1 = read_image(filename_queue)   image2 = read_image(filename_queue)   image3 = read_image(filename_queue)   image = tf.concat([image1, image2, image3,], axis=2)   label = read.image(filename_queue)    # reshape necessary, otherwise error..   image = tf.reshape(image, [600, 600, 3])   label = tf.reshape(label, [600, 600, 1])    min_after_dequeue = 200   capacity = min_after_dequeue + 12 * batch_size   image_batch, label_batch = tf.train.batch([image, label],                              batch_size=batch_size,                              num_threads=12,                              capacity=capacity)   return image_batch, label_batch 

thanks help!

but wondering if there more fashionable solution

yes! there's better , faster solution. first redesign database, since want combine 3 gray images 1 rgb images training; prepare dataset of rgb images gray images (it save whole lot of time during training).

redesign way retrieve data

  # retrieve image , corresponding label @ same time    # here if set num_epochs=none, queue run continuously; , take-care of data need training till end   filename_queue = tf.train.string_input_producer([file_names_images_list, corresponding_file_names_label_list], num_epochs=none, shuffle=false)    image = read_image(filename_queue[0])   label = read_image(filename_queue[1]) 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -