2017-05-18 18 views
7

Kestiricilerden oluşan bir vektör verildiğinde iki çıkışı tahmin etmekle uğraşan bir problemim var. x1, y1'un x1, y1 koordinatlarını ve att's'un x1, y1 koordinatlarının oluşumuna eklenmiş olan diğer öznitelikler olduğunu belirten bir belirteç vektörünün x1, y1, att1, att2, ..., attn gibi göründüğünü varsayalım. Bu tahmin setine dayanarak, x2, y2 değerini tahmin etmek istiyorum. Bu, çoklu regresyon kullanarak çözmeyi denediğim bir zaman serisi problemidir. Sorum, son katmana 2 çıkış verebilen keçileri nasıl kurarım. Ben kerasındaki basit regresyon problemini çözdüm ve kod my github'da kullanılabilir.Keras'ta çoklu çıktılar

cevap

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

yüzden doğru o zaman ne demek istediğini anlamadıysam geçerli: 'InputShape = (10,)' 'model_1 = Sıralı() model_1.add (Yoğun (250, aktivasyon = 'tanh', input_shape = (InputShape))) model_1.add (Yoğun (2, etkinleştirme = 'relu')) model_1.compile (optimizer = 'adam', loss = 'mse', metrikler = ['doğruluk']) model_1. fit (öngörücüler, hedefler, epochs = neyse, ....) ' . Benim sorum şu ki, bu sizinkilerden farklı, sadece iki çıktıyı belirlediğiniz yer. –

+2

Cevabım hakkındaki yorumlar eklendi :) - Sıralı bir modele sahip dallar oluşturamazsınız, bu mümkün değildir. –

+0

@Daniel Hi Daniel, bunu genişletebilir misin? Aradığım şey, iki farklı şeyi tahmin etmeye çalışan bir ağa sahip olmaktı ve bu yüzden iki farklı softmax katmanına beslenen sondan bir önceki katmanımda bir dal resmi çizdikten sonra, bu iki katmanın sonuçlarını bir araya getirip daha sonra tekrar bir araya getirdim Buna göre. Keras'ta bu mümkün değil mi? – tryingtolearn

İlgili konular