MCPcopy Create free account
hub / github.com/ChenhongyiYang/QueryDet-PyTorch / QueryInfer

Class QueryInfer

models/querydet/qinfer.py:24–167  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22
23
24class QueryInfer(object):
25 def __init__(self, anchor_num, num_classes, score_th=0.12, context=2):
26
27 self.anchor_num = anchor_num
28 self.num_classes = num_classes
29 self.score_th = score_th
30 self.context = context
31
32 self.initialized = False
33 self.cls_spconv = None
34 self.bbox_spconv = None
35 self.qcls_spconv = None
36 self.qcls_conv = None
37 self.n_conv = None
38
39
40 def _make_sparse_tensor(self, query_logits, last_ys, last_xs, anchors, feature_value):
41 if last_ys is None:
42 N, _, qh, qw = query_logits.size()
43 assert N == 1
44 prob = torch.sigmoid_(query_logits).view(-1)
45 pidxs = torch.where(prob > self.score_th)[0]# .float()
46 y = torch.div(pidxs, qw).int()
47 x = torch.remainder(pidxs, qw).int()
48 else:
49 prob = torch.sigmoid_(query_logits).view(-1)
50 pidxs = prob > self.score_th
51 y = last_ys[pidxs]
52 x = last_xs[pidxs]
53
54 if y.size(0) == 0:
55 return None, None, None, None, None, None
56
57 _, fc, fh, fw = feature_value.shape
58
59 ys, xs = [], []
60 for i in range(2):
61 for j in range(2):
62 ys.append(y * 2 + i)
63 xs.append(x * 2 + j)
64
65 ys = torch.cat(ys, dim=0)
66 xs = torch.cat(xs, dim=0)
67 inds = (ys * fw + xs).long()
68
69 sparse_ys = []
70 sparse_xs = []
71
72 for i in range(-1*self.context, self.context+1):
73 for j in range(-1*self.context, self.context+1):
74 sparse_ys.append(ys+i)
75 sparse_xs.append(xs+j)
76
77 sparse_ys = torch.cat(sparse_ys, dim=0)
78 sparse_xs = torch.cat(sparse_xs, dim=0)
79
80
81 good_idx = (sparse_ys >= 0) & (sparse_ys < fh) & (sparse_xs >= 0) & (sparse_xs < fw)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected