def box(self, original, w, *args, **kargs):
        w = self.w.getVal(c = w, shape = original.shape, **kargs)
        sub = self.sub.getVal(c = 1, shape = original.shape, **kargs)

        assert (0 <= h.dten(w)).all()
        assert (h.dten(sub) <= 1).all()
        assert (0 <= h.dten(sub)).all() 

        if h.dten(w).sum().item() <= 0.0:
            inter = original
        else:
            inter = self.a.box(original, w = w * (1 - sub), *args, **kargs)

        return self.b.box(inter, w = w * sub, *args, **kargs)
    def box(self, original, w, *args, **kargs):
        w = self.w.getVal(c = w, shape = original.shape[:1], **kargs)
        sub = self.sub.getVal(c = 1, shape = original.shape[:1], **kargs)

        assert (0 <= h.dten(w)).all()
        assert (h.dten(sub) <= 1).all()
        assert (0 <= h.dten(sub)).all() 
        if self.normal:
            inter = torch.randn_like(original, device = h.device)
        else:
            inter = (torch.rand_like(original, device = h.device) * 2 - 1) 

        inter = inter * w * (1 - sub)
        
        return self.a.box(original + inter, w = w * sub, *args, **kargs)
Example #3
0
 def printNet(self, f):  # only complete if we've forwardt stride=1
     print("Conv2D", file=f)
     sz = list(self.prev)
     print(
         self.activation +
         ", filters={}, kernel_size={}, input_shape={}, stride={}, padding={}"
         .format(self.out_channels, [self.kernel_size, self.kernel_size],
                 list(reversed(sz)), [self.stride, self.stride],
                 self.padding),
         file=f)
     print(h.printListsNumpy([[list(p) for p in l]
                              for l in self.weight.permute(2, 3, 1, 0).data
                              ]),
           file=f)
     print(h.printNumpy(
         self.bias if self.bias is not None else h.dten(self.out_channels)),
           file=f)
Example #4
0
 def init(self, in_shape, mean, std, **kargs):
     self.mean_v = mean
     self.std_v = std
     self.mean = h.dten(mean)
     self.std = 1 / h.dten(std)
     return in_shape
 def box(self, original, w, *args, **kargs):
     epsilon = self.epsilon.getVal(c = w, shape = original.shape[:1], **kargs)
     assert (0 <= h.dten(epsilon)).all()
     epsilon = torch.randn(original.size()[0:1], device = h.device)[0] * epsilon
     return self.a.box(original, w = epsilon, *args, **kargs)