【问题标题】:Changing the final layer in caffe更改 caffe 中的最后一层
【发布时间】:2017-05-03 14:31:21
【问题描述】:

这是问题here 的扩展,该问题是关于如何在训练前将现有权重添加到模型中。

我想使用现有的权重,但我的最后一层输出的是 50 而不是 1000(因为网络经过训练可以对 1000 个项目进行分类)。在上一篇文章中,通过更改输出层的名称,我能够添加权重。但后来我意识到还有其他层依赖于最后一层。这是来自 VGG 网络的 sn-p:

 layer {
   name: "loss3/classifier"
   type: "InnerProduct"
   bottom: "pool5/7x7_s1"
   top: "loss3/classifier"
   param {
     lr_mult: 1
     decay_mult: 1
   }
   param {
     lr_mult: 2
     decay_mult: 0
   }
   inner_product_param {
     num_output: 50
     weight_filler {
       type: "xavier"
     }
     bias_filler {
       type: "constant"
       value: 0
     }
   }
 }
 layer {
   name: "loss3/loss3"
   type: "SoftmaxWithLoss"
   bottom: "loss3/classifier"
   bottom: "label"
   top: "loss3/loss3"
   loss_weight: 1
 }
 layer {
   name: "loss3/top-1"
   type: "Accuracy"
   bottom: "loss3/classifier"
   bottom: "label"
   top: "loss3/top-1"
   include {
     phase: TEST
   }
 }
 layer {
   name: "loss3/top-5"
   type: "Accuracy"
   bottom: "loss3/classifier"
   bottom: "label"
   top: "loss3/top-5"
   include {
     phase: TEST
   }
   accuracy_param {
     top_k: 5
   }
 }

我的问题是:

  1. 到底什么是底部和顶部参数?

  2. 后面两层“loss3/classifier”的名称需要改吗?

【问题讨论】:

    标签: machine-learning neural-network deep-learning caffe


    【解决方案1】:

    这是一个相当基本的问题。我强烈建议您阅读一些文档和基本的 caffe 教程来了解 caffe 的基础知识。 This tutorial 是一个很好的起点。


    深度网络具有描述从网络输入到预测输出的数据“流”的底层图。您在问题中附加的 sn-p 描述了一个这样的图表。
    每一层代表“数据路径”上的一个“处理单元”:其输入是"bottom" blob,层将其处理后的数据作为"top" blob 输出。
    所以,如果你有一个图层

    layer {
      name: "loss3/classifier"
      type: "InnerProduct"
      bottom: "pool5/7x7_s1"
      top: "loss3/classifier"
      ...
    }
    

    此层执行"InnerProduct" 操作(由层的type 定义)。它对输入 blob "pool5/7x7_s1"(定义为 bottom)执行操作,并将结果输出到 blob "loss3/classifier"(定义为 top blob)。该层的可学习参数(权重和偏差)由 caffe 使用层的名称 "loss3/classifier" 存储和访问。
    因此,如果您将图层的 name 更改为 "loss3/classifier_50" 而不 更改 top 您将获得所需的效果:caffe 不会复制此图层的权重,但将保持这一层的输出连接到其他层。


    顺便说一句,
    您确定您使用的是 VGG 网络吗?这个 prototxt 看起来像 GoogLeNet 架构...
    请注意,AlexNet、VGG 和 GoogLeNet 是三个完全不同的网络。

    【讨论】:

    • 啊,是的。你说的对。是谷歌网络。我为这样的基本问题道歉。我一定会复习教程。谢谢!
    猜你喜欢
    • 2018-08-18
    • 2018-02-05
    • 1970-01-01
    • 2017-05-10
    • 1970-01-01
    • 2022-01-23
    • 1970-01-01
    • 2017-06-20
    • 2016-09-21
    相关资源
    最近更新 更多