2016-06-23 8 views
9

मैं flow_from_directory उपयोग कर रहा हूँ प्रशिक्षण निम्नलिखित संरचना के साथ एक फ़ोल्डर से सेट प्राप्त करने के लिए:एकाधिक कक्षाओं पर प्रशिक्षण करते समय केरास में लेबल आईडी कैसे प्राप्त करें?

train 
    class1 
    class2 
    class3 
    ... 

जनरेटर के रूप में यह इस प्रकार कहा जाता है:

train_generator = train_datagen.flow_from_directory( 
     train_data_dir,        
     target_size=(img_height, img_width),   
     batch_size=32,        
     class_mode='categorical') 

मैं तर्क classes की स्थापना नहीं कर रहा हूँ, लेकिन मैं लेबल को वर्णानुक्रम में प्राप्त करने की उम्मीद कर रहा था।

classes: optional list of class subdirectories (e.g. ['dogs', 'cats']). Default: None. If not provided, the list of classes will be automatically inferred (and the order of the classes, which will map to the label indices, will be alphanumeric).

हालांकि

, जब मैं प्रशिक्षण छवियों (चेकिंग जो लेबल में लौटाए जा रहे के लिए) को वर्गीकृत, मैं किसी भी विशिष्ट आदेश नहीं मिलता है। प्रशिक्षण अच्छी तरह से चला जाता है (~ 85% की शुद्धता), और उसी वर्ग से छवियों को वर्गीकृत करते समय आउटपुट लेबल के साथ एक स्थिरता है।

मैं flow_from_directory द्वारा उत्पन्न लेबल संख्याओं का अनुमान कैसे लगा सकता हूं और उन्हें कक्षाओं में मानचित्रित कर सकता हूं?

+0

यह समस्या से तय हुई थी पर एक उदाहरण है [इस पुल अनुरोध] (https://github.com/fchollet/keras/pull/3052)। –

उत्तर

13

आप देख सकते हैं कि किस वर्ग पत्र व्यवहार करने के जो चर ImageDataGenerator.class_indices

यहाँ पर देख रहे हैं पूर्णांक कैसे उपयोग करने के लिए यह

def build(source=None): 
     datagen = ImageDataGenerator(rescale=1./255) 
     data_generator = datagen.flow_from_directory(
     source, # this is the target directory 
     target_size=(150, 150), # all images will be resized to 150x150 
     batch_size=11, 
     class_mode='sparse') 
     class_dictionary = data_generator.class_indices 
    return data_generator, class_dictionary 
+0

बढ़िया! धन्यवाद!! –

+0

मुझे त्रुटि मिलती है: 'ImageDataGenerator' ऑब्जेक्ट में कोई विशेषता नहीं है 'class_indices' –

+0

यह बिना कहने के जा सकता है, लेकिन यदि आप नहीं चाहते हैं कि 'build()' फ़ंक्शन चलाते समय इस मामले में class_dictionary स्वचालित रूप से वापस लौटाया जाए, तो आप कर सकते हैं करें: 'global class_dictionary', फिर' class_dictionary = data_generator.class_indices' जो आपको वैश्विक स्तर पर class_dictionary तक पहुंचने की अनुमति देगा। –

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