INNER CODE UNIT · Python
pbar
patrickjohncyh/fashion-clip · fashion_clip/fashion_clip.py:209
pbar = tqdm(total=len(text) // batch_size, position=0)
with torch.no_grad():
for batch in dataloader:
batch = {k: v.to(self.device) for k, v in batch.items()}
text_embeddings.extend(self.model.get_text_features(**batch).detach().cpu().numpy())
pbar.update(1)
pbar.close()
return np.stack(text_embeddings)
def _cosine_similarity(self, key_vectors: np.ndarray, space_vectors: np.ndarray, normalize=True):
if normalize:
key_vectors = key_vectors / np.linalg.norm(key_vectors, ord=2, axis=-1, keepdims=True)
return np.matmul(key_vectors, space_vectors.T)
def _nearest_neighbours(self, k, key_vectors, space_vectors, normalize=True, debug=False):
if type(key_vectors) == List:
key_vectors = np.array(key_vectors)
if type(space_vectors) == List: