repo
stringlengths
2
99
file
stringlengths
13
225
code
stringlengths
0
18.3M
file_length
int64
0
18.3M
avg_line_length
float64
0
1.36M
max_line_length
int64
0
4.26M
extension_type
stringclasses
1 value
finer
finer-main/models/bilstm.py
import tensorflow as tf import numpy as np from tf2crf import CRF class BiLSTM(tf.keras.Model): def __init__( self, n_classes, n_layers=1, n_units=128, dropout_rate=0.1, crf=False, word2vectors_weights=None, subword_po...
4,319
31
110
py
finer
finer-main/models/transformer.py
import tensorflow as tf import numpy as np from transformers import AutoTokenizer, TFAutoModel from tf2crf import CRF class Transformer(tf.keras.Model): def __init__( self, model_name, n_classes, dropout_rate=0.1, crf=False, tokenizer=None, ...
4,291
29.013986
112
py
finer
finer-main/models/__init__.py
from models.bilstm import BiLSTM from models.transformer import Transformer from models.transformer_bilstm import TransformerBiLSTM
132
32.25
55
py
finer
finer-main/configurations/configuration.py
import json import os import logging from shutil import copy2 from time import strftime, gmtime from configurations import CONFIG_DIR from data import EXPERIMENTS_RUNS_DIR, VECTORS_DIR parameters = {} class ParameterStore(type): def __getitem__(cls, key: str): global parameters return parameter...
5,368
39.368421
116
py
finer
finer-main/configurations/__init__.py
import os CONFIG_DIR = os.path.dirname(os.path.realpath(__file__)) from configurations.configuration import Configuration
122
29.75
56
py
finer
finer-main/data/__init__.py
import os DATA_DIR = os.path.dirname(os.path.realpath(__file__)) EXPERIMENTS_RUNS_DIR = os.path.join(DATA_DIR, 'experiments_runs') VECTORS_DIR = os.path.join(DATA_DIR, 'vectors')
179
35
65
py
TCPD
TCPD-master/build_tcpd.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Collect and verify all time series that are not packaged in the repository. Author: Gertjan van den Burg License: See LICENSE file. Copyright: 2019, The Alan Turing Institute """ import argparse import platform import os DATASET_DIR = "./datasets" TARGETS = [ ...
3,081
25.568966
80
py
TCPD
TCPD-master/examples/python/load_dataset.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Example code for loading a dataset to a TimeSeries object. Note that this code requires Pandas to be available. Author: Gertjan van den Burg Copyright: The Alan Turing Institute, 2019 License: See LICENSE file. """ import json import numpy as np import pandas as pd...
2,654
22.289474
75
py
TCPD
TCPD-master/datasets/scanline_126007/get_scanline_126007.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Collect the scanline_126007 dataset. See the README file for more information. Author: Gertjan van den Burg License: This file is part of TCPD, see the top-level LICENSE file. Copyright: 2019, The Alan Turing Institute """ import argparse import hashlib import os i...
4,045
24.2875
181
py
TCPD
TCPD-master/datasets/shanghai_license/convert.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Dataset conversion script Author: Gertjan van den Burg """ import json import argparse import clevercsv def reformat_time(mmmyy): """ From MMM-YY to %Y-%m """ MONTHS = { "Jan": 1, "Feb": 2, "Mar": 3, "Apr": 4, "May":...
1,956
20.744444
75
py
TCPD
TCPD-master/datasets/bee_waggle_6/get_bee_waggle_6.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Collect the bee_waggle_6 dataset. See the README file for more information. Author: G.J.J. van den Burg License: This file is part of TCPD, see the top-level LICENSE file. Copyright: 2019, The Alan Turing Institute """ import argparse import hashlib import json imp...
5,957
28.205882
114
py
TCPD
TCPD-master/datasets/construction/convert.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Dataset conversion script Author: G.J.J. van den Burg """ import argparse import json import xlrd MONTHS = { "Jan": 1, "Feb": 2, "Mar": 3, "Apr": 4, "May": 5, "Jun": 6, "Jul": 7, "Aug": 8, "Sep": 9, "Oct": 10, "Nov": 11, ...
2,316
19.147826
68
py
TCPD
TCPD-master/datasets/lga_passengers/convert.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Dataset conversion script Author: G.J.J. van den Burg """ import json import argparse import clevercsv def month2index(month): return { "Jan": "01", "Feb": "02", "Mar": "03", "Apr": "04", "May": "05", "Jun": "06"...
1,932
21.476744
78
py
TCPD
TCPD-master/datasets/unemployment_nl/convert.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Author: Gertjan van den Burg """ import argparse import clevercsv import json def parse_args(): parser = argparse.ArgumentParser() parser.add_argument("input_file", help="File to convert") parser.add_argument("output_file", help="File to write to") ...
1,974
23.6875
76
py
TCPD
TCPD-master/datasets/scanline_42049/get_scanline_42049.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Collect the scanline_42049 dataset. See the README file for more information. Author: Gertjan van den Burg License: This file is part of TCPD, see the top-level LICENSE file. Copyright: 2019, The Alan Turing Institute """ import argparse import hashlib import os im...
4,038
24.402516
180
py
TCPD
TCPD-master/datasets/us_population/convert.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Dataset conversion script Author: Gertjan van den Burg """ import json import argparse import clevercsv def parse_args(): parser = argparse.ArgumentParser() parser.add_argument("input_file", help="File to convert") parser.add_argument("output_file", he...
1,428
20.984615
72
py
TCPD
TCPD-master/datasets/usd_isk/convert.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Author: Gertjan van den Burg """ import clevercsv import json import sys def format_month(ymm): year, month = ymm.split("M") return f"{year}-{month}" def main(input_filename, output_filename): with open(input_filename, "r", newline="", encoding="asci...
2,059
22.678161
78
py
TCPD
TCPD-master/datasets/jfk_passengers/convert.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Dataset conversion script Author: G.J.J. van den Burg """ import json import argparse import clevercsv def month2index(month): return { "Jan": "01", "Feb": "02", "Mar": "03", "Apr": "04", "May": "05", "Jun": "06"...
1,927
21.16092
78
py
TCPD
TCPD-master/datasets/centralia/convert.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Dataset conversion script Author: Gertjan van den Burg """ import json import argparse def parse_args(): parser = argparse.ArgumentParser() parser.add_argument( "-s", "--subsample", help="Number of observations to skip during subsam...
1,365
20.015385
68
py
TCPD
TCPD-master/datasets/iceland_tourism/get_iceland_tourism.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Collect the iceland_tourism dataset See the README file for more information. Author: G.J.J. van den Burg License: This file is part of TCPD, see the top-level LICENSE file. Copyright: 2019, The Alan Turing Institute """ import argparse import hashlib import json i...
5,389
24.424528
177
py
TCPD
TCPD-master/datasets/global_co2/get_global_co2.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Collect the global_co2 dataset See the README file for more information. Author: G.J.J. van den Burg License: This file is part of TCPD, see the top-level LICENSE file. Copyright: 2019, The Alan Turing Institute """ import argparse import clevercsv import hashlib ...
4,971
24.761658
239
py
TCPD
TCPD-master/datasets/robocalls/get_robocalls.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Collect the robocalls dataset See the README file for more information. Author: G.J.J. van den Burg License: This file is part of TCPD, see the top-level LICENSE file. Copyright: 2019, The Alan Turing Institute """ import argparse import bs4 import hashlib import ...
5,907
25.375
89
py
TCPD
TCPD-master/datasets/ozone/convert.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Dataset conversion script Author: G.J.J. van den Burg """ import argparse import clevercsv import json def parse_args(): parser = argparse.ArgumentParser() parser.add_argument("input_file", help="File to convert") parser.add_argument("output_file", hel...
1,378
20.546875
73
py
TCPD
TCPD-master/datasets/homeruns/get_homeruns.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Collect the homeruns dataset See the README file for more information. Author: G.J.J. van den Burg License: This file is part of TCPD, see the top-level LICENSE file. Copyright: 2019, The Alan Turing Institute """ import argparse import clevercsv import hashlib imp...
4,748
24.532258
181
py
TCPD
TCPD-master/datasets/run_log/convert.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Dataset conversion script Author: Gertjan van den Burg """ import argparse import clevercsv import json def parse_args(): parser = argparse.ArgumentParser() parser.add_argument("input_file", help="File to convert") parser.add_argument("output_file", he...
1,458
20.776119
72
py
TCPD
TCPD-master/datasets/measles/get_measles.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Collect the measles dataset See the README file for more information. Author: G.J.J. van den Burg License: This file is part of TCPD, see the top-level LICENSE file. Copyright: 2019, The Alan Turing Institute """ import argparse import clevercsv import hashlib impo...
4,225
24.305389
108
py
TCPD
TCPD-master/datasets/gdp_argentina/convert.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Dataset conversion script Author: Gertjan van den Burg """ import json import argparse import clevercsv def parse_args(): parser = argparse.ArgumentParser() parser.add_argument("input_file", help="File to convert") parser.add_argument("output_file", he...
1,824
20.72619
76
py
TCPD
TCPD-master/datasets/brent_spot/convert.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Dataset conversion script Author: G.J.J. van den Burg """ import argparse import clevercsv import json SAMPLE = 10 def date_to_iso(datestr): mm, dd, yyyy = list(map(int, datestr.split("/"))) return f"{yyyy}-{mm:02d}-{dd:02d}" def parse_args(): parser...
1,660
21.445946
76
py
TCPD
TCPD-master/datasets/bitcoin/get_bitcoin.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Retrieve the bitcoin dataset. See the README file for more information. Author: G.J.J. van den Burg License: This file is part of TCPD, see the top-level LICENSE file. Copyright: 2019, The Alan Turing Institute """ import argparse import clevercsv import hashlib im...
4,297
24.431953
129
py
TCPD
TCPD-master/datasets/occupancy/get_occupancy.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Collect the occupancy dataset. See the README file for more information. Author: G.J.J. van den Burg License: This file is part of TCPD, see the top-level LICENSE file. Copyright: 2019, The Alan Turing Institute """ import argparse import clevercsv import hashlib i...
4,628
25.301136
148
py
TCPD
TCPD-master/datasets/ratner_stock/get_ratner_stock.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Collect the ratner_stock dataset. See the README file for more information. Author: G.J.J. van den Burg License: This file is part of TCPD, see the top-level LICENSE file. Copyright: 2019, The Alan Turing Institute """ import argparse import clevercsv import hashli...
5,611
24.981481
88
py
TCPD
TCPD-master/datasets/gdp_croatia/convert.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Dataset conversion script Author: Gertjan van den Burg """ import json import argparse import clevercsv def parse_args(): parser = argparse.ArgumentParser() parser.add_argument("input_file", help="File to convert") parser.add_argument("output_file", he...
1,806
20.511905
76
py
TCPD
TCPD-master/datasets/gdp_iran/convert.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Dataset conversion script Author: Gertjan van den Burg """ import json import argparse import clevercsv def parse_args(): parser = argparse.ArgumentParser() parser.add_argument("input_file", help="File to convert") parser.add_argument("output_file", he...
1,812
20.329412
76
py
TCPD
TCPD-master/datasets/businv/convert.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Dataset conversion script Author: G.J.J. van den Burg """ import argparse import json def parse_args(): parser = argparse.ArgumentParser() parser.add_argument("input_file", help="File to convert") parser.add_argument("output_file", help="File to write ...
1,812
22.545455
76
py
TCPD
TCPD-master/datasets/well_log/convert.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Dataset conversion script Author: G.J.J. van den Burg """ import json import argparse SAMPLE = 6 def parse_args(): parser = argparse.ArgumentParser() parser.add_argument("input_file", help="File to convert") parser.add_argument("output_file", help="Fi...
1,038
18.603774
63
py
TCPD
TCPD-master/datasets/apple/get_apple.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Collect the apple dataset. This script uses the yfinance package to download the data from Yahoo Finance and subsequently reformats it to a JSON file that adheres to our dataset schema. See the README file for more information on the dataset. Author: G.J.J. van den...
13,677
39.111437
88
py
TCPD
TCPD-master/utils/plot_dataset.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Utility script to plot datasets and annotations. Author: G.J.J. van den Burg Copyright (c) 2020 - The Alan Turing Institute License: See the LICENSE file. """ import argparse import datetime import json import matplotlib.pyplot as plt import pandas as pd def parse...
3,606
27.401575
76
py
TCPD
TCPD-master/utils/validate_dataset.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Validate the dataset schema of a given file. Note that this script requires the ``jsonschema`` package. Author: G.J.J. van den Burg License: This file is part of TCPD. See the LICENSE file. Copyright: 2019, The Alan Turing Institute """ import argparse import json ...
4,659
30.486486
83
py
TCPD
TCPD-master/utils/check_checksums.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Validate the datasets by checksum Author: G.J.J. van den Burg License: This file is part of TCPD, see the top-level LICENSE file. Copyright: 2019, The Alan Turing Institute """ import argparse import hashlib import os import json def parse_args(): parser = arg...
2,382
24.902174
78
py
UDAStrongBaseline
UDAStrongBaseline-master/sbs_traindbscan_unc.py
from __future__ import print_function, absolute_import import argparse import os.path as osp import random import numpy as np import sys from sklearn.cluster import DBSCAN # from sklearn.preprocessing import normalize import torch from torch import nn from torch.backends import cudnn from torch.utils.data import Dat...
23,722
40.692443
151
py
UDAStrongBaseline
UDAStrongBaseline-master/sbs_traindbscan.py
from __future__ import print_function, absolute_import import argparse import os.path as osp import random import numpy as np import sys from sklearn.cluster import DBSCAN # from sklearn.preprocessing import normalize import torch from torch import nn from torch.backends import cudnn from torch.utils.data import Dat...
22,980
40.0375
151
py
UDAStrongBaseline
UDAStrongBaseline-master/source_pretrain.py
from __future__ import print_function, absolute_import import argparse import os.path as osp import random import numpy as np import sys import torch from torch import nn from torch.backends import cudnn from torch.utils.data import DataLoader from UDAsbs import datasets from UDAsbs import models from UDAsbs.trainers...
9,253
39.946903
154
py
UDAStrongBaseline
UDAStrongBaseline-master/sbs_trainkmeans.py
from __future__ import print_function, absolute_import import argparse import os import os.path as osp import random import numpy as np import sys from sklearn.cluster import DBSCAN,KMeans # from sklearn.preprocessing import normalize import torch from torch import nn from torch.backends import cudnn from torch.util...
23,432
42.718284
162
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/evaluators.py
from __future__ import print_function, absolute_import import time from collections import OrderedDict import numpy as np import torch from .evaluation_metrics import cmc, mean_ap from .feature_extraction import extract_cnn_feature from .utils.meters import AverageMeter from .utils.rerank import re_ranking def extra...
6,592
37.109827
126
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/trainers.py
from __future__ import print_function, absolute_import import time import torch import torch.nn as nn from torch.nn import functional as F from .evaluation_metrics import accuracy from .loss import SoftTripletLoss_vallia, CrossEntropyLabelSmooth, SoftTripletLoss, SoftEntropy from .memorybank.NCECriterion import Multi...
24,831
41.01692
163
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/__init__.py
from __future__ import absolute_import from . import datasets from . import evaluation_metrics from . import feature_extraction from . import loss from . import metric_learning from . import models from . import utils from . import dist_metric from . import evaluators from . import trainers __version__ = '1.0.0'
316
20.133333
38
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/dist_metric.py
from __future__ import absolute_import import torch from .evaluators import extract_features from .metric_learning import get_metric class DistanceMetric(object): def __init__(self, algorithm='euclidean', *args, **kwargs): super(DistanceMetric, self).__init__() self.algorithm = algorithm ...
926
28.903226
63
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/multigpu.py
import time import torch # from util import MovingAverage def aggreg_multi_gpu(model, dataloader, hc, dim, TYPE=torch.float64, model_gpus=1): """"Accumulate activations and save them on multiple GPUs * this function assumes the model is on the first `model_gpus` GPUs so that it can write the acti...
5,048
40.04878
123
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/sinkhornknopp.py
import torch import torch.nn as nn import time import numpy as np from UDAsbs.multigpu import gpu_mul_Ax, gpu_mul_xA, aggreg_multi_gpu, gpu_mul_AB from scipy.special import logsumexp def py_softmax(x, axis=None): """stable softmax""" return np.exp(x - logsumexp(x, axis=axis, keepdims=True)) def cpu_sk(self)...
8,028
36.872642
117
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/memorybank/alias_multinomial.py
import torch class AliasMethod(object): """ From: https://hips.seas.harvard.edu/blog/2013/03/03/the-alias-method-efficient-sampling-with-many-discrete-outcomes/ """ def __init__(self, probs): if probs.sum() > 1: probs.div_(probs.sum()) K = len(probs) self.prob = to...
1,968
28.833333
120
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/memorybank/NCEAverage.py
import torch from torch import nn from torch.nn import functional as F import math from numpy.testing import assert_almost_equal def normalize(x, axis=-1): """Normalizing to unit length along the specified dimension. Args: x: pytorch Variable Returns: x: pytorch Variable, same shape as input ...
22,548
44.370221
151
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/memorybank/NCECriterion.py
import torch from torch import nn import torch.nn.functional as F eps = 1e-7 class NCECriterion(nn.Module): """ Eq. (12): L_{memorybank} """ def __init__(self, n_data): super(NCECriterion, self).__init__() self.n_data = n_data def forward(self, x): bsz = x.shape[0] ...
3,840
29.975806
108
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/models/resnet_multi.py
from __future__ import absolute_import from torch import nn from torch.nn import functional as F from torch.nn import Parameter from torch.nn import init import torchvision import torch from ..layers import ( IBN, Non_local, get_norm, ) from .gem_pooling import GeneralizedMeanPoolingP __all__ = ['ResNet'...
9,954
36.566038
129
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/models/memory_bank.py
import torch from torch import nn from torch.nn import functional as F import math from numpy.testing import assert_almost_equal def normalize(x, axis=-1): """Normalizing to unit length along the specified dimension. Args: x: pytorch Variable Returns: x: pytorch Variable, same shape as input ...
7,998
38.019512
154
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/models/resnet.py
from __future__ import absolute_import from torch import nn from torch.nn import functional as F from torch.nn import init import torchvision import torch from ..layers import ( IBN, Non_local, get_norm, ) from .gem_pooling import GeneralizedMeanPoolingP __all__ = ['ResNet', 'resnet18', 'resnet34', 'resn...
8,933
34.879518
129
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/models/gem_pooling.py
# encoding: utf-8 """ @author: l1aoxingyu @contact: sherlockliao01@gmail.com """ import torch import torch.nn.functional as F from torch import nn class GeneralizedMeanPooling(nn.Module): r"""Applies a 2D power-average adaptive pooling over an input signal composed of several input planes. The function comp...
1,764
35.020408
106
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/models/dsbn.py
import torch import torch.nn as nn # Domain-specific BatchNorm class DSBN2d(nn.Module): def __init__(self, planes): super(DSBN2d, self).__init__() self.num_features = planes self.BN_S = nn.BatchNorm2d(planes) self.BN_T = nn.BatchNorm2d(planes) def forward(self, x): if ...
2,669
32.797468
68
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/models/__init__.py
from __future__ import absolute_import from .resnet import * # from .resnet_sbs import resnet50_sbs from .resnet_multi import resnet50_multi,resnet50_multi_sbs __factory = { 'resnet18': resnet18, 'resnet34': resnet34, 'resnet50': resnet50, 'resnet101': resnet101, 'resnet152': resnet152, 'resnet...
2,014
34.982143
80
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/datasets/dukemtmc.py
from __future__ import print_function, absolute_import import os.path as osp import glob import re import urllib import zipfile from ..utils.data import BaseImageDataset from ..utils.osutils import mkdir_if_missing from ..utils.serialization import write_json class DukeMTMC(BaseImageDataset): """ DukeMTMC-re...
4,391
38.927273
121
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/datasets/msmt17.py
from __future__ import print_function, absolute_import import os.path as osp import tarfile import glob import re import urllib import zipfile from ..utils.osutils import mkdir_if_missing from ..utils.serialization import write_json style='MSMT17_V1' def _pluck_msmt(list_file, subdir, ncl, pattern=re.compile(r'([-\d...
3,315
32.494949
105
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/datasets/personx.py
from __future__ import print_function, absolute_import import os.path as osp import glob import re import urllib import zipfile from ..utils.data import BaseImageDataset from ..utils.osutils import mkdir_if_missing from ..utils.serialization import write_json class personX(BaseImageDataset): dataset_dir = '.' ...
3,185
37.853659
115
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/datasets/personxval.py
from __future__ import print_function, absolute_import import os.path as osp import glob import re import urllib import zipfile from ..utils.data import BaseImageDataset from ..utils.osutils import mkdir_if_missing from ..utils.serialization import write_json class personXval(BaseImageDataset): dataset_dir = '....
4,015
38.372549
120
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/datasets/market1501.py
from __future__ import print_function, absolute_import import os.path as osp import glob import re import urllib import zipfile from ..utils.data import BaseImageDataset from ..utils.osutils import mkdir_if_missing from ..utils.serialization import write_json class Market1501(BaseImageDataset): """ Market1501...
3,578
37.902174
115
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/datasets/__init__.py
from __future__ import absolute_import import warnings from .dukemtmc import DukeMTMC from .market1501 import Market1501 from .msmt17 import MSMT17 from .personx import personX from .personxval import personXval __factory = { 'market1501': Market1501, 'dukemtmc': DukeMTMC, 'msmt17': MSMT17, 'personx':...
1,372
26.46
79
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/layers/batch_norm.py
# encoding: utf-8 """ @author: liaoxingyu @contact: sherlockliao01@gmail.com """ import logging import torch import torch.nn.functional as F from torch import nn __all__ = [ "BatchNorm", "IBN", "GhostBatchNorm", "FrozenBatchNorm", "SyncBatchNorm", "get_norm", ] class BatchNorm(nn.BatchNorm...
8,165
39.029412
118
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/layers/non_local.py
# encoding: utf-8 import torch from torch import nn from .batch_norm import get_norm class Non_local(nn.Module): def __init__(self, in_channels, bn_norm, num_splits, reduc_ratio=2): super(Non_local, self).__init__() self.in_channels = in_channels self.inter_channels = reduc_ratio // red...
1,901
33.581818
94
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/layers/__init__.py
# encoding: utf-8 """ @author: liaoxingyu @contact: sherlockliao01@gmail.com """ from torch import nn # from .batch_drop import BatchDrop # from .attention import * from .batch_norm import * # from .context_block import ContextBlock from .non_local import Non_local # from .se_layer import SELayer # from .frn import F...
622
23.92
69
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/layers/sync_bn/replicate.py
# -*- coding: utf-8 -*- # File : replicate.py # Author : Jiayuan Mao # Email : maojiayuan@gmail.com # Date : 27/01/2018 # # This file is part of Synchronized-BatchNorm-PyTorch. # https://github.com/vacancy/Synchronized-BatchNorm-PyTorch # Distributed under MIT License. import functools from torch.nn.parallel.da...
3,226
32.968421
115
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/layers/sync_bn/unittest.py
# -*- coding: utf-8 -*- # File : unittest.py # Author : Jiayuan Mao # Email : maojiayuan@gmail.com # Date : 27/01/2018 # # This file is part of Synchronized-BatchNorm-PyTorch. # https://github.com/vacancy/Synchronized-BatchNorm-PyTorch # Distributed under MIT License. import unittest import torch class TorchTes...
746
23.9
59
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/layers/sync_bn/batchnorm.py
# -*- coding: utf-8 -*- # File : batchnorm.py # Author : Jiayuan Mao # Email : maojiayuan@gmail.com # Date : 27/01/2018 # # This file is part of Synchronized-BatchNorm-PyTorch. # https://github.com/vacancy/Synchronized-BatchNorm-PyTorch # Distributed under MIT License. import collections import contextlib import...
15,978
39.35101
116
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/layers/sync_bn/batchnorm_reimpl.py
#! /usr/bin/env python3 # -*- coding: utf-8 -*- # File : batchnorm_reimpl.py # Author : acgtyrant # Date : 11/01/2018 # # This file is part of Synchronized-BatchNorm-PyTorch. # https://github.com/vacancy/Synchronized-BatchNorm-PyTorch # Distributed under MIT License. import torch import torch.nn as nn import torch...
2,385
30.813333
95
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/layers/sync_bn/comm.py
# -*- coding: utf-8 -*- # File : comm.py # Author : Jiayuan Mao # Email : maojiayuan@gmail.com # Date : 27/01/2018 # # This file is part of Synchronized-BatchNorm-PyTorch. # https://github.com/vacancy/Synchronized-BatchNorm-PyTorch # Distributed under MIT License. import queue import collections import threading...
4,449
31.246377
117
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/layers/sync_bn/__init__.py
# -*- coding: utf-8 -*- # File : __init__.py # Author : Jiayuan Mao # Email : maojiayuan@gmail.com # Date : 27/01/2018 # # This file is part of Synchronized-BatchNorm-PyTorch. # https://github.com/vacancy/Synchronized-BatchNorm-PyTorch # Distributed under MIT License. from .batchnorm import SynchronizedBatchNorm1...
507
35.285714
96
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/feature_extraction/cnn.py
from __future__ import absolute_import from collections import OrderedDict from ..utils import to_torch def extract_cnn_feature(model, inputs, modules=None): model.eval() # with torch.no_grad(): inputs = to_torch(inputs).cuda() if modules is None: outputs = model(inputs) outputs = ou...
705
25.148148
56
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/feature_extraction/database.py
from __future__ import absolute_import import h5py import numpy as np from torch.utils.data import Dataset class FeatureDatabase(Dataset): def __init__(self, *args, **kwargs): super(FeatureDatabase, self).__init__() self.fid = h5py.File(*args, **kwargs) def __enter__(self): return se...
1,311
24.230769
59
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/feature_extraction/__init__.py
from __future__ import absolute_import from .cnn import extract_cnn_feature from .database import FeatureDatabase __all__ = [ 'extract_cnn_feature', 'FeatureDatabase', ]
180
17.1
38
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/loss/invariance.py
import torch import torch.nn.functional as F from torch import nn, autograd from torch.autograd import Variable, Function import numpy as np import math import warnings warnings.filterwarnings("ignore") class ExemplarMemory(Function): def __init__(self, em, alpha=0.01): super(ExemplarMemory, self).__init_...
2,793
31.870588
94
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/loss/triplet.py
from __future__ import absolute_import import torch from torch import nn import torch.nn.functional as F def euclidean_dist(x, y): m, n = x.size(0), y.size(0) xx = torch.pow(x, 2).sum(1, keepdim=True).expand(m, n) yy = torch.pow(y, 2).sum(1, keepdim=True).expand(n, m).t() dist = xx + yy dist.addm...
7,326
39.038251
160
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/loss/crossentropy.py
import torch import torch.nn as nn import torch.nn.functional as F class CrossEntropyLabelSmooth(nn.Module): def __init__(self, num_classes, epsilon=0.1, reduce=True): super(CrossEntropyLabelSmooth, self).__init__() self.num_classes = num_classes self.epsilon = epsilon self.logsoftmax = nn.LogSoftmax(dim=1...
1,162
28.075
82
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/loss/multisoftmax.py
import torch from torch import nn import torch.nn.functional as F eps = 1e-7 class NCECriterion(nn.Module): """ Eq. (12): L_{memorybank} """ def __init__(self, n_data): super(NCECriterion, self).__init__() self.n_data = n_data def forward(self, x): bsz = x.shape[0] ...
3,800
29.166667
108
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/loss/__init__.py
from __future__ import absolute_import from .triplet import SoftTripletLoss_vallia, SoftTripletLoss from .crossentropy import CrossEntropyLabelSmooth, SoftEntropy from .multisoftmax import MultiSoftmaxLoss from .invariance import InvNet __all__ = [ 'SoftTripletLoss_vallia', 'CrossEntropyLabelSmooth', 'Soft...
393
25.266667
62
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/metric_learning/kissme.py
from __future__ import absolute_import import numpy as np from metric_learn.base_metric import BaseMetricLearner def validate_cov_matrix(M): M = (M + M.T) * 0.5 k = 0 I = np.eye(M.shape[0]) while True: try: _ = np.linalg.cholesky(M) break except np.linalg.LinAl...
1,654
28.553571
82
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/metric_learning/euclidean.py
from __future__ import absolute_import import numpy as np from metric_learn.base_metric import BaseMetricLearner class Euclidean(BaseMetricLearner): def __init__(self): self.M_ = None def metric(self): return self.M_ def fit(self, X): self.M_ = np.eye(X.shape[1]) self.X_...
425
18.363636
54
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/metric_learning/__init__.py
from __future__ import absolute_import from metric_learn import (ITML_Supervised, LMNN, LSML_Supervised, SDML_Supervised, NCA, LFDA, RCA_Supervised) from .euclidean import Euclidean from .kissme import KISSME __factory = { 'euclidean': Euclidean, 'kissme': KISSME, 'itml': ITML_S...
653
24.153846
69
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/metric_learning/distance.py
from __future__ import absolute_import from __future__ import print_function from __future__ import division import numpy as np import torch from torch.nn import functional as F def compute_distance_matrix(input1, input2, metric='euclidean'): """A wrapper function for computing distance matrix. Args: ...
2,454
31.733333
86
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/utils/lr_scheduler.py
# encoding: utf-8 """ @author: liaoxingyu @contact: sherlockliao01@gmail.com """ from bisect import bisect_right import torch from torch.optim.lr_scheduler import * # separating MultiStepLR with WarmupLR # but the current LRScheduler design doesn't allow it class WarmupMultiStepLR(torch.optim.lr_scheduler._LRSched...
1,807
30.172414
80
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/utils/loss_and_miner_utils.py
import torch import numpy as np import math from . import common_functions as c_f def logsumexp(x, keep_mask=None, add_one=True, dim=1): max_vals, _ = torch.max(x, dim=dim, keepdim=True) inside_exp = x - max_vals exp = torch.exp(inside_exp) if keep_mask is not None: exp = exp*keep_mask ins...
7,816
34.694064
114
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/utils/common_functions.py
import collections import torch from torch.autograd import Variable import numpy as np import os import logging import glob import scipy.stats import re NUMPY_RANDOM = np.random class Identity(torch.nn.Module): def __init__(self): super().__init__() def forward(self, x): return x def try_n...
9,084
28.306452
113
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/utils/logging.py
from __future__ import absolute_import import os import sys from .osutils import mkdir_if_missing class Logger(object): def __init__(self, fpath=None): self.console = sys.stdout self.file = None if fpath is not None: mkdir_if_missing(os.path.dirname(fpath)) self.fi...
876
20.925
52
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/utils/faiss_rerank.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ CVPR2017 paper:Zhong Z, Zheng L, Cao D, et al. Re-ranking Person Re-identification with k-reciprocal Encoding[J]. 2017. url:http://openaccess.thecvf.com/content_cvpr_2017/papers/Zhong_Re-Ranking_Person_Re-Identification_CVPR_2017_paper.pdf Matlab version: https://githu...
4,838
38.663934
126
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/utils/faiss_utils.py
import os import numpy as np import faiss import torch def swig_ptr_from_FloatTensor(x): assert x.is_contiguous() assert x.dtype == torch.float32 return faiss.cast_integer_to_float_ptr( x.storage().data_ptr() + x.storage_offset() * 4) def swig_ptr_from_LongTensor(x): assert x.is_contiguous() ...
3,182
28.201835
92
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/utils/__init__.py
from __future__ import absolute_import import torch def to_numpy(tensor): if torch.is_tensor(tensor): return tensor.cpu().numpy() elif type(tensor).__module__ != 'numpy': raise ValueError("Cannot convert {} to numpy array" .format(type(tensor))) return tensor de...
594
26.045455
60
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/utils/rerank.py
#!/usr/bin/env python2/python3 # -*- coding: utf-8 -*- """ Source: https://github.com/zhunzhong07/person-re-ranking Created on Mon Jun 26 14:46:56 2017 @author: luohao Modified by Yixiao Ge, 2020-3-14. CVPR2017 paper:Zhong Z, Zheng L, Cao D, et al. Re-ranking Person Re-identification with k-reciprocal Encoding[J]. 2017...
8,856
41.37799
119
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/utils/meters.py
from __future__ import absolute_import class AverageMeter(object): """Computes and stores the average and current value""" def __init__(self): self.val = 0 self.avg = 0 self.sum = 0 self.count = 0 def reset(self): self.val = 0 self.avg = 0 self.sum...
496
20.608696
59
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/utils/serialization.py
from __future__ import print_function, absolute_import import json import os.path as osp import shutil import torch from torch.nn import Parameter from .osutils import mkdir_if_missing def read_json(fpath): with open(fpath, 'r') as f: obj = json.load(f) return obj def write_json(obj, fpath): m...
1,758
27.370968
78
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/utils/osutils.py
from __future__ import absolute_import import os import errno def mkdir_if_missing(dir_path): try: os.makedirs(dir_path) except OSError as e: if e.errno != errno.EEXIST: raise
214
16.916667
38
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/utils/data/sampler.py
from __future__ import absolute_import from collections import defaultdict import math import numpy as np import copy import random import torch from torch.utils.data.sampler import ( Sampler, SequentialSampler, RandomSampler, SubsetRandomSampler, WeightedRandomSampler) def No_index(a, b): assert isinsta...
3,547
32.471698
108
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/utils/data/base_dataset.py
# encoding: utf-8 """ @author: sherlock @contact: sherlockliao01@gmail.com """ import numpy as np class BaseDataset(object): """ Base class of reid dataset """ def get_imagedata_info(self, data): pids, cams = [], [] for item in data: pids += [item[1]] cams +=...
2,237
31.911765
112
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/utils/data/transformer.py
from __future__ import absolute_import from torchvision.transforms import * from PIL import Image import random import math import numpy as np class RectScale(object): def __init__(self, height, width, interpolation=Image.BILINEAR): self.height = height self.width = width self.interpolatio...
3,358
33.989583
96
py
UDAStrongBaseline
UDAStrongBaseline-master/UDAsbs/utils/data/__init__.py
from __future__ import absolute_import from .base_dataset import BaseImageDataset from .preprocessor import Preprocessor class IterLoader: def __init__(self, loader, length=None): self.loader = loader self.length = length self.iter = None def __len__(self): if (self.length is ...
619
23.8
44
py