本文整理匯總了Python中attention.ZoomableAttentionWindow.nn2att_wn方法的典型用法代碼示例。如果您正苦於以下問題:Python ZoomableAttentionWindow.nn2att_wn方法的具體用法?Python ZoomableAttentionWindow.nn2att_wn怎麽用?Python ZoomableAttentionWindow.nn2att_wn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類attention.ZoomableAttentionWindow
的用法示例。
在下文中一共展示了ZoomableAttentionWindow.nn2att_wn方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: LocatorReader
# 需要導入模塊: from attention import ZoomableAttentionWindow [as 別名]
# 或者: from attention.ZoomableAttentionWindow import nn2att_wn [as 別名]
class LocatorReader(Initializable):
def __init__(self, x_dim, dec_dim, channels, height, width, N, **kwargs):
super(LocatorReader, self).__init__(name="reader", **kwargs)
self.img_height = height
self.img_width = width
self.N = N
self.x_dim = x_dim
self.dec_dim = dec_dim
self.output_dim = channels * N * N
self.zoomer = ZoomableAttentionWindow(channels, height, width, N)
self.readout = MLP(activations=[Identity()], dims=[dec_dim, 7], **kwargs)
self.children = [self.readout]
def get_dim(self, name):
if name == 'input':
return self.dec_dim
elif name == 'x_dim':
return self.x_dim
elif name == 'output':
return self.output_dim
else:
raise ValueError
@application(inputs=['x', 'h_dec'], outputs=['r', 'l'])
def apply(self, x, h_dec):
l = self.readout.apply(h_dec)
center_y, center_x, deltaY, deltaX, sigmaY, sigmaX, gamma = self.zoomer.nn2att(l)
w = gamma * self.zoomer.read(x, center_y, center_x, deltaY, deltaX, sigmaY, sigmaX)
return w, l
@application(inputs=['h_dec'], outputs=['center_y', 'center_x', 'deltaY', 'deltaX'])
def apply_l(self, h_dec):
l = self.readout.apply(h_dec)
center_y, center_x, deltaY, deltaX = self.zoomer.nn2att_wn(l)
return center_y, center_x, deltaY, deltaX