我在Keras中有一个具有许多输出的网络,然而,我的训练数据一次只提供单个输出的信息。
目前,我的训练方法是对有问题的输入运行预测,更改我正在训练的特定输出的值,然后执行一次批量更新。如果我是正确的,这与将所有输出的损失设置为零是相同的,除了我试图训练的输出。
有没有更好的方法?我已经尝试了类权重,除了我正在训练的输出之外,我对所有的输出都设置了零权重,但是它没有给我预期的结果?
我正在使用Theano后端。
发布于 2017-08-21 10:35:10
为了达到这个目的,我最终使用了“函数式API”。您基本上创建了多个模型,使用相同的层输入层和隐藏层,但不同的输出层。
例如:
https://keras.io/getting-started/functional-api-guide/
from keras.layers import Input, Dense
from keras.models import Model
# This returns a tensor
inputs = Input(shape=(784,))
# a layer instance is callable on a tensor, and returns a tensor
x = Dense(64, activation='relu')(inputs)
x = Dense(64, activation='relu')(x)
predictions_A = Dense(1, activation='softmax')(x)
predictions_B = Dense(1, activation='softmax')(x)
# This creates a model that includes
# the Input layer and three Dense layers
modelA = Model(inputs=inputs, outputs=predictions_A)
modelA.compile(optimizer='rmsprop',
loss='categorical_crossentropy',
metrics=['accuracy'])
modelB = Model(inputs=inputs, outputs=predictions_B)
modelB.compile(optimizer='rmsprop',
loss='categorical_crossentropy',
metrics=['accuracy'])https://stackoverflow.com/questions/40446488
复制相似问题