Example #1
0
def filter_cls_data(yx_min, yx_max, mask):
    if mask.numel() > 0:
        _mask = torch.unsqueeze(mask, -1).repeat(1, 2)  # PyTorch's bug
        yx_min, yx_max = (t[_mask].view(-1, 2) for t in (yx_min, yx_max))
    else:  # all bboxes are difficult
        yx_min = utils.ensure_device(torch.zeros(0, 2))
        yx_max = utils.ensure_device(torch.zeros(0, 2))
    return yx_min, yx_max
Example #2
0
def filter_cls_data(yx_min, yx_max, mask):
    if mask.numel() > 0:
        _mask = torch.unsqueeze(mask, -1).repeat(1, 2)  # PyTorch's bug
        yx_min, yx_max = (t[_mask].view(-1, 2) for t in (yx_min, yx_max))
    else:  # all bboxes are difficult
        yx_min = utils.ensure_device(torch.zeros(0, 2))
        yx_max = utils.ensure_device(torch.zeros(0, 2))
    return yx_min, yx_max
 def __init__(self, args, config):
     self.args = args
     self.config = config
     self.model_dir = utils.get_model_dir(config)
     self.category = utils.get_category(config)
     self.anchors = torch.from_numpy(utils.get_anchors(config)).contiguous()
     self.dnn = utils.parse_attr(config.get('model',
                                            'dnn'))(config, self.anchors,
                                                    len(self.category))
     self.dnn.eval()
     logging.info(
         humanize.naturalsize(
             sum(var.cpu().numpy().nbytes
                 for var in self.dnn.state_dict().values())))
     if torch.cuda.is_available():
         self.dnn.cuda()
     self.height, self.width = tuple(
         map(int,
             config.get('image', 'size').split()))
     output = self.dnn(
         torch.autograd.Variable(
             utils.ensure_device(torch.zeros(1, 3, self.height,
                                             self.width))))
     _, _, self.rows, self.cols = output.size()
     self.i, self.j = self.rows // 2, self.cols // 2
     self.output = output[:, :, self.i, self.j]
     dataset = Dataset(self.height, self.width)
     try:
         workers = self.config.getint('data', 'workers')
     except configparser.NoOptionError:
         workers = multiprocessing.cpu_count()
     self.loader = torch.utils.data.DataLoader(
         dataset, batch_size=self.args.batch_size, num_workers=workers)
Example #4
0
def conv_logits(pred):
    if 'logits' in pred:
        logits = pred['logits'].contiguous()
        prob, cls = torch.max(F.softmax(logits, -1), -1)
    else:
        size = pred['iou'].size()
        prob = torch.autograd.Variable(utils.ensure_device(torch.ones(*size)))
        cls = torch.autograd.Variable(
            utils.ensure_device(torch.zeros(*size).int()))
    return prob, cls
 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 __init__(self, args, config):
     self.args = args
     self.config = config
     self.model_dir = utils.get_model_dir(config)
     self.category = utils.get_category(config)
     self.anchors = torch.from_numpy(utils.get_anchors(config)).contiguous()
     self.dnn = utils.parse_attr(config.get('model', 'dnn'))(model.ConfigChannels(config), self.anchors, len(self.category))
     self.dnn.eval()
     logging.info(humanize.naturalsize(sum(var.cpu().numpy().nbytes for var in self.dnn.state_dict().values())))
     if torch.cuda.is_available():
         self.dnn.cuda()
     self.height, self.width = tuple(map(int, config.get('image', 'size').split()))
     output = self.dnn(torch.autograd.Variable(utils.ensure_device(torch.zeros(1, 3, self.height, self.width)), volatile=True))
     _, _, self.rows, self.cols = output.size()
     self.i, self.j = self.rows // 2, self.cols // 2
     self.output = output[:, :, self.i, self.j]
     dataset = Dataset(self.height, self.width)
     try:
         workers = self.config.getint('data', 'workers')
     except configparser.NoOptionError:
         workers = multiprocessing.cpu_count()
     self.loader = torch.utils.data.DataLoader(dataset, batch_size=self.args.batch_size, num_workers=workers)