(self, raw_text)
| 109 | return cond |
| 110 | |
| 111 | def encode_text(self, raw_text): |
| 112 | device = next(self.parameters()).device |
| 113 | max_text_len = 20 |
| 114 | if max_text_len is not None: |
| 115 | default_context_length = 77 |
| 116 | context_length = max_text_len + 2 # start_token + 20 + end_token |
| 117 | assert context_length < default_context_length |
| 118 | texts = clip.tokenize(raw_text, |
| 119 | context_length=context_length, |
| 120 | truncate=True).to(device) |
| 121 | zero_pad = torch.zeros( |
| 122 | [texts.shape[0], default_context_length - context_length], |
| 123 | dtype=texts.dtype, |
| 124 | device=texts.device) |
| 125 | texts = torch.cat([texts, zero_pad], dim=1) |
| 126 | return self.clip_model.encode_text(texts).float() |
| 127 | |
| 128 | def get_precompute_condition(self, text, device=None, **kwargs): |
| 129 | if not self.training and device == torch.device('cpu'): |
no outgoing calls
no test coverage detected