MCPcopy
hub / github.com/Hillobar/Rope / compute_conditional

Method compute_conditional

models/clipseg.py:225–243  ·  view source on GitHub ↗
(self, conditional)

Source from the content-addressed store, hash-verified

223 return cond
224
225 def compute_conditional(self, conditional):
226 import clip
227
228 dev = next(self.parameters()).device
229
230 if type(conditional) in {list, tuple}:
231 text_tokens = clip.tokenize(conditional).to(dev)
232 cond = self.clip_model.encode_text(text_tokens)
233 else:
234 if conditional in self.precomputed_prompts:
235 cond = self.precomputed_prompts[conditional].float().to(dev)
236 else:
237 text_tokens = clip.tokenize([conditional]).to(dev)
238 cond = self.clip_model.encode_text(text_tokens)[0]
239
240 if self.shift_vector is not None:
241 return cond + self.shift_vector
242 else:
243 return cond
244
245
246def clip_load_untrained(version):

Callers 1

get_cond_vecMethod · 0.95

Calls 1

encode_textMethod · 0.80

Tested by

no test coverage detected