repo stringlengths 1 99 | file stringlengths 13 215 | code stringlengths 12 59.2M | file_length int64 12 59.2M | avg_line_length float64 3.82 1.48M | max_line_length int64 12 2.51M | extension_type stringclasses 1
value |
|---|---|---|---|---|---|---|
pytorch-metric-learning | pytorch-metric-learning-master/src/pytorch_metric_learning/losses/generic_pair_loss.py | import torch
from ..utils import common_functions as c_f
from ..utils import loss_and_miner_utils as lmu
from .base_metric_loss_function import BaseMetricLossFunction
class GenericPairLoss(BaseMetricLossFunction):
def __init__(self, mat_based_loss, **kwargs):
super().__init__(**kwargs)
self.loss_... | 1,492 | 35.414634 | 83 | py |
pytorch-metric-learning | pytorch-metric-learning-master/src/pytorch_metric_learning/losses/pnp_loss.py | import torch
from ..distances import CosineSimilarity
from ..utils import common_functions as c_f
from ..utils import loss_and_miner_utils as lmu
from .base_metric_loss_function import BaseMetricLossFunction
class PNPLoss(BaseMetricLossFunction):
VARIANTS = ["Ds", "Dq", "Iu", "Ib", "O"]
def __init__(self, b... | 3,506 | 35.53125 | 111 | py |
pytorch-metric-learning | pytorch-metric-learning-master/src/pytorch_metric_learning/losses/base_loss_wrapper.py | import torch
class BaseLossWrapper(torch.nn.Module):
def __init__(self, loss, **kwargs):
super().__init__(**kwargs)
loss_name = type(loss).__name__
self.check_loss_support(loss_name)
@staticmethod
def supported_losses():
raise NotImplementedError
@classmethod
def ... | 391 | 22.058824 | 44 | py |
pytorch-metric-learning | pytorch-metric-learning-master/src/pytorch_metric_learning/losses/large_margin_softmax_loss.py | import math
import numpy as np
import scipy.special
import torch
from ..distances import CosineSimilarity
from ..utils import common_functions as c_f
from ..utils import loss_and_miner_utils as lmu
from .base_metric_loss_function import BaseMetricLossFunction
from .mixins import WeightRegularizerMixin
class LargeMa... | 5,674 | 40.727941 | 88 | py |
pytorch-metric-learning | pytorch-metric-learning-master/src/pytorch_metric_learning/losses/ntxent_loss.py | import torch
from ..distances import CosineSimilarity
from ..utils import common_functions as c_f
from .generic_pair_loss import GenericPairLoss
class NTXentLoss(GenericPairLoss):
def __init__(self, temperature=0.07, **kwargs):
super().__init__(mat_based_loss=False, **kwargs)
self.temperature = t... | 1,778 | 36.851064 | 87 | py |
pytorch-metric-learning | pytorch-metric-learning-master/src/pytorch_metric_learning/losses/sphereface_loss.py | import torch
from .large_margin_softmax_loss import LargeMarginSoftmaxLoss
class SphereFaceLoss(LargeMarginSoftmaxLoss):
# implementation of https://arxiv.org/pdf/1704.08063.pdf
def scale_logits(self, logits, embeddings):
embedding_norms = torch.norm(embeddings, p=2, dim=1)
return logits * em... | 360 | 31.818182 | 65 | py |
pytorch-metric-learning | pytorch-metric-learning-master/src/pytorch_metric_learning/losses/normalized_softmax_loss.py | import torch
from ..distances import DotProductSimilarity
from ..utils import common_functions as c_f
from ..utils import loss_and_miner_utils as lmu
from .base_metric_loss_function import BaseMetricLossFunction
from .mixins import WeightRegularizerMixin
class NormalizedSoftmaxLoss(WeightRegularizerMixin, BaseMetric... | 2,173 | 40.018868 | 83 | py |
pytorch-metric-learning | pytorch-metric-learning-master/src/pytorch_metric_learning/losses/fast_ap_loss.py | import torch
from ..distances import LpDistance
from ..utils import common_functions as c_f
from ..utils import loss_and_miner_utils as lmu
from .base_metric_loss_function import BaseMetricLossFunction
class FastAPLoss(BaseMetricLossFunction):
def __init__(self, num_bins=10, **kwargs):
super().__init__(*... | 2,833 | 38.915493 | 84 | py |
pytorch-metric-learning | pytorch-metric-learning-master/src/pytorch_metric_learning/losses/multiple_losses.py | import torch
from ..utils import common_functions as c_f
class MultipleLosses(torch.nn.Module):
def __init__(self, losses, miners=None, weights=None):
super().__init__()
self.is_dict = isinstance(losses, dict)
self.losses = (
torch.nn.ModuleDict(losses) if self.is_dict else to... | 2,351 | 34.104478 | 88 | py |
pytorch-metric-learning | pytorch-metric-learning-master/src/pytorch_metric_learning/losses/circle_loss.py | import torch
from ..distances import CosineSimilarity
from ..reducers import AvgNonZeroReducer
from ..utils import common_functions as c_f
from ..utils import loss_and_miner_utils as lmu
from .generic_pair_loss import GenericPairLoss
class CircleLoss(GenericPairLoss):
"""
Circle loss for pairwise labels only... | 2,832 | 31.193182 | 87 | py |
pytorch-metric-learning | pytorch-metric-learning-master/src/pytorch_metric_learning/losses/subcenter_arcface_loss.py | import math
import numpy as np
import torch
from ..utils import common_functions as c_f
from .arcface_loss import ArcFaceLoss
class SubCenterArcFaceLoss(ArcFaceLoss):
"""
Implementation of https://www.ecva.net/papers/eccv_2020/papers_ECCV/papers/123560715.pdf
"""
def __init__(self, *args, margin=28... | 2,600 | 39.640625 | 92 | py |
pytorch-metric-learning | pytorch-metric-learning-master/src/pytorch_metric_learning/losses/proxy_losses.py | import torch
from ..utils import common_functions as c_f
from .mixins import WeightRegularizerMixin
from .nca_loss import NCALoss
class ProxyNCALoss(WeightRegularizerMixin, NCALoss):
def __init__(self, num_classes, embedding_size, **kwargs):
super().__init__(**kwargs)
self.proxies = torch.nn.Para... | 1,376 | 37.25 | 88 | py |
pytorch-metric-learning | pytorch-metric-learning-master/src/pytorch_metric_learning/losses/n_pairs_loss.py | import torch
from ..distances import DotProductSimilarity
from ..utils import common_functions as c_f
from ..utils import loss_and_miner_utils as lmu
from .base_metric_loss_function import BaseMetricLossFunction
class NPairsLoss(BaseMetricLossFunction):
def __init__(self, **kwargs):
super().__init__(**kw... | 1,463 | 36.538462 | 83 | py |
pytorch-metric-learning | pytorch-metric-learning-master/src/pytorch_metric_learning/losses/tuplet_margin_loss.py | import numpy as np
import torch
from ..distances import CosineSimilarity
from ..utils import common_functions as c_f
from ..utils import loss_and_miner_utils as lmu
from .generic_pair_loss import GenericPairLoss
class TupletMarginLoss(GenericPairLoss):
def __init__(self, margin=5.73, scale=64, **kwargs):
... | 2,049 | 36.962963 | 86 | py |
pytorch-metric-learning | pytorch-metric-learning-master/src/pytorch_metric_learning/losses/soft_triple_loss.py | import math
import torch
import torch.nn.functional as F
from ..distances import CosineSimilarity
from ..utils import common_functions as c_f
from ..utils import loss_and_miner_utils as lmu
from .base_metric_loss_function import BaseMetricLossFunction
from .mixins import WeightRegularizerMixin
###### modified from ... | 3,230 | 34.505495 | 95 | py |
pytorch-metric-learning | pytorch-metric-learning-master/src/pytorch_metric_learning/losses/angular_loss.py | import numpy as np
import torch
from ..distances import LpDistance
from ..utils import common_functions as c_f
from ..utils import loss_and_miner_utils as lmu
from .base_metric_loss_function import BaseMetricLossFunction
class AngularLoss(BaseMetricLossFunction):
"""
Implementation of https://arxiv.org/abs/1... | 3,061 | 40.378378 | 88 | py |
pytorch-metric-learning | pytorch-metric-learning-master/src/pytorch_metric_learning/losses/nca_loss.py | import torch
from ..distances import LpDistance
from ..utils import common_functions as c_f
from ..utils import loss_and_miner_utils as lmu
from .base_metric_loss_function import BaseMetricLossFunction
class NCALoss(BaseMetricLossFunction):
def __init__(self, softmax_scale=1, **kwargs):
super().__init__(... | 1,957 | 34.6 | 86 | py |
pytorch-metric-learning | pytorch-metric-learning-master/src/pytorch_metric_learning/losses/multi_similarity_loss.py | from ..distances import CosineSimilarity
from ..utils import common_functions as c_f
from ..utils import loss_and_miner_utils as lmu
from .generic_pair_loss import GenericPairLoss
class MultiSimilarityLoss(GenericPairLoss):
"""
modified from https://github.com/MalongTech/research-ms-loss/
Args:
al... | 1,558 | 34.431818 | 83 | py |
pytorch-metric-learning | pytorch-metric-learning-master/src/pytorch_metric_learning/losses/intra_pair_variance_loss.py | import torch
from ..distances import CosineSimilarity
from ..losses import GenericPairLoss
from ..utils import loss_and_miner_utils as lmu
class IntraPairVarianceLoss(GenericPairLoss):
def __init__(self, pos_eps=0.01, neg_eps=0.01, **kwargs):
super().__init__(mat_based_loss=False, **kwargs)
self.... | 2,047 | 34.929825 | 84 | py |
pytorch-metric-learning | pytorch-metric-learning-master/src/pytorch_metric_learning/losses/cross_batch_memory.py | import torch
from ..utils import common_functions as c_f
from ..utils import loss_and_miner_utils as lmu
from ..utils.module_with_records import ModuleWithRecords
from .base_loss_wrapper import BaseLossWrapper
class CrossBatchMemory(BaseLossWrapper, ModuleWithRecords):
def __init__(self, loss, embedding_size, me... | 5,333 | 35.285714 | 87 | py |
pytorch-metric-learning | pytorch-metric-learning-master/src/pytorch_metric_learning/losses/cosface_loss.py | import torch
from ..utils import common_functions as c_f
from .large_margin_softmax_loss import LargeMarginSoftmaxLoss
class CosFaceLoss(LargeMarginSoftmaxLoss):
"""
Implementation of https://arxiv.org/pdf/1801.07698.pdf
"""
def __init__(self, *args, margin=0.35, scale=64, **kwargs):
super()... | 939 | 29.322581 | 76 | py |
pytorch-metric-learning | pytorch-metric-learning-master/src/pytorch_metric_learning/losses/p2s_grad_loss.py | import torch
import torch.nn as nn
from torch.nn import Parameter
from ..utils import common_functions as c_f
from . import BaseMetricLossFunction
# Adapted from https://github.com/nii-yamagishilab/project-NN-Pytorch-scripts/blob/master/core_modules/p2sgrad.py
# Original Author: Xin Wang
# Email: wangxin@nii.ac.jp
# ... | 2,635 | 34.146667 | 113 | py |
pytorch-metric-learning | pytorch-metric-learning-master/src/pytorch_metric_learning/losses/vicreg_loss.py | import torch
import torch.nn.functional as F
from ..utils import common_functions as c_f
from .base_metric_loss_function import BaseMetricLossFunction
class VICRegLoss(BaseMetricLossFunction):
def __init__(
self, invariance_lambda=25, variance_mu=25, covariance_v=1, eps=1e-4, **kwargs
):
if "... | 3,368 | 36.853933 | 105 | py |
pytorch-metric-learning | pytorch-metric-learning-master/src/pytorch_metric_learning/losses/arcface_loss.py | import numpy as np
import torch
from ..utils import common_functions as c_f
from .large_margin_softmax_loss import LargeMarginSoftmaxLoss
class ArcFaceLoss(LargeMarginSoftmaxLoss):
"""
Implementation of https://arxiv.org/pdf/1801.07698.pdf
"""
def __init__(self, num_classes, embedding_size, margin=2... | 1,386 | 29.152174 | 85 | py |
pytorch-metric-learning | pytorch-metric-learning-master/src/pytorch_metric_learning/losses/mixins.py | import torch
from ..utils import common_functions as c_f
class WeightMixin:
def __init__(self, weight_init_func=None, **kwargs):
super().__init__(**kwargs)
self.weight_init_func = weight_init_func
if self.weight_init_func is None:
self.weight_init_func = self.get_default_weigh... | 2,863 | 38.232877 | 85 | py |
pytorch-metric-learning | pytorch-metric-learning-master/src/pytorch_metric_learning/losses/self_supervised_loss.py | import torch
from .base_loss_wrapper import BaseLossWrapper
class SelfSupervisedLoss(BaseLossWrapper):
"""
Issue #411:
A common use case is to have embeddings and ref_emb be augmented versions of each other.
For most losses right now you have to create labels to indicate
which embeddings corresp... | 2,269 | 32.382353 | 92 | py |
pytorch-metric-learning | pytorch-metric-learning-master/src/pytorch_metric_learning/losses/lifted_structure_loss.py | import torch
from ..utils import common_functions as c_f
from ..utils import loss_and_miner_utils as lmu
from .generic_pair_loss import GenericPairLoss
class LiftedStructureLoss(GenericPairLoss):
def __init__(self, neg_margin=1, pos_margin=0, **kwargs):
super().__init__(mat_based_loss=False, **kwargs)
... | 3,034 | 36.469136 | 83 | py |
pytorch-metric-learning | pytorch-metric-learning-master/src/pytorch_metric_learning/losses/triplet_margin_loss.py | import torch
from ..reducers import AvgNonZeroReducer
from ..utils import common_functions as c_f
from ..utils import loss_and_miner_utils as lmu
from .base_metric_loss_function import BaseMetricLossFunction
class TripletMarginLoss(BaseMetricLossFunction):
"""
Args:
margin: The desired difference bet... | 2,290 | 33.712121 | 85 | py |
pytorch-metric-learning | pytorch-metric-learning-master/src/pytorch_metric_learning/losses/proxy_anchor_loss.py | import torch
from ..distances import CosineSimilarity
from ..reducers import DivisorReducer
from ..utils import common_functions as c_f
from ..utils import loss_and_miner_utils as lmu
from .base_metric_loss_function import BaseMetricLossFunction
from .mixins import WeightRegularizerMixin
# adapted from
# https://git... | 3,469 | 34.408163 | 93 | py |
pytorch-metric-learning | pytorch-metric-learning-master/src/pytorch_metric_learning/losses/instance_loss.py | import torch
import torch.nn.functional as F
from ..distances import CosineSimilarity
from ..reducers import MeanReducer
from ..utils import common_functions as c_f
from .base_metric_loss_function import BaseMetricLossFunction
class InstanceLoss(BaseMetricLossFunction):
"""
Implementation of Dual-Path Convo... | 1,689 | 33.489796 | 102 | py |
pytorch-metric-learning | pytorch-metric-learning-master/src/pytorch_metric_learning/trainers/base_trainer.py | import torch
import tqdm
from ..utils import common_functions as c_f
from ..utils import loss_tracker as l_t
from ..utils.key_checker import KeyChecker, KeyCheckerDict
class BaseTrainer:
def __init__(
self,
models,
optimizers,
batch_size,
loss_funcs,
dataset,
... | 11,599 | 34.913313 | 102 | py |
pytorch-metric-learning | pytorch-metric-learning-master/src/pytorch_metric_learning/trainers/deep_adversarial_metric_learning.py | import copy
import torch
from ..distances import LpDistance
from ..losses import TripletMarginLoss
from ..miners import EmbeddingsAlreadyPackagedAsTriplets
from ..utils import common_functions as c_f
from ..utils import loss_and_miner_utils as lmu
from .train_with_classifier import TrainWithClassifier
class Negativ... | 6,807 | 36.822222 | 84 | py |
pytorch-metric-learning | pytorch-metric-learning-master/src/pytorch_metric_learning/trainers/twostream_metric_loss.py | import torch
from ..utils import common_functions as c_f
from ..utils import loss_and_miner_utils as lmu
from .base_trainer import BaseTrainer
class TwoStreamMetricLoss(BaseTrainer):
def calculate_loss(self, curr_batch):
(anchors, posnegs), labels = curr_batch
embeddings = (
self.comp... | 2,295 | 38.586207 | 86 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/__init__.py | import os
import sys
import torch
sys.path.insert(0, "src")
import pytorch_metric_learning
from pytorch_metric_learning.utils import common_functions as c_f
dtypes_from_environ = os.environ.get("TEST_DTYPES", "float16,float32,float64").split(
","
)
device_from_environ = os.environ.get("TEST_DEVICE", "cuda")
with... | 886 | 27.612903 | 125 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/distances/test_custom_check_shape.py | import unittest
import torch
from pytorch_metric_learning.distances import BaseDistance, LpDistance
from pytorch_metric_learning.losses import TripletMarginLoss
class CustomDistance(BaseDistance):
def compute_mat(self, query_emb, ref_emb):
return torch.randn(query_emb.shape[0], ref_emb.shape[0])
de... | 805 | 27.785714 | 70 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/distances/test_collected_stats.py | import unittest
import torch
from pytorch_metric_learning.distances import LpDistance
from .. import WITH_COLLECT_STATS
class TestCollectedStats(unittest.TestCase):
@unittest.skipUnless(WITH_COLLECT_STATS, "WITH_COLLECT_STATS is false")
def test_collected_stats(self):
x = torch.randn(32, 128)
... | 574 | 26.380952 | 75 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/distances/test_batched_distance.py | import unittest
import torch
from pytorch_metric_learning.distances import BatchedDistance, CosineSimilarity
def collect_fn(all_mat):
def fn(mat, *_):
all_mat.append(mat)
return fn
class TestBatchedDistance(unittest.TestCase):
def test_batched_distance(self):
torch.manual_seed(1432)
... | 1,901 | 37.816327 | 88 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/samplers/test_m_per_class_sampler.py | import unittest
import torch
from pytorch_metric_learning.samplers import MPerClassSampler
from pytorch_metric_learning.utils import common_functions as c_f
class TestMPerClassSampler(unittest.TestCase):
def test_mperclass_sampler(self):
batch_size = 100
m = 5
length_before_new_iter = 99... | 3,590 | 43.333333 | 86 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/samplers/test_tuples_to_weights_sampler.py | import os
import shutil
import unittest
import torch
from torchvision import datasets, models, transforms
from pytorch_metric_learning.miners import MultiSimilarityMiner
from pytorch_metric_learning.samplers import TuplesToWeightsSampler
from .. import TEST_DEVICE
class TestTuplesToWeightsSampler(unittest.TestCase... | 1,585 | 29.5 | 88 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/samplers/test_fixed_set_of_triplets.py | import unittest
import torch
from pytorch_metric_learning.miners import EmbeddingsAlreadyPackagedAsTriplets
from pytorch_metric_learning.samplers import FixedSetOfTriplets
from pytorch_metric_learning.utils import common_functions as c_f
class TestFixedSetOfTriplet(unittest.TestCase):
def test_fixed_set_of_trip... | 2,295 | 46.833333 | 88 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/samplers/test_hierarchical_sampler.py | import math
import unittest
from collections import Counter
import torch
from pytorch_metric_learning.samplers import HierarchicalSampler
class TestHierarchicalSampler(unittest.TestCase):
def test_hierarchical_sampler(self):
dataset_size = 15023
batches_per_super_tuple = 9
num_superlabel... | 3,078 | 40.608108 | 87 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/miners/test_uniform_histogram_miner.py | import unittest
import torch
from pytorch_metric_learning.distances import LpDistance, SNRDistance
from pytorch_metric_learning.miners import UniformHistogramMiner
from pytorch_metric_learning.utils import loss_and_miner_utils as lmu
from .. import TEST_DEVICE, TEST_DTYPES
class TestUniformHistogramMiner(unittest.... | 2,627 | 34.513514 | 84 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/miners/test_batch_easy_hard_miner_labels.py | import unittest
import torch
from pytorch_metric_learning.distances import (
CosineSimilarity,
DotProductSimilarity,
LpDistance,
SNRDistance,
)
from pytorch_metric_learning.miners import BatchEasyHardMiner
from .. import TEST_DEVICE, TEST_DTYPES
class TestBatchEasyHardMinerLabels(unittest.TestCase)... | 2,056 | 35.087719 | 79 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/miners/test_batch_easy_hard_miner.py | import unittest
import torch
from pytorch_metric_learning.distances import LpDistance
from pytorch_metric_learning.miners import BatchEasyHardMiner
from pytorch_metric_learning.utils import loss_and_miner_utils as lmu
from .. import TEST_DEVICE, TEST_DTYPES, WITH_COLLECT_STATS
class TestBatchEasyHardMiner(unittest... | 14,344 | 40.944444 | 86 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/miners/test_hdc_miner.py | import unittest
import torch
from pytorch_metric_learning.distances import CosineSimilarity, LpDistance
from pytorch_metric_learning.miners import HDCMiner
from .. import TEST_DEVICE, TEST_DTYPES
from ..zzz_testing_utils.testing_utils import angle_to_coord
class TestHDCMiner(unittest.TestCase):
@classmethod
... | 4,460 | 39.926606 | 86 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/miners/test_distance_weighted_miner.py | import unittest
import torch
from pytorch_metric_learning.miners import DistanceWeightedMiner
from pytorch_metric_learning.utils import loss_and_miner_utils as lmu
from .. import TEST_DEVICE, TEST_DTYPES
from ..zzz_testing_utils.testing_utils import angle_to_coord
class TestDistanceWeightedMiner(unittest.TestCase)... | 3,720 | 41.284091 | 87 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/miners/test_batch_hard_miner.py | import unittest
import numpy as np
import torch
from pytorch_metric_learning.distances import CosineSimilarity, LpDistance
from pytorch_metric_learning.miners import BatchHardMiner
from .. import TEST_DEVICE, TEST_DTYPES, WITH_COLLECT_STATS
from ..zzz_testing_utils.testing_utils import angle_to_coord
class TestBat... | 6,004 | 39.033333 | 83 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/miners/test_pair_margin_miner.py | import unittest
import torch
from pytorch_metric_learning.distances import CosineSimilarity, LpDistance
from pytorch_metric_learning.miners import PairMarginMiner
from .. import TEST_DEVICE, TEST_DTYPES, WITH_COLLECT_STATS
from ..zzz_testing_utils import testing_utils
from ..zzz_testing_utils.testing_utils import an... | 4,305 | 42.494949 | 87 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/miners/test_multi_similarity_miner.py | import unittest
import torch
from pytorch_metric_learning.distances import CosineSimilarity, LpDistance
from pytorch_metric_learning.miners import MultiSimilarityMiner
from pytorch_metric_learning.utils import common_functions as c_f
from .. import TEST_DEVICE, TEST_DTYPES
from ..zzz_testing_utils.testing_utils impo... | 4,742 | 41.72973 | 88 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/miners/test_angular_miner.py | import unittest
import numpy as np
import torch
from pytorch_metric_learning.miners import AngularMiner
from .. import TEST_DEVICE, TEST_DTYPES, WITH_COLLECT_STATS
from ..zzz_testing_utils import testing_utils
class TestAngularMiner(unittest.TestCase):
def test_angular_miner(self):
for dtype in TEST_DT... | 3,502 | 40.702381 | 83 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/miners/test_triplet_margin_miner.py | import unittest
import torch
from pytorch_metric_learning.distances import CosineSimilarity, LpDistance
from pytorch_metric_learning.miners import TripletMarginMiner
from .. import TEST_DEVICE, TEST_DTYPES, WITH_COLLECT_STATS
from ..zzz_testing_utils import testing_utils
from ..zzz_testing_utils.testing_utils import... | 5,093 | 43.295652 | 85 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/utils/test_loss_and_miner_utils.py | import unittest
import torch
from pytorch_metric_learning.utils import loss_and_miner_utils as lmu
from .. import TEST_DEVICE, TEST_DTYPES
class TestLossAndMinerUtils(unittest.TestCase):
def test_logsumexp(self):
for dtype in TEST_DTYPES:
rtol = 1e-2 if dtype == torch.float16 else 1e-5
... | 12,747 | 41.922559 | 88 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/utils/test_calculate_accuracies.py | import itertools
import logging
import unittest
import numpy as np
import torch
from pytorch_metric_learning.distances import LpDistance
from pytorch_metric_learning.utils import accuracy_calculator
from pytorch_metric_learning.utils.common_functions import LOGGER
from pytorch_metric_learning.utils.inference import C... | 36,004 | 37.181336 | 88 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/utils/test_inference.py | import os
import unittest
import uuid
import faiss
import torch
import torchvision
from torchvision import datasets, transforms
from pytorch_metric_learning.utils.inference import InferenceModel
from .. import TEST_DEVICE
class TextModel(torch.nn.Module):
def forward(self, list_of_text):
return torch.r... | 3,429 | 31.358491 | 88 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/utils/test_distributed.py | import logging
import os
import unittest
import torch
import torch.distributed as dist
import torch.multiprocessing as mp
import torch.optim as optim
from torch.nn.parallel import DistributedDataParallel as DDP
from pytorch_metric_learning.losses import ContrastiveLoss, CrossBatchMemory
from pytorch_metric_learning.m... | 14,458 | 35.238095 | 88 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/utils/test_common_functions.py | import logging
import unittest
import numpy as np
import torch
from sklearn.preprocessing import StandardScaler
from pytorch_metric_learning.losses import TripletMarginLoss
from pytorch_metric_learning.utils import common_functions as c_f
from .. import WITH_COLLECT_STATS
def process_label_helper(
cls,
dat... | 6,087 | 34.602339 | 89 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/utils/test_module_with_records_and_reducer.py | import unittest
import torch
from pytorch_metric_learning.losses import ContrastiveLoss
from pytorch_metric_learning.reducers import AvgNonZeroReducer
from .. import WITH_COLLECT_STATS
class TestModuleWithRecordsAndReducer(unittest.TestCase):
def test_deepcopy_reducer(self):
loss_fn = ContrastiveLoss(
... | 740 | 31.217391 | 85 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/utils/test_calculate_accuracies_large_k.py | import unittest
import numpy as np
import torch
from pytorch_metric_learning.utils import accuracy_calculator, inference
from .. import TEST_DEVICE
### FROM https://gist.github.com/VChristlein/fd55016f8d1b38e95011a025cbff9ccc
### and https://github.com/KevinMusgrave/pytorch-metric-learning/issues/290
class TestCa... | 5,038 | 38.677165 | 102 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/utils/test_loss_tracker.py | import unittest
from pytorch_metric_learning.utils.loss_tracker import LossTracker
class TestLossTracker(unittest.TestCase):
def test_loss_tracker(self):
LT = LossTracker(["a", "b", "c"])
self.assertTrue(LT.losses == {"a": 0, "b": 0, "c": 0, "total_loss": 0})
losses = LT.losses
l... | 946 | 27.69697 | 82 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/reducers/test_multiple_reducers.py | import unittest
import torch
from pytorch_metric_learning.reducers import (
AvgNonZeroReducer,
DivisorReducer,
MultipleReducers,
)
from .. import TEST_DEVICE, TEST_DTYPES
class TestMultipleReducers(unittest.TestCase):
def test_multiple_reducers(self):
reducer = MultipleReducers(
... | 2,096 | 33.95 | 83 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/reducers/test_threshold_reducer.py | import unittest
import torch
from pytorch_metric_learning.reducers import ThresholdReducer
from .. import TEST_DEVICE, TEST_DTYPES, WITH_COLLECT_STATS
class TestThresholdReducer(unittest.TestCase):
def test_threshold_reducer(self):
for low_threshold, high_threshold in [(0.1, None), (None, 0.2), (0.1, 0... | 2,444 | 41.155172 | 87 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/reducers/test_avg_non_zero_reducer.py | import unittest
import torch
from pytorch_metric_learning.reducers import AvgNonZeroReducer
from .. import TEST_DEVICE, TEST_DTYPES
class TestAvgNonZeroReducer(unittest.TestCase):
def test_avg_non_zero_reducer(self):
reducer = AvgNonZeroReducer()
for dtype in TEST_DTYPES:
batch_size... | 1,909 | 36.45098 | 83 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/reducers/test_class_weighted_reducer.py | import unittest
import torch
from pytorch_metric_learning.reducers import ClassWeightedReducer
from .. import TEST_DEVICE, TEST_DTYPES
class TestClassWeightedReducer(unittest.TestCase):
def test_class_weighted_reducer(self):
torch.manual_seed(99114)
class_weights = torch.tensor([1, 0.9, 1, 0.1,... | 2,307 | 37.466667 | 83 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/reducers/test_divisor_reducer.py | import unittest
import torch
from pytorch_metric_learning.reducers import DivisorReducer
from .. import TEST_DEVICE, TEST_DTYPES
class TestDivisorReducer(unittest.TestCase):
def test_divisor_reducer(self):
reducer = DivisorReducer()
batch_size = 100
embedding_size = 64
for dtype... | 2,509 | 35.911765 | 83 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/reducers/test_mean_reducer.py | import unittest
import torch
from pytorch_metric_learning.reducers import MeanReducer, SumReducer
from .. import TEST_DEVICE, TEST_DTYPES
class TestMeanReducer(unittest.TestCase):
def test_mean_reducer(self):
reducer = MeanReducer()
sum_reducer = SumReducer()
batch_size = 100
em... | 1,760 | 34.22 | 83 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/reducers/test_do_nothing_reducer.py | import unittest
import torch
from pytorch_metric_learning.reducers import DoNothingReducer
from .. import TEST_DEVICE, TEST_DTYPES
class TestDoNothingReducer(unittest.TestCase):
def test_do_nothing_reducer(self):
reducer = DoNothingReducer()
for dtype in TEST_DTYPES:
loss_dict = {
... | 653 | 27.434783 | 75 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/reducers/test_per_anchor_reducer.py | import unittest
import torch
from pytorch_metric_learning.reducers import (
AvgNonZeroReducer,
MeanReducer,
PerAnchorReducer,
)
from pytorch_metric_learning.utils import common_functions as c_f
from pytorch_metric_learning.utils import loss_and_miner_utils as lmu
from .. import TEST_DEVICE, TEST_DTYPES
... | 3,736 | 42.453488 | 88 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/reducers/test_setting_reducers.py | import unittest
from pytorch_metric_learning.losses import ContrastiveLoss, TripletMarginLoss
from pytorch_metric_learning.reducers import (
AvgNonZeroReducer,
MeanReducer,
ThresholdReducer,
)
class TestSettingReducers(unittest.TestCase):
def test_setting_reducers(self):
for loss in [TripletM... | 793 | 30.76 | 77 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/regularizers/test_regular_face_regularizer.py | import unittest
import torch
from pytorch_metric_learning.losses import NormalizedSoftmaxLoss
from pytorch_metric_learning.regularizers import RegularFaceRegularizer
from pytorch_metric_learning.utils import common_functions as c_f
from .. import TEST_DEVICE, TEST_DTYPES
class TestRegularFaceRegularizer(unittest.T... | 1,995 | 36.660377 | 85 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/regularizers/test_center_invariant_regularizer.py | import unittest
import torch
from pytorch_metric_learning.losses import NormalizedSoftmaxLoss
from pytorch_metric_learning.regularizers import CenterInvariantRegularizer
from .. import TEST_DEVICE, TEST_DTYPES
class TestCenterInvariantRegularizer(unittest.TestCase):
def test_center_invariant_regularizer(self):... | 2,189 | 36.758621 | 87 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/testers/test_global_two_stream_embedding_space_tester.py | import unittest
import numpy as np
import torch
from pytorch_metric_learning.testers import GlobalTwoStreamEmbeddingSpaceTester
from pytorch_metric_learning.utils import accuracy_calculator
from ..zzz_testing_utils.testing_utils import angle_to_coord
class FakeDataset(torch.utils.data.Dataset):
def __init__(se... | 1,731 | 30.490909 | 81 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/testers/test_with_same_parent_label_tester.py | import unittest
import numpy as np
import torch
from pytorch_metric_learning.testers import WithSameParentLabelTester
from pytorch_metric_learning.utils import accuracy_calculator
from pytorch_metric_learning.utils import common_functions as c_f
from ..zzz_testing_utils.testing_utils import angle_to_coord
class Te... | 2,672 | 34.171053 | 87 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/testers/test_global_embedding_space_tester.py | import unittest
import torch
from pytorch_metric_learning.testers import GlobalEmbeddingSpaceTester
from pytorch_metric_learning.utils import accuracy_calculator
from pytorch_metric_learning.utils import common_functions as c_f
from ..zzz_testing_utils.testing_utils import angle_to_coord
class TestGlobalEmbeddingS... | 2,953 | 34.590361 | 87 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/losses/test_fastap_loss.py | ######################################
#######ORIGINAL IMPLEMENTATION########
######################################
# FROM https://github.com/kunhe/FastAP-metric-learning/blob/master/pytorch/FastAP_loss.py
# This code is copied directly from the official implementation
# so that we can make sure our implementation ret... | 8,715 | 35.165975 | 89 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/losses/test_ntxent_loss.py | import unittest
import torch
from pytorch_metric_learning.distances import LpDistance
from pytorch_metric_learning.losses import NTXentLoss, SupConLoss
from pytorch_metric_learning.reducers import AvgNonZeroReducer, PerAnchorReducer
from .. import TEST_DEVICE, TEST_DTYPES
from ..zzz_testing_utils.testing_utils impor... | 7,944 | 37.756098 | 88 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/losses/test_soft_triple_loss.py | ######################################
#######ORIGINAL IMPLEMENTATION########
######################################
# FROM https://github.com/idstcv/SoftTriple/blob/master/loss/SoftTriple.py
# This code is copied directly from the official implementation
# so that we can make sure our implementation returns the same r... | 4,724 | 37.414634 | 83 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/losses/test_triplet_margin_loss.py | import unittest
import torch
from pytorch_metric_learning.distances import CosineSimilarity
from pytorch_metric_learning.losses import TripletMarginLoss
from pytorch_metric_learning.reducers import MeanReducer
from .. import TEST_DEVICE, TEST_DTYPES
from ..zzz_testing_utils.testing_utils import angle_to_coord
from .... | 5,718 | 36.379085 | 86 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/losses/test_angular_loss.py | import unittest
import numpy as np
import torch
from pytorch_metric_learning.losses import AngularLoss
from .. import TEST_DEVICE, TEST_DTYPES
from ..zzz_testing_utils.testing_utils import angle_to_coord
from .utils import get_triplet_embeddings_with_ref
class TestAngularLoss(unittest.TestCase):
def test_angul... | 3,111 | 32.826087 | 85 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/losses/test_pnp_loss.py | import unittest
import torch
import torch.nn
import torch.nn.functional
import torch.nn.functional as F
from pytorch_metric_learning.losses import PNPLoss
from .. import TEST_DEVICE, TEST_DTYPES
class OriginalImplementationPNP(torch.nn.Module):
def __init__(self, b, alpha, anneal, variant, bs, classes):
... | 4,877 | 35.676692 | 111 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/losses/test_margin_loss.py | import unittest
import torch
from pytorch_metric_learning.losses import MarginLoss
from .. import TEST_DEVICE, TEST_DTYPES
from ..zzz_testing_utils.testing_utils import angle_to_coord
from .utils import get_triplet_embeddings_with_ref
class TestMarginLoss(unittest.TestCase):
def helper(
self, embedding... | 4,666 | 34.356061 | 88 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/losses/test_tuplet_margin_loss.py | import unittest
import numpy as np
import torch
from pytorch_metric_learning.losses import TupletMarginLoss
from .. import TEST_DEVICE, TEST_DTYPES, WITH_COLLECT_STATS
from ..zzz_testing_utils import testing_utils
class TestTupletMarginLoss(unittest.TestCase):
def test_tuplet_margin_loss(self):
margin,... | 3,160 | 31.927083 | 87 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/losses/test_p2s_grad_loss.py | import unittest
import torch
import torch.nn as nn
from pytorch_metric_learning.losses import P2SGradLoss
from pytorch_metric_learning.utils import common_functions as c_f
from .. import TEST_DEVICE, TEST_DTYPES
######################################
#######TRUSTED IMPLEMENTATION########
##########################... | 8,139 | 34.238095 | 105 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/losses/utils.py | import torch
def get_triplet_embeddings_with_ref(dtype, device):
embeddings = torch.randn(4, 32, requires_grad=True, device=device, dtype=dtype)
embeddings = torch.nn.functional.normalize(embeddings)
labels = torch.LongTensor([0, 0, 1, 1])
ref_emb = torch.randn(3, 32, requires_grad=True, device=devic... | 1,405 | 25.037037 | 83 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/losses/test_cosface_loss.py | import unittest
import torch
import torch.nn.functional as F
from pytorch_metric_learning.losses import CosFaceLoss
from .. import TEST_DEVICE, TEST_DTYPES
from ..zzz_testing_utils.testing_utils import angle_to_coord
class TestCosFaceLoss(unittest.TestCase):
def test_cosface_loss(self):
margin = 0.5
... | 1,636 | 31.098039 | 86 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/losses/test_intra_pair_variance_loss.py | import unittest
import torch
from pytorch_metric_learning.losses import IntraPairVarianceLoss
from .. import TEST_DEVICE, TEST_DTYPES
from ..zzz_testing_utils.testing_utils import angle_to_coord
class TestIntraPairVarianceLoss(unittest.TestCase):
def test_intra_pair_variance_loss(self):
pos_eps, neg_ep... | 3,303 | 31.07767 | 74 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/losses/test_multi_similarity_loss.py | import unittest
import torch
from pytorch_metric_learning.losses import MultiSimilarityLoss
from .. import TEST_DEVICE, TEST_DTYPES
from ..zzz_testing_utils.testing_utils import angle_to_coord
from .utils import get_pair_embeddings_with_ref
class TestMultiSimilarityLoss(unittest.TestCase):
def test_multi_simil... | 4,178 | 33.254098 | 84 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/losses/test_instance_loss.py | import unittest
import numpy as np
import torch
import torch.nn.functional as F
from torch import Tensor, nn
from pytorch_metric_learning.losses import InstanceLoss
from .. import TEST_DEVICE, TEST_DTYPES
# original loss copied from here
# https://github.com/layumi/Person_reID_baseline_pytorch/blob/master/instance... | 2,263 | 33.830769 | 100 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/losses/test_manifold_loss.py | import unittest
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.modules.module import Module
from pytorch_metric_learning.losses import ManifoldLoss
from .. import TEST_DEVICE, TEST_DTYPES
def pairwise_similarity(x, y=None):
# x_norm = (x**2).sum(1).view(-1, ... | 8,264 | 34.320513 | 111 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/losses/test_signal_to_noise_ratio_losses.py | import unittest
import torch
from pytorch_metric_learning.losses import SignalToNoiseRatioContrastiveLoss
from pytorch_metric_learning.regularizers import ZeroMeanRegularizer
from .. import TEST_DEVICE, TEST_DTYPES
from ..zzz_testing_utils.testing_utils import angle_to_coord
class TestSNRContrastiveLoss(unittest.T... | 4,029 | 33.741379 | 85 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/losses/test_large_margin_softmax_loss.py | import math
import unittest
import numpy as np
import scipy
import torch
from pytorch_metric_learning.losses import LargeMarginSoftmaxLoss, SphereFaceLoss
from .. import TEST_DEVICE, TEST_DTYPES
from ..zzz_testing_utils.testing_utils import angle_to_coord
class TestLargeMarginSoftmaxLoss(unittest.TestCase):
de... | 5,920 | 40.405594 | 91 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/losses/test_circle_loss.py | import unittest
import torch
from pytorch_metric_learning.losses import CircleLoss
from .. import TEST_DEVICE, TEST_DTYPES
from ..zzz_testing_utils.testing_utils import angle_to_coord
class TestCircleLoss(unittest.TestCase):
def test_circle_loss(self):
margin, gamma = 0.25, 256
Op, On = 1 + mar... | 4,761 | 34.014706 | 87 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/losses/test_proxy_anchor_loss.py | ######################################
#######ORIGINAL IMPLEMENTATION########
######################################
# FROM https://github.com/tjddus9597/Proxy-Anchor-CVPR2020/blob/master/code/losses.py
# This code is copied directly from the official implementation
# so that we can make sure our implementation returns... | 4,958 | 32.506757 | 88 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/losses/test_multiple_losses.py | import unittest
import torch
from pytorch_metric_learning.losses import (
ContrastiveLoss,
MultipleLosses,
TripletMarginLoss,
)
from pytorch_metric_learning.miners import MultiSimilarityMiner
from .. import TEST_DEVICE, TEST_DTYPES
from ..zzz_testing_utils.testing_utils import angle_to_coord
class Test... | 4,261 | 32.559055 | 88 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/losses/test_contrastive_loss.py | import unittest
import torch
from pytorch_metric_learning.distances import CosineSimilarity, LpDistance
from pytorch_metric_learning.losses import ContrastiveLoss
from pytorch_metric_learning.reducers import MeanReducer
from .. import TEST_DEVICE, TEST_DTYPES, WITH_COLLECT_STATS
from ..zzz_testing_utils import testi... | 6,631 | 37.33526 | 86 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/losses/test_normalized_softmax_loss.py | import unittest
import torch
from pytorch_metric_learning.distances import DotProductSimilarity
from pytorch_metric_learning.losses import NormalizedSoftmaxLoss
from .. import TEST_DEVICE, TEST_DTYPES
from ..zzz_testing_utils.testing_utils import angle_to_coord
class TestNormalizedSoftmaxLoss(unittest.TestCase):
... | 1,822 | 34.057692 | 79 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/losses/test_nca_loss.py | import unittest
import torch
from pytorch_metric_learning.losses import NCALoss
from .. import TEST_DEVICE, TEST_DTYPES
from ..zzz_testing_utils.testing_utils import angle_to_coord
class TestNCALoss(unittest.TestCase):
def test_nca_loss(self):
softmax_scale = 10
loss_func = NCALoss(softmax_scal... | 2,823 | 32.619048 | 76 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/losses/test_cross_batch_memory.py | import unittest
import torch
import pytorch_metric_learning.losses as losses
from pytorch_metric_learning.losses import (
ContrastiveLoss,
CrossBatchMemory,
MultiSimilarityLoss,
NTXentLoss,
)
from pytorch_metric_learning.miners import (
DistanceWeightedMiner,
MultiSimilarityMiner,
PairMarg... | 26,787 | 42.487013 | 118 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/losses/test_npairs_loss.py | import unittest
import torch
from pytorch_metric_learning.losses import NPairsLoss
from pytorch_metric_learning.regularizers import LpRegularizer
from .. import TEST_DEVICE, TEST_DTYPES
from ..zzz_testing_utils.testing_utils import angle_to_coord
class TestNPairsLoss(unittest.TestCase):
def test_npairs_loss(se... | 3,495 | 35.8 | 81 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/losses/test_subcenter_arcface_loss.py | import math
import unittest
import numpy as np
import torch
import torch.nn.functional as F
from pytorch_metric_learning.losses import ArcFaceLoss, SubCenterArcFaceLoss
from .. import TEST_DEVICE, TEST_DTYPES
class TestSubCenterArcFaceLoss(unittest.TestCase):
def test_subcenter_arcface_loss(self):
batc... | 5,757 | 38.710345 | 87 | py |
pytorch-metric-learning | pytorch-metric-learning-master/tests/losses/test_self_supervised_loss.py | import unittest
import torch
import pytorch_metric_learning.losses as losses
from .. import TEST_DEVICE, TEST_DTYPES
class TestSelfSupervisedLoss(unittest.TestCase):
def test_ssl_wrapper_all(self):
for dtype in TEST_DTYPES:
for symmetric in [True, False]:
embeddings = torch.... | 3,457 | 32.901961 | 86 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.