machine-learning - 在Caffe中实现 "transpose"层时出错

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

我正在尝试使用 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/

相关文章:

c++ - 深度神经网络的图像识别精度,float 还是 double?

python - 使用 SGD 分类器和 GridsearchCV 查找最重要的特征

machine-learning - 检查输入 : expected conv2d_27_input to have 4 dimensions, 但获得形状为 (55000, 28, 28) 的数组时出错

python - 有没有办法使用 TRAINS python 包创建一个比较超参数与模型精度的图表?

indexing - 从打包序列中获取每个序列的最后一项

python - 具有多个输入的 Keras TimeDistributed 层

python - 使用文本特征提取创建数据集

python - 无法确定 Keras 中卷积层的输入形状和类型

machine-learning - 如何保存 keras 实验运行产生的数据结果?

python - 如何计算序列的交叉熵损失