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

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

有人可以告诉我我在做什么错吗?

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


谢谢,
Vijetha。

最佳答案

我认为您的reshape错误。
尝试:

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


shapeReshape自变量不是整数,而是作为单独的自变量。

关于machine-learning - 在Caffe中实现“转置”层时出错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43484011/

10-12 19:27