Exemplo n.º 1
0
 def forward(self, x):
     x = x * 0.5
     x.requires_grad_(True)
     h = self.conv(x)
     grad_x = grad(
         h,
         (x,),
         retain_graph=True,
         create_graph=True,
     )
     h = self.linear(grad_x[0])
     return h
Exemplo n.º 2
0
 def forward(self, x):
     x0 = x * 0.5
     x0.requires_grad_(True)
     h = self.conv(x0)
     grad_x0 = grad(
         h,
         (x0,),
         retain_graph=True,
         create_graph=True,
     )
     x1 = x * 0.5
     x1.requires_grad_(True)
     h = self.conv(x1)
     grad_x1 = grad(
         h,
         (x1,),
         retain_graph=True,
         create_graph=True,
     )
     h = self.linear(grad_x0[0] + grad_x1[0])
     return h
Exemplo n.º 3
0
 def forward(self, x):
     x0 = x * 0.5
     x1 = x * 2.0
     x0.requires_grad_(True)
     x1.requires_grad_(True)
     h = self.conv(torch.cat([x0, x1], dim=1))
     grad_x = grad(
         h,
         (x0, x1),
         retain_graph=True,
         create_graph=True,
     )
     h = self.linear(grad_x[0])
     return h