【问题标题】:Caffe deploy.prototxt with multiple inputs of different dimensions具有多个不同维度的输入的 Caffe deploy.prototxt
【发布时间】:2023-03-19 12:14:01
【问题描述】:

我在 Caffe 中有一个网络,它接受多个图像输入(可能具有不同的尺寸)并将它们用作网络初始部分的单独 blob。

在训练阶段,我按照文档中的建议通过创建 HDF5 数据库来实现这一点。

但是,对于部署阶段,我需要将训练阶段的数据层替换为输入层,并指定输入 blob 的尺寸。

对于单个 blob,这是通过 input_param 的 shape 属性完成的。在这种情况下,我有多个可能具有不同尺寸的 blob,我该怎么做?

谢谢。

【问题讨论】:

    标签: input neural-network deep-learning caffe dimensions


    【解决方案1】:

    如果您仔细查看caffe.proto,您会发现inputinput_shape 具有repeated 的属性:

    // DEPRECATED. See InputParameter. The input blobs to the network.
    repeated string input = 3;
    // DEPRECATED. See InputParameter. The shape of the input blobs.
    repeated BlobShape input_shape = 8;
    

    这意味着你可以有几个这样的条目:

    name: "AnAmazingNetWithMultipleInputs_ThankYouShai_IwillForeverBeInYourDebt"
    input: "first_input_1x3x127x127"
    input_shape { dim: 1 dim: 3 dim: 127 dim: 127 }
    input: "second_input_2x4x224x224"
    input_shape { dim: 2 dim: 4 dim: 224 dim: 224 }
    # I hope you can take it from here ;)
    

    如果您更仔细地查看caffe.proto 的相关部分,您会注意到这种形式的“输入形状声明”已被弃用。
    更好的方法是使用"Input"层:

    layer {
      type: "Input"
      name: "one_input_layer"
      top: "first_input_1x3x127x127"
      shape { dim: 1 dim: 3 dim: 127 dim: 127 }
      top: "second_input_2x4x224x224"
      shape { dim: 2 dim: 4 dim: 224 dim: 224 }
    }
    

    如果您觉得更容易理解/阅读,您还可以为每个输入设置不同的"Input" 层。

    【讨论】:

    • 谢谢!我应该考虑使用多个输入层!一个疑问:如果我重复使用 top 和 shape ,每个 top 之后必须只有一个 shape 吗?它是如何建立映射关系的?
    • 我想按出场顺序
    • 谢谢@Shai,这很有效。但是,似乎有一个小错误:我认为 shape 是 input_param 的属性,而不是直接的 Input 层。当我尝试在第二个示例中使用它时出现错误,已通过使用 input_param 进行了更正。
    猜你喜欢
    • 2015-11-21
    • 2014-04-17
    • 2018-11-20
    • 2016-09-23
    • 1970-01-01
    • 2016-08-28
    • 2015-12-30
    • 2016-04-17
    • 2017-12-23
    相关资源
    最近更新 更多