MCPcopy Create free account
hub / github.com/DragonisCV/RAM / reshape_features

Method reshape_features

ram/utils/dino_feature_extractor.py:48–76  ·  view source on GitHub ↗
(feat)

Source from the content-addressed store, hash-verified

46 deep_feat2 = hidden_states[39]
47
48 def reshape_features(feat):
49 feat = feat[:, 1:, :]
50 B, N, C = feat.shape
51
52 h = int(math.sqrt(N / aspect_ratio))
53 w = int(N / h)
54
55
56 if(aspect_ratio > 1):
57 if h * w > N:
58 h -= 1
59 w = N // h
60 if h * w < N:
61 h += 1
62 w = N // h
63 else:
64 if h * w > N:
65 w -= 1
66 h = N // w
67 if h * w < N:
68 w += 1
69 h = N // w
70
71
72 assert h * w == N, f"Dimensions mismatch: {h}*{w} != {N}"
73
74
75 feat = feat.reshape(B, h, w, C).permute(0, 3, 1, 2)
76 return feat
77
78
79 shallow_feat1 = reshape_features(shallow_feat1).float()

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected