【发布时间】:2021-09-10 17:16:13
【问题描述】:
之前有人问过类似的问题,但答案并不令人满意。
给定一个使用 keras 中的功能 API 制作的模型。
在训练模型时,我们有两个输入和一个输出。一种输入是图像。另一个输入是自定义损失函数所需的一组成本。
然而,在推理过程中,我们将只获得图像作为输入,并且没有任何成本。因此只有一个输入和一个输出。
如何调整在两个输入上训练过的相同模型进行推理?
训练时的模型有点像这样:
input1 = Input(shape=(64,64,3)) #RGB Image
input2 = Input(shape=(4,))#Costs associated with the image, input to the custom loss function
conv1 = Conv2D(16, 3 , padding = 'same', activation = 'relu')(input1)
#Other layers
output = Dense(6)(x) # last layer gives classification output
model = Model(inputs = [input1, input2] , outputs = output)
model.compile(loss = custom_loss_function(input2) , optimizer = 'adam')
这是训练期间的模型。
当图像只需要一个输入并且没有成本输入时,在推理过程中该怎么做?
【问题讨论】:
标签: python tensorflow keras deep-learning computer-vision