如何在CAFFE中的新网络中重复使用同一网络两次



我有一个预训练的网络(我们称之为N),我想在一个新网络中使用两次。有人知道怎么复制吗?然后我想给每个副本分配一个不同的学习率。

例如(N1N的第一个副本,N2N的第二个副本),新网络可能看起来像:

N1 --> [joint ip 
N2 -->    layer]

我知道如何用一个副本重用N,但是,由于N1N2的学习率不同(微调),我不知道如何制作两个N副本,并为每个副本分配不同的学习率。

谢谢!

两次使用同一个网络被称为"暹罗网络"。它在caffe中的实现方式是显式复制网络,但对每个参数blob使用"name" param来创建底层参数的单个副本。例如,请参阅此prototxt
一旦您明确地在网络上排便两次,您就可以为每个副本分配不同的"lr_mult"参数。

因此,假设您的参考网络N有一个输入层(在本例中我将跳过它)和一个名为"ip1"的内积层。然后

 layer {
   name: "ip1_a"
   bottom: "data_a"
   top: "ip1_a"
   type: "InnerProduct"
   inner_product_param {
     num_output: 10
   }
   param {
     name: "ip1_w"  # NOTE THIS NAME!
     lr_mult: 1
   }
   param {
     name: "ip1_b"
     lr_mult: 2
   }
 }
 layer {
   name: "ip1_b"
   bottom: "data_b"
   top: "ip1_b"
   type: "InnerProduct"
   inner_product_param {
     num_output: 10
   }
   param {
     name: "ip1_w"  # NOTE THIS NAME: it's the same!
     lr_mult: 10 # different LR for this branch
   }
   param {
     name: "ip1_b"
     lr_mult: 20
   }
 }
 # one layer to combine them     
 layer {
   type: "Concat"
   bottom: "ip1_a"
   bottom: "ip1_b"
   top: "ip1_combine"
   name: "concat"
 }
 layer {
   name: "joint_ip"
   type: "InnerProduct"
   bottom: "ip1_combine"
   top: "joint_ip"
   inner_product_param {
     num_output: 30
   }
 } 

如果您进行微调,您可能需要进行一些网络操作,以便将原始wiegs保存在名为"ip1_w""ip1_b".caffemodel文件中。

最新更新