【问题标题】:How to understand Caffe reshape parameters and reimplement in Keras?在 Keras 中如何理解 Caffe reshape 参数和重新实现?
【发布时间】:2018-05-11 02:03:59
【问题描述】:

我不确定如何解释重塑参数。这里http://caffe.berkeleyvision.org/tutorial/layers/reshape.html 表示 0 表示复制,-1 表示推断。当 -1 不是最后一个参数时是否相同?谁能帮我理解一下?

 layer {
  name: "Layer1"
  type: "Reshape"
  bottom: "Layer1"
  top: "Layer2"
  reshape_param {
  shape {
      dim: 0
      dim: 2
      dim: -1
      dim: 0
}
}

另外,如果我想在 Keras 中实现相同的层,我是否也使用 Keras 重塑层,例如:

Layer2 = K.reshape(Layer1,(-1,input_dim)) 

【问题讨论】:

标签: neural-network keras caffe reshape layer


【解决方案1】:

这意味着考虑到您有一个形状为(a, b, c, d, e) 的输入,您的输出将具有以下形状:

(a, 2, b * c * e / 2, d)

ad 是从上一层复制而来的。值 2 是强制的,值 -1 计算保持与输入相同数量的元素所需的任何值。

在 Keras 中,由于您没有更改第一个维度(批量大小),因此您只需要一个常规的 Reshape 层来忽略批量大小:

Reshape((2,-1,youMustKnowThis)) 

Sequential 模型中,只需添加这一层:

sequentialModel.add(Reshape((2,-1,youMustKnowThis))

在函数式 API Model 中,传递上一层的输出:

newShaped = Reshape((2,-1,youMustKnowThis))(outputOfPreviousLayer)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-02
    • 1970-01-01
    • 2015-11-21
    • 1970-01-01
    • 1970-01-01
    • 2020-10-10
    • 1970-01-01
    相关资源
    最近更新 更多