MCPcopy
hub / github.com/mlfoundations/open_clip / _n2p

Function _n2p

src/open_clip/convert.py:21–33  ·  view source on GitHub ↗
(w, t=True, idx=None)

Source from the content-addressed store, hash-verified

19 from timm.layers import resample_patch_embed, resample_abs_pos_embed
20
21 def _n2p(w, t=True, idx=None):
22 if idx is not None:
23 w = w[idx]
24 if w.ndim == 4 and w.shape[0] == w.shape[1] == w.shape[2] == 1:
25 w = w.flatten()
26 if t:
27 if w.ndim == 4:
28 w = w.transpose([3, 2, 0, 1])
29 elif w.ndim == 3:
30 w = w.transpose([2, 0, 1])
31 elif w.ndim == 2:
32 w = w.transpose([1, 0])
33 return torch.from_numpy(w)
34
35 w = np.load(checkpoint_path)
36 interpolation = 'bilinear'

Callers 4

_convert_timm_imgFunction · 0.85
_convert_openclip_txtFunction · 0.85
load_big_vision_weightsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected