def prepare_detection(self, box, poly, ct_hm, cls_id, wh, reg, ct_cls, ct_ind): ct_hm = ct_hm[cls_id] ct_cls.append(cls_id) x_min, y_min, x_max, y_max = box ct = np.array([(x_min + x_max) / 2, (y_min + y_max) / 2], dtype=np.float32) ct_float = ct.copy() ct = np.round(ct).astype(np.int32) h, w = y_max - y_min, x_max - x_min radius = data_utils.gaussian_radius((math.ceil(h), math.ceil(w))) radius = max(0, int(radius)) data_utils.draw_umich_gaussian(ct_hm, ct, radius) wh.append([w, h]) ct_ind.append(ct[1] * ct_hm.shape[1] + ct[0]) reg.append((ct_float - ct).tolist()) x_min, y_min = ct[0] - w / 2, ct[1] - h / 2 x_max, y_max = ct[0] + w / 2, ct[1] + h / 2 decode_box = [x_min, y_min, x_max, y_max] return decode_box
def prepare_detection_(self, box, poly, ct_hm, cls_id, wh, ct_cls, ct_ind): ct_hm = ct_hm[cls_id] ct_cls.append(cls_id) x_min, y_min, x_max, y_max = box box_ct = np.array([(x_min + x_max) / 2, (y_min + y_max) / 2], dtype=np.float32) x_min_int, y_min_int = int(x_min), int(y_min) h_int, w_int = math.ceil(y_max - y_min_int) + 1, math.ceil(x_max - x_min_int) + 1 max_h, max_w = ct_hm.shape[0], ct_hm.shape[1] h_int, w_int = min(y_min_int + h_int, max_h) - y_min_int, min( x_min_int + w_int, max_w) - x_min_int mask_poly = poly - np.array([x_min_int, y_min_int]) mask_ct = box_ct - np.array([x_min_int, y_min_int]) ct, off, xy = snake_voc_utils.prepare_ct_off_mask( mask_poly, mask_ct, h_int, w_int) xy += np.array([x_min_int, y_min_int]) ct += np.array([x_min_int, y_min_int]) h, w = y_max - y_min, x_max - x_min radius = data_utils.gaussian_radius((math.ceil(h), math.ceil(w))) radius = max(0, int(radius)) data_utils.draw_umich_gaussian(ct_hm, ct, radius) wh.append([w, h]) ct_ind.append(ct[1] * ct_hm.shape[1] + ct[0])
def prepare_rcnn(self, abox, instance, cp_hm, cp_wh, cp_ind): if len(abox) == 0: return x_min, y_min, x_max, y_max = abox ct = np.round([(x_min + x_max) / 2, (y_min + y_max) / 2]).astype(np.int32) h, w = y_max - y_min, x_max - x_min abox = np.array( [ct[0] - w / 2, ct[1] - h / 2, ct[0] + w / 2, ct[1] + h / 2]) hm = np.zeros([1, snake_config.cp_h, snake_config.cp_w], dtype=np.float32) abox_w, abox_h = abox[2] - abox[0], abox[3] - abox[1] cp_wh_ = [] cp_ind_ = [] ratio = [snake_config.cp_w, snake_config.cp_h] / np.array( [abox_w, abox_h]) decode_boxes = [] for ex in instance: box = np.concatenate([np.min(ex, axis=0), np.max(ex, axis=0)]) box_w, box_h = box[2] - box[0], box[3] - box[1] cp_wh_.append([box_w, box_h]) center = np.array([(box[0] + box[2]) / 2, (box[1] + box[3]) / 2]) shift = center - abox[:2] ro_center = shift / [abox_w, abox_h ] * [snake_config.cp_w, snake_config.cp_h] ro_center = np.floor(ro_center).astype(np.int32) cp_ind_.append(ro_center[1] * hm.shape[2] + ro_center[0]) ro_box_w, ro_box_h = [box_w, box_h] * ratio radius = data_utils.gaussian_radius( (math.ceil(ro_box_h), math.ceil(ro_box_w))) radius = max(0, int(radius)) data_utils.draw_umich_gaussian(hm[0], ro_center, radius) center = ro_center / [snake_config.cp_w, snake_config.cp_h ] * [abox_w, abox_h] + abox[:2] x_min, y_min = center[0] - box_w / 2, center[1] - box_h / 2 x_max, y_max = center[0] + box_w / 2, center[1] + box_h / 2 x_min, y_min = max(x_min, 0), max(y_min, 0) decode_boxes.append([x_min, y_min, x_max, y_max]) cp_hm.append(hm) cp_wh.append(cp_wh_) cp_ind.append(cp_ind_) return decode_boxes
def prepare_detection(self, box, poly, ct_hm, cls_id, wh, ct_cls, ct_ind, ct_reg_pts=None, centerness=None, rs_hm=None): ct_hm = ct_hm[cls_id] ct_cls.append(cls_id) x_min, y_min, x_max, y_max = box ct = np.array([(x_min + x_max) / 2, (y_min + y_max) / 2], dtype=np.float32) ct_float = ct.copy() ct = np.round(ct).astype(np.int32) if ct_reg_pts is not None: ct_reg_pts.append((ct_float - ct).tolist()) if cfg.dist_4d: xc = np.mean(poly[:, 0]) yc = np.mean(poly[:, 1]) w1 = xc - x_min w2 = x_max - xc h1 = yc - y_min h2 = y_max - yc h = h1 + h2 w = w1 + w2 wh.append([w1, h1, w2, h2]) if cfg.centerness: c = 1.0 centerness.append([c]) else: h, w = y_max - y_min, x_max - x_min wh.append([w, h]) radius = data_utils.gaussian_radius((math.ceil(h), math.ceil(w))) radius = max(0, int(radius)) data_utils.draw_umich_gaussian(ct_hm, ct, radius) ct_ind.append(ct[1] * ct_hm.shape[1] + ct[0]) x_min, y_min = ct[0] - w / 2, ct[1] - h / 2 x_max, y_max = ct[0] + w / 2, ct[1] + h / 2 decode_box = [x_min, y_min, x_max, y_max] return decode_box
def prepare_detection_(self, box, poly, ct_hm, cls_id, wh, ct_cls, ct_ind, ct_reg_pts=None): ct_hm = ct_hm[cls_id] ct_cls.append(cls_id) x_min, y_min, x_max, y_max = box box_ct = np.array([(x_min + x_max) / 2, (y_min + y_max) / 2], dtype=np.float32) x_min_int, y_min_int = int(x_min), int(y_min) h_int, w_int = math.ceil(y_max - y_min_int) + 1, math.ceil(x_max - x_min_int) + 1 max_h, max_w = ct_hm.shape[0], ct_hm.shape[1] h_int, w_int = min(y_min_int + h_int, max_h) - y_min_int, min( x_min_int + w_int, max_w) - x_min_int mask_poly = poly - np.array([x_min_int, y_min_int]) mask_ct = box_ct - np.array([x_min_int, y_min_int]) ct, off, xy = snake_text_utils.prepare_ct_off_mask( mask_poly, mask_ct, h_int, w_int) xy += np.array([x_min_int, y_min_int]) ct += np.array([x_min_int, y_min_int]) if cfg.dist_4d: xc, yc = ct[0], ct[1] w1 = xc - x_min w2 = x_max - xc h1 = yc - y_min h2 = y_max - yc h = h1 + h2 w = w1 + w2 wh.append([w1, h1, w2, h2]) else: h, w = y_max - y_min, x_max - x_min wh.append([w, h]) radius = data_utils.gaussian_radius((math.ceil(h), math.ceil(w))) radius = max(0, int(radius)) data_utils.draw_umich_gaussian(ct_hm, ct, radius) ct_ind.append(ct[1] * ct_hm.shape[1] + ct[0])
def prepare_adet(self, box, ct_hm, cls_id, wh, ct_ind): if len(box) == 0: return ct_hm = ct_hm[cls_id] x_min, y_min, x_max, y_max = box ct = np.round([(x_min + x_max) / 2, (y_min + y_max) / 2]).astype(np.int32) h, w = y_max - y_min, x_max - x_min radius = data_utils.gaussian_radius((math.ceil(h), math.ceil(w))) radius = max(0, int(radius)) data_utils.draw_umich_gaussian(ct_hm, ct, radius) wh.append([w, h]) ct_ind.append(ct[1] * ct_hm.shape[1] + ct[0])