2017-05-18 10 views
7

में एकाधिक आउटपुट मुझे एक समस्या है जो भविष्यवाणियों के वेक्टर दिए जाने पर दो आउटपुट की भविष्यवाणी करने से संबंधित है। मान लें कि भविष्यवाणी वेक्टर x1, y1, att1, att2, ..., attn जैसा दिखता है, जो कहता है कि x1, y1 निर्देशांक हैं और att'sx1, y1 समन्वय की घटना से जुड़े अन्य गुण हैं। इस भविष्यवाणियों के सेट के आधार पर मैं x2, y2 की भविष्यवाणी करना चाहता हूं। यह एक समय श्रृंखला समस्या है, जिसे मैं एकाधिक प्रतिगमन का उपयोग करके हल करने की कोशिश कर रहा हूं। मेरा सवाल यह है कि मैं कैरस कैसे सेट करूं, जो मुझे अंतिम परत में 2 आउटपुट दे सकता है। मैंने कैमरे में सरल प्रतिगमन समस्या हल की है और कोड my github में उपलब्ध नहीं है।केरस

उत्तर

11
from keras.models import Model 
from keras.layers import *  

#inp is a "tensor", that can be passed when calling other layers to produce an output 
inp = Input((10,)) #supposing you have ten numeric values as input 


#here, SomeLayer() is defining a layer, 
#and calling it with (inp) produces the output tensor x 
x = SomeLayer(blablabla)(inp) 
x = SomeOtherLayer(blablabla)(x) #here, I just replace x, because this intermediate output is not interesting to keep 


#here, I want to keep the two different outputs for defining the model 
#notice that both left and right are called with the same input x, creating a fork 
out1 = LeftSideLastLayer(balbalba)(x)  
out2 = RightSideLastLayer(banblabala)(x) 


#here, you define which path you will follow in the graph you've drawn with layers 
#notice the two outputs passed in a list, telling the model I want it to have two outputs. 
model = Model(inp, [out1,out2]) 
model.compile(optimizer = ...., loss = ....) #loss can be one for both sides or a list with different loss functions for out1 and out2  

model.fit(inputData,[outputYLeft, outputYRight], epochs=..., batch_size=...) 
+0

तो अगर मैं तुम्हें सही ढंग से तो तुम क्या मतलब समझते हैं: 'InputShape = (10,)' ' model_1 = अनुक्रमिक() model_1.add (घने (250, सक्रियण = 'tanh', input_shape = (इनपुटशिप))) model_1.add (घन (2, सक्रियण = 'relu')) model_1.compile (optimizer = 'adam', loss = 'mse', मेट्रिक्स = ['सटीकता']) मॉडल_1। फिट (predictors, लक्ष्य, epochs = जो भी, ....) ' । मेरा सवाल यह है कि यह आपके से अलग कैसे है, जहां आप विशेष रूप से दो आउटपुट निर्दिष्ट कर रहे हैं। –

+2

मेरे उत्तर में टिप्पणी जोड़ा गया :) - आप अनुक्रमिक मॉडल के साथ शाखाएं नहीं बना सकते हैं, यह संभव नहीं है। –

+0

@ डैनियल हाय डैनियल, क्या आप उस पर विस्तार कर सकते हैं? जो मैं खोज रहा हूं वह एक ऐसा नेटवर्क है जो दो अलग-अलग चीजों की भविष्यवाणी करने का प्रयास करता है और इसलिए मैं अपनी अंतिम परत पर होने वाली शाखा को चित्रित कर रहा था जो दो अलग-अलग सॉफ्टमैक्स परतों में फ़ीड करता है, फिर मैं उन दो परतों के परिणामों को जोड़ता हूं और फिर बैकप्रोपोगेट इसके संबंध में। क्या यह कैरस में संभव नहीं है? – tryingtolearn