Python源码示例:torch.nn.modules.module.Module()
示例1
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
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)
示例3
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)
示例4
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)
示例5
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)
示例6
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)
示例7
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)
示例8
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)
示例9
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)
示例10
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
示例11
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