我正在尝试使用 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
谢谢你, 维杰塔。
最佳答案
我认为您 reshape
不正确。
尝试:
def reshape(self, bottom, top):
top[0].reshape(bottom[0].data.shape[1], bottom[0].data.shape[0])
Reshape
的 shape
参数不是作为元组给出,而是作为单独的参数给出。
关于machine-learning - 在Caffe中实现 "transpose"层时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43484011/