Source File: pytorch_clusters.py From pytorch_active_learning with MIT License 6 votes def cosine_similary(self, item): text = item[1] words = text.split() vector = [0] * len(self.feature_vector) for word in words: if word not in self.feature_idx: self.feature_idx[word] = len...
Currently F.pairwise_distance and F.cosine_similarity accept two sets of vectors of the same size and compute similarity between corresponding vectors. However, it's often useful to compute pairwise similarities or distances between all ...
Source File: ssad.py From Deep-SAD-PyTorch with MIT License 4 votes def test(self, dataset: BaseADDataset, device: str = 'cpu', n_jobs_dataloader: int = 0): """Tests the SSAD model on the test data.""" logger = logging.getLogger() _, test_loader = dataset.loaders(batch_size...
base_y = self.basenet(y) base_z = self.basenet(z)ifself.distance =='cosine': dist_a =.5-.5* F.cosine_similarity(base_x, base_y,1,1e-6).view(-1) dist_b =.5-.5* F.cosine_similarity(base_y, base_z,1,1e-6).view(-1)elifself.distance =='l2': dist_a = F.pairwi...