2017-08-31 5 views
1

Ich habe die Namen und Beschriftungen eines Bildes als Liste und ich möchte einen Stapel von 64 Bildern/Beschriftungen erhalten. Ich könnte die Bilder richtig bekommen, aber für Beschriftungen ist ihre Dimension (64,8126). Jede Spalte hat 64 Mal das gleiche Element. Und Zeilen bestehen aus 8126 ursprünglichen Label-Werten, ohne gemischt zu werden.Wie behandelt man Etiketten in der Eingabepipeline?

Ich verstehe das Problem, dass tf.train.shuffle_batch für jeden Bild 8126 Element Label-Vektor berücksichtigt. Aber wie würde ich nur ein einzelnes Element für jedes Bild weitergeben?

def _get_images(shuffle=True): 

"""Gets the images and labels as a batch""" 

    #get image and label list 
    _img_names,_img_class = _get_list() #list of image names and labels 

    filename_queue = tf.train.string_input_producer(_img_names) 

    #reader 
    image_reader = tf.WholeFileReader() 
    _, image_file = image_reader.read(filename_queue) 

    #decode jpeg 
    image_original = tf.image.decode_jpeg(image_file) 
    label_original = tf.convert_to_tensor(_img_class,dtype=tf.int32) 
    #print label_original 

    #image preprocessing 
    image = tf.image.resize_images(image_original, [224,224]) 
    float_image = tf.cast(image,dtype=tf.float32) 
    float_image = tf.image.per_image_standardization(image) 
    #set the shape 
    float_image.set_shape((224, 224, 3)) 
    #label_original.set_shape([8126]) #<<<<<=========== causes (64,8126) dimension label without shuffle 

    #parameters for shuffle 
    batch_size = 64 
    num_preprocess_threads = 16 
    num_examples_per_epoch = 8000 
    min_fraction_of_examples_in_queue = 0.4 
    min_queue_examples = int(num_examples_per_epoch * 
         min_fraction_of_examples_in_queue) 

    if shuffle: 
     images_batch, label_batch = tf.train.shuffle_batch(
      [float_image,label_original], 
      batch_size=batch_size, 
      num_threads=num_preprocess_threads, 
      capacity=min_queue_examples + 3 * batch_size, 
      min_after_dequeue=min_queue_examples) 
    else: 
     images_batch, label_original = tf.train.batch(
      [float_image,_img_class], 
      batch_size=batch_size, 
      num_threads=num_preprocess_threads, 
      capacity=min_queue_examples + 3 * batch_size) 

    return images_batch,label_batch 

Antwort

0

Sie tf.train.slice_input_producer

# here _img_class should be a list 
labels_queue = tf.train.slice_input_producer([_img_class]) 
... 
images_batch, label_batch = tf.train.shuffle_batch(
     [float_image,labels_queue], 
     batch_size=batch_size, 
     num_threads=num_preprocess_threads, 
     capacity=min_queue_examples + 3 * batch_size, 
     min_after_dequeue=min_queue_examples) 
+0

Greatttt verwenden !! Danke, sehr angenehm! –

Verwandte Themen