MCPcopy Create free account
hub / github.com/CHENGY12/PLOT / TextEncoder

Class TextEncoder

plot-adapter/main_imagenet.py:54–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52 self._models[name].load_state_dict(state_dict, strict=False)
53
54class TextEncoder(nn.Module):
55 def __init__(self, clip_model):
56 super().__init__()
57 self.transformer = clip_model.transformer
58 self.positional_embedding = clip_model.positional_embedding
59 self.ln_final = clip_model.ln_final
60 self.text_projection = clip_model.text_projection
61 self.dtype = clip_model.dtype
62
63 def forward(self, prompts, tokenized_prompts):
64
65 x = prompts + self.positional_embedding.type(self.dtype)
66
67 x = x.permute(1, 0, 2) # NLD -> LND
68 x = self.transformer(x)
69 x = x.permute(1, 0, 2) # LND -> NLD
70 x = self.ln_final(x).type(self.dtype)
71
72 x = x[torch.arange(x.shape[0]), tokenized_prompts.argmax(dim=-1)] @ self.text_projection
73
74 return x
75
76
77class PromptLearner(nn.Module):

Callers 1

__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected