0

Ich habe ein Verzeichnis von PNG-Dateien. Es gibt einen Zugordner und einen Testordner. Im Zugordner habe ich 10 Ordner als 10 Labels [0 -9]. Jeder Ordner enthält PNG-Dateien dieses Labels. Ich möchte sie zum Trainieren in Tensor Flow laden. Ich bin neu in Tensor Flow i eine sehr harte Zeit habe dieseWie kann ich ein Verzeichnis von Png in Tensorflow laden?

i anaconda bin mit (py ver 3,5)

import tensorflow as tf 


filename_queue = tf.train.string_input_producer(
    tf.train.match_filenames_once("./images/*.jpg")) 

image_reader = tf.WholeFileReader() 

ich versucht habe zu erledigen dies mit aber es funktioniert. es lädt nur 1 Bild

Antwort

0

Es funktioniert aber für mich. Können Sie dieses Skript ausführen? (Stand Labels zu erhalten, wie gut)

import tensorflow as tf 
filename_queue = tf.train.string_input_producer(
tf.train.match_filenames_once("/home/xxx/Desktop/stackoverflow/images/*/*.png")) 

image_reader = tf.WholeFileReader() 
key, image_file = image_reader.read(filename_queue) 
S = tf.string_split([key],'/') 
length = tf.cast(S.dense_shape[1],tf.int32) 
# adjust constant value corresponding to your paths if you face issues. It should work for above format. 
label = S.values[length-tf.constant(2,dtype=tf.int32)] 
label = tf.string_to_number(label,out_type=tf.int32) 
image = tf.image.decode_png(image_file) 

# Start a new session to show example output. 
with tf.Session() as sess: 
    # Required to get the filename matching to run. 
    tf.initialize_all_variables().run() 

    # Coordinate the loading of image files. 
    coord = tf.train.Coordinator() 
    threads = tf.train.start_queue_runners(coord=coord) 

    for i in xrange(6): 
     # Get an image tensor and print its value. 
     key_val,label_val,image_tensor = sess.run([key,label,image]) 
     print(image_tensor.shape) 
     print(key_val) 
     print(label_val) 


    # Finish off the filename queue coordinator. 
    coord.request_stop() 
    coord.join(threads) 

Dateiverzeichnis

./images/1/1.png 
./images/1/2.png 
./images/3/1.png 
./images/3/2.png 
./images/2/1.png 
./images/2/2.png 

Ausgang:

(881, 2079, 3) 
/home/xxxx/Desktop/stackoverflow/images/3/1.png 
3 
(155, 2552, 3) 
/home/xxxx/Desktop/stackoverflow/images/2/1.png 
2 
(562, 1978, 3) 
/home/xxxx/Desktop/stackoverflow/images/3/2.png 
3 
(291, 2558, 3) 
/home/xxxx/Desktop/stackoverflow/images/1/1.png 
1 
(157, 2554, 3) 
/home/xxxx/Desktop/stackoverflow/images/1/2.png 
1 
(866, 936, 3) 
/home/xxxx/Desktop/stackoverflow/images/2/2.png 
2 
+0

Vielen Dank u sehr viel ..es funktioniert, aber ich bekomme nicht, wie die Etiketten und das Image des Beziehung behandelt werden –

+0

@FarshidRayhan, habe ich Skript hinzugefügt, um Beschriftungen für jedes Bild zu erhalten. Bitte führen Sie das Skript aus und überprüfen Sie die Beschriftung - Bildpaare sind korrekt. Ich hoffe, das löst deine Aufgabe. – hars

+0

@FarshidRayhan, hat meine Antwort Ihnen geholfen? – hars

Verwandte Themen