def __call__(self): changed = np.zeros([self.height, self.width], np.bool) for yx in tqdm.tqdm(self.loader): batch_size = yx.size(0) tensor = torch.zeros(batch_size, 3, self.height, self.width) for i, _yx in enumerate(torch.unbind(yx)): y, x = torch.unbind(_yx) tensor[i, :, y, x] = 1 tensor = utils.ensure_device(tensor) output = self.dnn(torch.autograd.Variable(tensor)) output = output[:, :, self.i, self.j] cmp = output == self.output cmp = torch.prod(cmp, -1).data for _yx, c in zip(torch.unbind(yx), torch.unbind(cmp)): y, x = torch.unbind(_yx) changed[y, x] = c return changed
def __call__(self): changed = np.zeros([self.height, self.width], np.bool) for yx in tqdm.tqdm(self.loader): batch_size = yx.size(0) tensor = torch.zeros(batch_size, 3, self.height, self.width) for i, _yx in enumerate(torch.unbind(yx)): y, x = torch.unbind(_yx) tensor[i, :, y, x] = 1 tensor = utils.ensure_device(tensor) output = self.dnn(torch.autograd.Variable(tensor, volatile=True)) output = output[:, :, self.i, self.j] cmp = output == self.output cmp = torch.prod(cmp, -1).data for _yx, c in zip(torch.unbind(yx), torch.unbind(cmp)): y, x = torch.unbind(_yx) changed[y, x] = c return changed
def filter_valid(yx_min, yx_max, cls, difficult): mask = torch.prod(yx_min < yx_max, -1) & (difficult < 1) _mask = torch.unsqueeze(mask, -1).repeat(1, 2) # PyTorch's bug cls, = (t[mask] for t in (cls, )) yx_min, yx_max = (t[_mask].view(-1, 2) for t in (yx_min, yx_max)) return yx_min, yx_max, cls
def filter_valid(yx_min, yx_max, cls, difficult): mask = torch.prod(yx_min < yx_max, -1) & (difficult < 1) _mask = torch.unsqueeze(mask, -1).repeat(1, 2) # PyTorch's bug cls, = (t[mask] for t in (cls,)) yx_min, yx_max = (t[_mask].view(-1, 2) for t in (yx_min, yx_max)) return yx_min, yx_max, cls