I need to perform the transpose operation on a blob(2D matrix) in order to implement a loss function.
Below is the code for my layer.
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
It is throwing the error "terminate called after throwing an instance of 'boost::python::error_already_set' " at Reshape() method.