本文整理匯總了Python中torch.nn.modules.module.Module方法的典型用法代碼示例。如果您正苦於以下問題:Python module.Module方法的具體用法?Python module.Module怎麽用?Python module.Module使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類torch.nn.modules.module
的用法示例。
在下文中一共展示了module.Module方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: forward
# 需要導入模塊: from torch.nn.modules import module [as 別名]
# 或者: from torch.nn.modules.module import Module [as 別名]
def forward(self, input):
# if not self.aux_loss:
return self.f(input)
# else:
# identity = torch.from_numpy(np.array([[1,0,0], [0,1,0]], dtype=np.float32))
# batch_identity = torch.zeros([input.size(0), 2,3])
# for i in range(input.size(0)):
# batch_identity[i] = identity
# batch_identity = Variable(batch_identity)
# loss = torch.mul(input - batch_identity, input - batch_identity)
# loss = torch.sum(loss,1)
# loss = torch.sum(loss,2)
# return self.f(input), loss.view(-1,1)
# class CylinderGridGen(Module):
# def __init__(self, height, width, lr = 1, aux_loss = False):
# super(CylinderGridGen, self).__init__()
# self.height, self.width = height, width
# self.aux_loss = aux_loss
# self.f = CylinderGridGenFunction(self.height, self.width, lr=lr)
# self.lr = lr
# def forward(self, input):
# if not self.aux_loss:
# return self.f(input)
# else:
# return self.f(input), torch.mul(input, input).view(-1,1)
示例2: forward
# 需要導入模塊: from torch.nn.modules import module [as 別名]
# 或者: from torch.nn.modules.module import Module [as 別名]
def forward(self, input1, input2):
return minDepthFlowProjectionLayer.apply(input1, input2,self.requires_grad)
# class FlowFillholeModule(Module):
# def __init__(self,hole_value = -10000.0):
# super(FlowFillholeModule, self).__init__()
# self.f = FlowFillholeLayer()
#
# def forward(self, input1):
# return self.f(input1)
#we actually dont need to write the backward code for a module, since we have
示例3: forward
# 需要導入模塊: from torch.nn.modules import module [as 別名]
# 或者: from torch.nn.modules.module import Module [as 別名]
def forward(self, input1, input2):
return DepthFlowProjectionLayer.apply(input1, input2,self.requires_grad)
# class FlowFillholeModule(Module):
# def __init__(self,hole_value = -10000.0):
# super(FlowFillholeModule, self).__init__()
# self.f = FlowFillholeLayer()
#
# def forward(self, input1):
# return self.f(input1)
#we actually dont need to write the backward code for a module, since we have