【问题标题】:Error in implementing "transpose" layer in Caffe在 Caffe 中实现“转置”层时出错
【发布时间】:2017-04-18 23:48:27
【问题描述】:

我正在尝试使用 Python 层在 Caffe 中实现转置功能。 下面是相同的代码。

但是,在Reshape() 方法中抛出boost::python::error_already_set 的实例后,它会抛出错误“终止调用。

有人可以说明我做错了什么吗?

import caffe
import numpy as np

class transpose(caffe.Layer):

    def setup(self, bottom, top):
        assert len(bottom) == 1,            'requires a single layer.bottom'
        assert bottom[0].data.ndim == 2,    'requires matrix data'
        assert len(top) == 1,               'requires a single layer.top'

    def reshape(self, bottom, top):
        top[0].reshape((bottom[0].data.shape[1], bottom[0].data.shape[0]))

    def forward(self, bottom, top):
        top[0].data = np.transpose(bottom[0].data)

    def backward(self, top, propagate_down, bottom):
        pass

谢谢你, 维杰塔。

【问题讨论】:

  • This 是关于置换层的讨论。这可能是相关的。该层的代码可用herehere
  • 反向传递如何,同时转置渐变?

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


【解决方案1】:

我认为你 reshapeing 不正确。
试试:

def reshape(self, bottom, top):
  top[0].reshape(bottom[0].data.shape[1], bottom[0].data.shape[0])

Reshapeshape 参数作为元组给出,而是作为单独的参数给出。

【讨论】:

  • 那行得通。谢谢你。另外,向后的方法是否正确?我也不太确定这种方法。就像您评论的那样,我应该转置从顶部传递的先前渐变吗?
  • @VijethaGattupalli 您需要使用 top.[0].diff 设置 bottom[0].diff。你需要转置...
  • 所以它会是底部[0].diff = np.transpose(top[0].diff)。我相信“通过”只会使bottom[0].diff = top[0].diff。如果我错了,请纠正我。
  • @VijethaGattupalli pass 表示通过。这意味着我不知道bottom[0].diff 中会发生什么...为什么caffe 要将top[0].diff 分配给bottom[0].diff?
  • 我猜 reshape 方法中的“pass”只会将底层的形状复制到顶部,因此在反向方法中可能会发生类似的事情。但谢谢你的澄清。我现在知道怎么写了。
猜你喜欢
  • 1970-01-01
  • 2017-07-25
  • 2016-12-21
  • 2017-12-20
  • 1970-01-01
  • 2018-07-21
  • 1970-01-01
  • 1970-01-01
  • 2017-04-27
相关资源
最近更新 更多