Пример #1
0
 def debug_data(self, data):
     for i, t in enumerate(torch.unbind(data['image'])):
         a = t.cpu().numpy()
         logging.info('image%d: %f %s' % (i, utils.abs_mean(a), hashlib.md5(a.tostring()).hexdigest()))
     for i, t in enumerate(torch.unbind(data['tensor'])):
         a = t.cpu().numpy()
         logging.info('tensor%d: %f %s' % (i, utils.abs_mean(a), hashlib.md5(a.tostring()).hexdigest()))
Пример #2
0
 def stat_ap(self):
     cls_num = [0 for _ in self.category]
     cls_score = [np.array([], dtype=np.float32) for _ in self.category]
     cls_tp = [np.array([], dtype=np.bool) for _ in self.category]
     for data in tqdm.tqdm(self.loader):
         for key in data:
             t = data[key]
             if torch.is_tensor(t):
                 data[key] = utils.ensure_device(t)
         tensor = torch.autograd.Variable(data['tensor'], volatile=True)
         batch_size = tensor.size(0)
         pred = pybenchmark.profile('inference')(model._inference)(
             self.inference, tensor)
         _prob, pred['cls'] = conv_logits(pred)
         pred['iou'] = pred['iou'].contiguous()
         pred['prob'] = pred['iou'] * _prob
         for key in pred:
             pred[key] = pred[key].data
         if self.config.getboolean('eval', 'debug'):
             self.debug_data(data)
             self.debug_pred(pred)
         norm_bbox(data, pred)
         for path, size, difficult, image, data_yx_min, data_yx_max, data_cls, yx_min, yx_max, iou, prob, cls in zip(
                 *(data[key]
                   for key in 'path, size, difficult'.split(', ')),
                 *(torch.unbind(data[key])
                   for key in 'image, yx_min, yx_max, cls'.split(', ')),
                 *(torch.unbind(pred[key].view(batch_size, -1, 2))
                   for key in 'yx_min, yx_max'.split(', ')),
                 *(torch.unbind(pred[key].view(batch_size, -1))
                   for key in 'iou, prob, cls'.split(', '))):
             data_yx_min, data_yx_max, data_cls = filter_valid(
                 data_yx_min, data_yx_max, data_cls, difficult)
             for c in data_cls.cpu().numpy():
                 cls_num[c] += 1
             yx_min, yx_max, cls, score = self.filter_visible(
                 yx_min, yx_max, iou, prob, cls)
             keep = pybenchmark.profile('nms')(utils.postprocess.nms)(
                 yx_min, yx_max, score,
                 self.config.getfloat('detect', 'overlap'))
             if keep:
                 keep = utils.ensure_device(torch.LongTensor(keep))
                 yx_min, yx_max, cls, score = (t[keep]
                                               for t in (yx_min, yx_max,
                                                         cls, score))
                 for c in set(cls.cpu().numpy()):
                     c = int(c)  # PyTorch's bug
                     _score, tp = self.filter_cls(c, path, data_yx_min,
                                                  data_yx_max, data_cls,
                                                  yx_min, yx_max, cls,
                                                  score)
                     cls_score[c] = np.append(cls_score[c],
                                              _score.cpu().numpy())
                     cls_tp[c] = np.append(cls_tp[c], tp)
     return cls_num, cls_score, cls_tp
Пример #3
0
 def debug_data(self, data):
     for i, t in enumerate(torch.unbind(data['image'])):
         a = t.cpu().numpy()
         logging.info(
             'image%d: %f %s' %
             (i, utils.abs_mean(a), hashlib.md5(a.tostring()).hexdigest()))
     for i, t in enumerate(torch.unbind(data['tensor'])):
         a = t.cpu().numpy()
         logging.info(
             'tensor%d: %f %s' %
             (i, utils.abs_mean(a), hashlib.md5(a.tostring()).hexdigest()))
Пример #4
0
 def debug_pred(self, pred):
     for i, t in enumerate(torch.unbind(pred['iou'])):
         a = t.cpu().numpy()
         logging.info('iou%d: %f %s' % (i, utils.abs_mean(a), hashlib.md5(a.tostring()).hexdigest()))
     for i, t in enumerate(torch.unbind(pred['center_offset'])):
         a = t.cpu().numpy()
         logging.info('center_offset%d: %f %s' % (i, utils.abs_mean(a), hashlib.md5(a.tostring()).hexdigest()))
     for i, t in enumerate(torch.unbind(pred['size_norm'])):
         a = t.cpu().numpy()
         logging.info('size_norm%d: %f %s' % (i, utils.abs_mean(a), hashlib.md5(a.tostring()).hexdigest()))
     for i, t in enumerate(torch.unbind(pred['logits'])):
         a = t.cpu().numpy()
         logging.info('logits%d: %f %s' % (i, utils.abs_mean(a), hashlib.md5(a.tostring()).hexdigest()))
Пример #5
0
 def stat_ap(self):
     cls_num = [0 for _ in self.category]
     cls_score = [np.array([], dtype=np.float32) for _ in self.category]
     cls_tp = [np.array([], dtype=np.bool) for _ in self.category]
     for data in tqdm.tqdm(self.loader):
         for key in data:
             t = data[key]
             if torch.is_tensor(t):
                 data[key] = utils.ensure_device(t)
         tensor = torch.autograd.Variable(data['tensor'], volatile=True)
         pred = pybenchmark.profile('inference')(model._inference)(
             self.inference, tensor)
         pred['iou'] = pred['iou'].contiguous()
         logits = get_logits(pred)
         pred['prob'] = F.softmax(logits, -1)
         for key in pred:
             pred[key] = pred[key].data
         if self.config.getboolean('eval', 'debug'):
             self.debug_data(data)
             self.debug_pred(pred)
         norm_bbox_data(data)
         norm_bbox_pred(pred)
         for path, difficult, image, data_yx_min, data_yx_max, data_cls, iou, yx_min, yx_max, prob in zip(
                 *(data[key] for key in 'path, difficult'.split(', ')),
                 *(torch.unbind(data[key])
                   for key in 'image, yx_min, yx_max, cls'.split(', ')),
                 *(torch.unbind(pred[key])
                   for key in 'iou, yx_min, yx_max, prob'.split(', '))):
             data_yx_min, data_yx_max, data_cls = filter_valid(
                 data_yx_min, data_yx_max, data_cls, difficult)
             for c in data_cls.cpu().numpy():
                 cls_num[c] += 1
             iou = iou.view(-1)
             yx_min, yx_max, prob = (t.view(-1, t.size(-1))
                                     for t in (yx_min, yx_max, prob))
             ret = postprocess(self.config, iou, yx_min, yx_max, prob)
             if ret is not None:
                 iou, yx_min, yx_max, cls, score = ret
                 for c in set(cls.cpu().numpy()):
                     c = int(c)  # PyTorch's bug
                     _score, tp = self.filter_cls(c, path, data_yx_min,
                                                  data_yx_max, data_cls,
                                                  yx_min, yx_max, cls,
                                                  score)
                     cls_score[c] = np.append(cls_score[c],
                                              _score.cpu().numpy())
                     cls_tp[c] = np.append(cls_tp[c], tp)
     return cls_num, cls_score, cls_tp
Пример #6
0
 def debug_pred(self, pred):
     for i, t in enumerate(torch.unbind(pred['iou'])):
         a = t.cpu().numpy()
         logging.info(
             'iou%d: %f %s' %
             (i, utils.abs_mean(a), hashlib.md5(a.tostring()).hexdigest()))
     for i, t in enumerate(torch.unbind(pred['center_offset'])):
         a = t.cpu().numpy()
         logging.info(
             'center_offset%d: %f %s' %
             (i, utils.abs_mean(a), hashlib.md5(a.tostring()).hexdigest()))
     for i, t in enumerate(torch.unbind(pred['size_norm'])):
         a = t.cpu().numpy()
         logging.info(
             'size_norm%d: %f %s' %
             (i, utils.abs_mean(a), hashlib.md5(a.tostring()).hexdigest()))
 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
Пример #9
0
 def stat_ap(self):
     cls_num = [0 for _ in self.category]
     cls_score = [np.array([], dtype=np.float32) for _ in self.category]
     cls_tp = [np.array([], dtype=np.bool) for _ in self.category]
     for data in tqdm.tqdm(self.loader):
         for key in data:
             t = data[key]
             if torch.is_tensor(t):
                 data[key] = utils.ensure_device(t)
         tensor = torch.autograd.Variable(data['tensor'], volatile=True)
         pred = pybenchmark.profile('inference')(model._inference)(self.inference, tensor)
         pred['iou'] = pred['iou'].contiguous()
         logits = get_logits(pred)
         pred['prob'] = F.softmax(logits, -1)
         for key in pred:
             pred[key] = pred[key].data
         if self.config.getboolean('eval', 'debug'):
             self.debug_data(data)
             self.debug_pred(pred)
         norm_bbox_data(data)
         norm_bbox_pred(pred)
         for path, difficult, image, data_yx_min, data_yx_max, data_cls, iou, yx_min, yx_max, prob in zip(*(data[key] for key in 'path, difficult'.split(', ')), *(torch.unbind(data[key]) for key in 'image, yx_min, yx_max, cls'.split(', ')), *(torch.unbind(pred[key]) for key in 'iou, yx_min, yx_max, prob'.split(', '))):
             data_yx_min, data_yx_max, data_cls = filter_valid(data_yx_min, data_yx_max, data_cls, difficult)
             for c in data_cls.cpu().numpy():
                 cls_num[c] += 1
             iou = iou.view(-1)
             yx_min, yx_max, prob = (t.view(-1, t.size(-1)) for t in (yx_min, yx_max, prob))
             ret = postprocess(self.config, iou, yx_min, yx_max, prob)
             if ret is not None:
                 iou, yx_min, yx_max, cls, score = ret
                 for c in set(cls.cpu().numpy()):
                     c = int(c)  # PyTorch's bug
                     _score, tp = self.filter_cls(c, path, data_yx_min, data_yx_max, data_cls, yx_min, yx_max, cls, score)
                     cls_score[c] = np.append(cls_score[c], _score.cpu().numpy())
                     cls_tp[c] = np.append(cls_tp[c], tp)
     return cls_num, cls_score, cls_tp