本文整理汇总了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