2016-08-12 12 views
7

मैं एमएल के लिए अपेक्षाकृत नया हूं और टेन्सफ़ोर्फ़्लो के लिए बहुत नया हूं। मैंने अपने डेटा को पढ़ने का तरीका जानने और समझने के लिए टेंसरफ्लो मिनी ट्यूटोरियल के साथ-साथ https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/how_tos/reading_data पर काफी समय बिताया है, लेकिन मुझे थोड़ी उलझन में आ रहा है।एक निर्देशिका में छवियों को लोड करना Tensorflow डेटा सेट

मेरे पास निर्देशिका/छवियों/0_Non/में छवियों (.png) का एक गुच्छा है। मैं इन्हें एक टेंसरफ्लो डेटा सेट में बनाने की कोशिश कर रहा हूं, इसलिए मैं मूल रूप से मिनी पास ट्यूटोरियल से सामग्री को पहले पास के रूप में चला सकता हूं।

import tensorflow as tf 

# Make a queue of file names including all the JPEG images files in the relative image directory. 
filename_queue = tf.train.string_input_producer(tf.train.match_filenames_once("../images/0_Non/*.png")) 

image_reader = tf.WholeFileReader() 

# Read a whole file from the queue, the first returned value in the tuple is the filename which we are ignoring. 
_, image_file = image_reader.read(filename_queue) 

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) 

    # Get an image tensor and print its value. 
    image_tensor = sess.run([image]) 
    print(image_tensor) 

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

मुझे यहां क्या हो रहा है समझने में कुछ परेशानी हो रही है। तो ऐसा लगता है कि image एक टेंसर है और image_tensor एक numpy सरणी है?

मैं अपनी छवियों को डेटा सेट में कैसे प्राप्त करूं? मैंने आईरिस उदाहरण के साथ भी निम्नलिखित कोशिश की जो एक सीएसवी के लिए है जो मुझे यहां लाया: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/learn/python/learn/datasets/base.py, लेकिन यह सुनिश्चित नहीं था कि यह मेरे मामले के लिए काम कैसे करे, जहां मेरे पास पीएनजी का गुच्छा है।

धन्यवाद!

+0

आप प्रकार का पता लगाने के लिए प्रकार (छवि) का उपयोग कर सकते हैं। एमएनआईएसटी उदाहरणों से आपका डेटासेट प्रारूप/संगठन अलग कैसे है? क्या आप उसी कोड का पुनः उपयोग कर सकते हैं जो एमएनआईएसटी उदाहरण डेटा लोड करता है? –

+0

हम्म। एमएनआईएसटी उदाहरण ऐसा लगता है कि डेटा .tar.gz प्रारूप के रूप में आ रहा है? क्या यह काम करेगा यदि मैंने अभी अपनी पीएनजी की निर्देशिका .tar.gz प्रारूप के रूप में बनाई है? – Vincent

उत्तर

1

हाल ही में जोड़ा tf.data API यह आसान यह करने के लिए बनाता है:

import tensorflow as tf 

# Make a Dataset of file names including all the PNG images files in 
# the relative image directory. 
filename_dataset = tf.data.Dataset.list_files("../images/0_Non/*.png") 

# Make a Dataset of image tensors by reading and decoding the files. 
image_dataset = filename_dataset.map(lambda x: tf.decode_png(tf.read_file(x))) 

# NOTE: You can add additional transformations, like 
# `image_dataset.batch(BATCH_SIZE)` or `image_dataset.repeat(NUM_EPOCHS)` 
# in here. 

iterator = image_dataset.make_one_shot_iterator() 
next_image = iterator.get_next() 

# Start a new session to show example output. 
with tf.Session() as sess: 

    try: 

    while True: 
     # Get an image tensor and print its value. 
     image_array = sess.run([next_image]) 
     print(image_tensor) 

    except tf.errors.OutOfRangeError: 
    # We have reached the end of `image_dataset`. 
    pass 

ध्यान दें कि प्रशिक्षण के लिए आप कहीं से लेबल पाने के लिए की आवश्यकता होगी। Dataset.zip() परिवर्तन एक अलग स्रोत से लेबल के डेटासेट के साथ image_dataset को एक साथ जोड़ने का एक संभावित तरीका है।

संबंधित मुद्दे