简体   繁体   English

Caffe使用自定义成本函数针对输入计算梯度

[英]Caffe compute gradient with respect to input using custom cost function

I have a pretrained caffe model with no loss layers. 我有一个没有损失层的预训练caffe模型。 I want to do the following steps: 我要执行以下步骤:

  1. Compute the cost/grad of some layer in the net. 计算网络中某一层的成本/等级。
  2. Backpropagate to compute the gradient with respect to the input layer. 反向传播以计算相对于输入层的渐变。
  3. Perform gradient descent repeating 1 and 2 to optimize input. 执行梯度下降重复1和2以优化输入。

I can not figure out how to add a loss layer to a pretrained model to do this. 我不知道如何为预训练模型添加损耗层。 In other NN frameworks you can call a backward() function and pass a cost function. 在其他NN框架中,您可以调用Backward()函数并传递一个cost函数。 Is there any way to do this in caffe? 有什么办法可以做到吗?

You can create a custom layer in caffe for your cost function. 您可以在caffe中为您的成本函数创建自定义图层。 Make a call to this cost function in the .prototxt file. 在.prototxt文件中对此费用函数进行调用。 You can finetune a pretrained model using your new cost function. 您可以使用新的成本函数微调预训练的模型。

Finetuning is done using the below format of coomandline code: 使用以下coomandline代码格式进行微调:

./build/tools/caffe train --solver theAboveMentioned.prototxt --weights thePreTrainedWeightsFile

More on caffe finetuning can be found here . 有关咖啡微调的更多信息,请参见此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM