Hello, everyone
I called RoIAlignFunction from RoIAlignAvg
but there is an error
‘RoIAlignFunctionBackward’ object has no attribute ‘aligned_height’
How can I solve this problem???
Thank you in advance and have a nice day
##############
class RoIAlignAvg(Module):
def init(self, aligned_height, aligned_width, spatial_scale):
super(RoIAlignAvg, self).init()
self.align_function = RoIAlignFunction(aligned_height+1, aligned_width+1, spatial_scale)
def forward(self, features, rois):
x = self.align_function.apply(features, rois)
return avg_pool2d(x, kernel_size=2, stride=1)
#############
class RoIAlignFunction(Function):
def init(self, aligned_height, aligned_width, spatial_scale):
self.aligned_width = int(aligned_width)
self.aligned_height = int(aligned_height)
self.spatial_scale = float(spatial_scale)
self.rois = None
self.feature_size = None
@staticmethod
def forward(self, features, rois):
self.rois = rois
self.feature_size = features.size()
batch_size, num_channels, data_height, data_width = features.size()
num_rois = rois.size(0)
######### error occurs here!!
output = features.new(num_rois, num_channels, self.aligned_height, self.aligned_width).zero_()
roi_align.roi_align_forward(self.aligned_height,self.aligned_width,self.spatial_scale, features,rois, output)
return output
@staticmethod
def backward(self, grad_output):
batch_size, num_channels, data_height, data_width = self.feature_size
grad_input = self.rois.new(batch_size, num_channels, data_height,data_width).zero_()
roi_align.roi_align_backward_cuda(self.aligned_height,self.aligned_width,self.spatial_scale,grad_output,self.rois, grad_input)
return grad_input, None