1

我想在使用Python圖層的Caffe中實現轉置功能。 以下是相同的代碼。在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 

謝謝, 。 Vijetha

+1

[This](https://github.com/BVLC/caffe/issues/3594)是關於置換層的討論。這可能是相關的。該層的代碼可以在[這裏](https://github.com/intel/caffe/blob/master/src/caffe/layers/permute_layer.cpp)或[這裏](https://github.com/ BVLC/CAFFE /斑點/ b68695db42aa79e874296071927536363fe1efbf/SRC/CAFFE /層/ permute_layer.cpp)。 –

+0

一個落後的傳球又如何轉置梯度? – Shai

回答

1

我認爲你是reshape荷蘭國際集團錯誤地
嘗試:

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

shape論據Reshape給出一個元組,而是作爲一個單獨的參數

+1

工作。謝謝。此外,落後的方法是否正確?我也不太確定這種方法。就像你評論的那樣,我應該轉置從頂部傳遞的上一個漸變嗎? –

+1

@VijethaGattupalli你需要使用top設置bottom [0] .diff。[0] .diff。你需要轉置... – Shai

+0

所以這將是底部[0] .diff = np.transpose(top [0] .diff)。我相信'通過'只會使bottom [0] .diff = top [0] .diff。如果我錯了,請糾正我。 –