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 |
|---|---|---|---|---|---|---|
ttt_for_deep_learning_cs | ttt_for_deep_learning_cs-master/varnet/functions/data/test_transforms.py | """
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import numpy as np
import pytest
import torch
from common import utils
from common.subsample import RandomMaskFunc
from data import transfor... | 5,497 | 28.244681 | 83 | py |
ttt_for_deep_learning_cs | ttt_for_deep_learning_cs-master/varnet/functions/data/transforms.py | """
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import numpy as np
import torch
def to_tensor(data):
"""
Convert numpy array to PyTorch tensor. For complex arrays, the real and ima... | 11,863 | 32.047354 | 155 | py |
ttt_for_deep_learning_cs | ttt_for_deep_learning_cs-master/varnet/functions/include/mri_helpers.py | import torch
import torch.nn as nn
import torchvision
import sys
import numpy as np
from PIL import Image
import PIL
import numpy as np
from torch.autograd import Variable
import random
import numpy as np
import torch
import matplotlib.pyplot as plt
from PIL import Image
import PIL
from torch.autograd import Vari... | 4,616 | 32.215827 | 106 | py |
ttt_for_deep_learning_cs | ttt_for_deep_learning_cs-master/varnet/functions/include/helpers.py | import torch
import torch.nn as nn
import torchvision
import sys
import numpy as np
from PIL import Image
import PIL
import numpy as np
from torch.autograd import Variable
import random
import numpy as np
import torch
import matplotlib.pyplot as plt
from PIL import Image
import PIL
from torch.autograd import Vari... | 4,860 | 26.308989 | 84 | py |
ttt_for_deep_learning_cs | ttt_for_deep_learning_cs-master/varnet/functions/include/transforms.py | """
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import numpy as np
import torch
def to_tensor(data):
"""
Convert numpy array to PyTorch tensor. For complex arrays, the real and ima... | 11,673 | 31.70028 | 155 | py |
ttt_for_deep_learning_cs | ttt_for_deep_learning_cs-master/varnet/functions/include/pytorch_ssim/__init__.py | import torch
import torch.nn.functional as F
from torch.autograd import Variable
import numpy as np
from math import exp
def gaussian(window_size, sigma):
gauss = torch.Tensor([exp(-(x - window_size//2)**2/float(2*sigma**2)) for x in range(window_size)])
return gauss/gauss.sum()
def create_window(window_size,... | 2,641 | 34.702703 | 104 | py |
ttt_for_deep_learning_cs | ttt_for_deep_learning_cs-master/unet/functions/mri_model.py | """
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
from collections import defaultdict
import numpy as np
import pytorch_lightning as pl
import torch
import torchvision
from torch.utils.data ... | 5,918 | 39.265306 | 124 | py |
ttt_for_deep_learning_cs | ttt_for_deep_learning_cs-master/unet/functions/unet_model.py | """
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import torch
from torch import nn
from torch.nn import functional as F
class ConvBlock(nn.Module):
"""
A Convolutional Block that c... | 8,124 | 36.790698 | 114 | py |
ttt_for_deep_learning_cs | ttt_for_deep_learning_cs-master/unet/functions/train_unet.py | """
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import pathlib
import random
import numpy as np
import torch
from pytorch_lightning import Trainer
from pytorch_lightning.logging import Tes... | 12,100 | 41.609155 | 119 | py |
ttt_for_deep_learning_cs | ttt_for_deep_learning_cs-master/unet/functions/helpers.py | import torch
import numpy as np
from torch.autograd import Variable
dtype = torch.cuda.FloatTensor
class MaskFunc:
"""
ref: https://github.com/facebookresearch/fastMRI/tree/master/fastmri
MaskFunc creates a sub-sampling mask of a given shape.
The mask selects a subset of columns from the input k-space... | 13,056 | 36.412607 | 155 | py |
ttt_for_deep_learning_cs | ttt_for_deep_learning_cs-master/unet/functions/common/utils.py | """
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import json
import h5py
def save_reconstructions(reconstructions, out_dir):
"""
Saves the reconstructions from a model into h5 file... | 1,187 | 28.7 | 91 | py |
ttt_for_deep_learning_cs | ttt_for_deep_learning_cs-master/unet/functions/common/test_subsample.py | """
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import numpy as np
import pytest
import torch
from common.subsample import MaskFunc
@pytest.mark.parametrize("center_fracs, accelerations,... | 1,506 | 30.395833 | 74 | py |
ttt_for_deep_learning_cs | ttt_for_deep_learning_cs-master/unet/functions/common/subsample.py | """
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import numpy as np
import torch
def create_mask_for_mask_type(mask_type_str, center_fractions, accelerations):
if mask_type_str == 'ran... | 7,423 | 42.415205 | 112 | py |
ttt_for_deep_learning_cs | ttt_for_deep_learning_cs-master/unet/functions/data/mri_data.py | """
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import pathlib
import random
import h5py
from torch.utils.data import Dataset
class SliceData(Dataset):
"""
A PyTorch Dataset that... | 2,181 | 35.983051 | 95 | py |
ttt_for_deep_learning_cs | ttt_for_deep_learning_cs-master/unet/functions/data/test_transforms.py | """
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import numpy as np
import pytest
import torch
from common import utils
from common.subsample import RandomMaskFunc
from data import transfor... | 5,497 | 28.244681 | 83 | py |
ttt_for_deep_learning_cs | ttt_for_deep_learning_cs-master/unet/functions/data/transforms.py | """
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import numpy as np
import torch
def to_tensor(data):
"""
Convert numpy array to PyTorch tensor. For complex arrays, the real and ima... | 11,863 | 32.047354 | 155 | py |
ttt_for_deep_learning_cs | ttt_for_deep_learning_cs-master/unet/functions/include/mri_helpers.py | import torch
import torch.nn as nn
import torchvision
import sys
import numpy as np
from PIL import Image
import PIL
import numpy as np
from torch.autograd import Variable
import random
import numpy as np
import torch
import matplotlib.pyplot as plt
from PIL import Image
import PIL
from torch.autograd import Vari... | 4,616 | 32.215827 | 106 | py |
ttt_for_deep_learning_cs | ttt_for_deep_learning_cs-master/unet/functions/include/helpers.py | import torch
import torch.nn as nn
import torchvision
import sys
import numpy as np
from PIL import Image
import PIL
import numpy as np
from torch.autograd import Variable
import random
import numpy as np
import torch
import matplotlib.pyplot as plt
from PIL import Image
import PIL
from torch.autograd import Vari... | 4,860 | 26.308989 | 84 | py |
ttt_for_deep_learning_cs | ttt_for_deep_learning_cs-master/unet/functions/include/transforms.py | """
Copyright (c) Facebook, Inc. and its affiliates.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
"""
import numpy as np
import torch
def to_tensor(data):
"""
Convert numpy array to PyTorch tensor. For complex arrays, the real and ima... | 11,673 | 31.70028 | 155 | py |
ttt_for_deep_learning_cs | ttt_for_deep_learning_cs-master/unet/functions/include/pytorch_ssim/__init__.py | import torch
import torch.nn.functional as F
from torch.autograd import Variable
import numpy as np
from math import exp
def gaussian(window_size, sigma):
gauss = torch.Tensor([exp(-(x - window_size//2)**2/float(2*sigma**2)) for x in range(window_size)])
return gauss/gauss.sum()
def create_window(window_size,... | 2,641 | 34.702703 | 104 | py |
DCEC | DCEC-master/ConvAE.py | from keras.layers import Conv2D, Conv2DTranspose, Dense, Flatten, Reshape
from keras.models import Sequential, Model
from keras.utils.vis_utils import plot_model
import numpy as np
def CAE(input_shape=(28, 28, 1), filters=[32, 64, 128, 10]):
model = Sequential()
if input_shape[0] % 8 == 0:
pad3 = 'sam... | 3,398 | 38.068966 | 121 | py |
DCEC | DCEC-master/datasets.py | import numpy as np
def load_mnist():
# the data, shuffled and split between train and test sets
from keras.datasets import mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x = np.concatenate((x_train, x_test))
y = np.concatenate((y_train, y_test))
x = x.reshape(-1, 28, 28, 1).as... | 1,619 | 33.468085 | 113 | py |
DCEC | DCEC-master/DCEC.py | from time import time
import numpy as np
import keras.backend as K
from keras.engine.topology import Layer, InputSpec
from keras.models import Model
from keras.utils.vis_utils import plot_model
from sklearn.cluster import KMeans
import metrics
from ConvAE import CAE
class ClusteringLayer(Layer):
"""
Clusterin... | 11,131 | 40.849624 | 122 | py |
evaluation-autoguide | evaluation-autoguide-main/utils.py | import os
import numpy, numpyro, pyro
import pathlib
from typing import Any, Dict, IO
from dataclasses import dataclass, field
from pandas import DataFrame, Series
from posteriordb import PosteriorDatabase
from os.path import splitext, basename
from itertools import product
from cmdstanpy import CmdStanModel
from sta... | 2,859 | 27.888889 | 73 | py |
evaluation-autoguide | evaluation-autoguide-main/eval.py | import logging, datetime, os, sys, traceback, re, argparse
import numpyro
import jax
from stannumpyro.dppl import NumPyroModel
from numpyro.infer import Trace_ELBO
from numpyro.optim import Adam
import numpyro.infer.autoguide as autoguide
from utils import (
compile_model,
get_posterior,
summary,
golds,... | 6,107 | 33.314607 | 126 | py |
csshar_tfa | csshar_tfa-main/ssl_training.py | import argparse
from models.dtw import DTWModule
import os
from pytorch_lightning import Trainer, seed_everything
from models.simclr import SimCLR
from models.mlp import LinearClassifier, MLPDropout, ProjectionMLP, MLP
from models.supervised import SupervisedModel
from utils.experiment_utils import generate_experime... | 17,219 | 45.540541 | 218 | py |
csshar_tfa | csshar_tfa-main/callbacks/log_confusion_matrix.py | import pytorch_lightning as pl
import pytorch_lightning.loggers as loggers
import wandb
class LogConfusionMatrix(pl.Callback):
"""
A callback which caches all labels and predictions encountered during a testing epoch,
then logs a confusion matrix to WandB at the end of the test.
"""
def __init__(se... | 1,562 | 34.522727 | 139 | py |
csshar_tfa | csshar_tfa-main/callbacks/log_classifier_metrics.py | import pytorch_lightning as pl
from torch import nn
import torch
import torchmetrics
class LogClassifierMetrics(pl.Callback):
"""
A callback which logs one or more classifier-specific metrics at the end of each
validation and test epoch, to all available loggers.
The available metrics are: accuracy, pr... | 2,465 | 43.035714 | 145 | py |
csshar_tfa | csshar_tfa-main/models/attention_lstm.py | import numpy as np
from torch import nn
import torch
import torch.nn.functional as F
from .mlp import ProjectionMLP_SimCLR, SimSiamMLP
class AttnLSTM(nn.Module):
def __init__(self,
input_dim,
hidden_dim,
output_dim,
n_layers=1,
sensor_attention=False,
temporal_attention=False,
retu... | 3,995 | 29.738462 | 81 | py |
csshar_tfa | csshar_tfa-main/models/simclr.py | import torch
import torch.nn.functional as F
from pytorch_lightning.core.lightning import LightningModule
from torch import nn
from apex.parallel.LARC import LARC
class SimCLR(LightningModule):
def __init__(self,
encoder,
projection,
ssl_batch_size=128,
temperatu... | 5,350 | 37.496403 | 153 | py |
csshar_tfa | csshar_tfa-main/models/supervised.py | from pandas import lreshape
import torch
import torch.nn as nn
from pytorch_lightning.core.lightning import LightningModule
class SupervisedModel(LightningModule):
def __init__(self,
encoder,
classifier,
fine_tuning=False,
optimizer_name='adam',
metric_sc... | 3,129 | 30.938776 | 110 | py |
csshar_tfa | csshar_tfa-main/models/conv_net.py | import torch.nn as nn
class CNN1D(nn.Module):
def __init__(self,
in_channels,
len_seq=30,
out_channels=[32, 64, 128],
fc_size=256,
kernel_size=3,
stride=1,
padding=1,
pool_padding... | 2,442 | 39.716667 | 146 | py |
csshar_tfa | csshar_tfa-main/models/mlp.py | import torch
import torch.nn as nn
class MLP(nn.Module):
def __init__(self, in_size, out_size, hidden=[256, 128], relu_type='leaky'):
super().__init__()
self.name = 'MLP'
if relu_type == 'leaky':
self.relu = nn.LeakyReLU(inplace=True)
else:
self.relu = nn.ReL... | 2,209 | 25.626506 | 80 | py |
csshar_tfa | csshar_tfa-main/models/dtw.py | import torch
import torch.nn.functional as F
from apex.parallel.LARC import LARC
from libraries.pytorch_softdtw_cuda.soft_dtw_cuda import SoftDTW
from pytorch_lightning.core.lightning import LightningModule
from torch import nn
from models.simclr import NTXent
class DTWModule(LightningModule):
"""
Implementa... | 4,302 | 36.417391 | 189 | py |
csshar_tfa | csshar_tfa-main/models/vanilla_lstm.py | from torch import nn
class VanillaLSTM(nn.Module):
def __init__(self, input_dim, hidden_dim, output_dim, n_layers=1, norm_out=False, get_lstm_features=False, initialize_lstm=False):
super(VanillaLSTM, self).__init__()
self.name = 'vanilla_lstm'
self.input_dim = input_dim
self.hidden_dim = hidden_dim
self.n_... | 921 | 30.793103 | 131 | py |
csshar_tfa | csshar_tfa-main/models/cae.py | import torch
import torch.nn as nn
from models.transformer import ConvLayers, PositionalEncoding, TransformerEncoderLayerWeights, TransformerEncoderWeights
class Encoder(nn.Module):
def __init__(self, in_channels, out_channels, kernel_size, stride, padding, pooling_kernel, pooling_padding):
super(Encoder, self).__... | 6,739 | 38.186047 | 187 | py |
csshar_tfa | csshar_tfa-main/models/transformer.py | import math
from typing import Optional
import torch
import torch.nn as nn
from torch import Tensor
from pytorch_lightning.core.lightning import LightningModule
class PositionalEncoding(nn.Module):
"""
Implementation of positional encoding from https://github.com/pytorch/examples/tree/master/word_language_m... | 6,082 | 39.553333 | 176 | py |
csshar_tfa | csshar_tfa-main/datasets/sensor_torch_datamodule.py | from typing import Optional
from pytorch_lightning import LightningDataModule
from torch.utils.data.dataloader import DataLoader
from datasets.sensor_torch_dataset import SensorTorchDataset
class SensorDataModule(LightningDataModule):
def __init__(self,
train_path,
val_path,
... | 3,074 | 31.03125 | 160 | py |
csshar_tfa | csshar_tfa-main/datasets/mobi_act_data.py | import os
import numpy as np
import pandas as pd
from torch.utils.data import Dataset
SCENARIOS_TO_IGNORE = {
'FOL',
'FKL',
'SDL',
'LYI',
'SLH',
'SBW',
'SLW',
'SBE',
'SRH',
'BSC'
}
MOBI_ACT_LABELS_DICT = {
'STD': 0,
'WAL': 1,
'JOG': 2,
'JUM': 3,
'STU': 4,
'STN': 5,
'SCH': 6,
'SIT': 7,
'CHU': 8,
'... | 3,950 | 25.695946 | 151 | py |
csshar_tfa | csshar_tfa-main/datasets/pamap_data.py | import os
import numpy as np
import pandas as pd
from torch.utils.data import Dataset
class PamapDataset():
""" A class for Pamap2 dataset structure inculding paths to each subject and experiment file
Attributes:
-----------
root_dir : str
Path to the root directory of the da... | 4,405 | 40.566038 | 157 | py |
csshar_tfa | csshar_tfa-main/datasets/motion_sense_data.py | import os
import numpy as np
import pandas as pd
from torch.utils.data import Dataset
ACTIVITIES_DICT = {
'dws': 0,
'jog': 1,
'sit': 2,
'std': 3,
'ups': 4,
'wlk': 5
}
MOTION_SENSE_COLUMNS_TO_IGNORE = [
'attitude.roll',
'attitude.pitch',
'attitude.yaw',
'gravity.x',
'gravity.y',
'gravity.z'
]
class... | 3,012 | 26.390909 | 105 | py |
csshar_tfa | csshar_tfa-main/datasets/sensor_torch_dataset.py | import os
import numpy as np
import pandas as pd
import random
from torch.utils.data import Dataset
from tqdm import tqdm
class SensorTorchDataset(Dataset):
def __init__(self, data_path, get_subjects=False, subj_act=False, ignore_subject=None, column_names=None, ssl=False, transforms=None, limited=False, limited... | 7,463 | 41.651429 | 217 | py |
csshar_tfa | csshar_tfa-main/utils/augmentation_utils.py | import numpy as np
import pandas as pd
from torchvision import transforms
class Shift():
def __init__(self, max_shift):
self.max_shift = max_shift
def __call__(self, x):
shift_len = np.random.randint(0, self.max_shift)
x = np.roll(x, shift_len, axis=0)
return x
class Jitteri... | 2,407 | 23.824742 | 88 | py |
csshar_tfa | csshar_tfa-main/utils/training_utils.py | import importlib
import itertools
import os
import shutil
import torch
from models.mlp import ProjectionMLP
from models.simclr import SimCLR
from models.mlp import MLP, MLPDropout
from models.supervised import SupervisedModel
from torchvision import transforms
from pytorch_lightning import loggers
from pytorch_lightni... | 9,115 | 38.124464 | 158 | py |
csshar_tfa | csshar_tfa-main/utils/experiment_utils.py | import datetime
import json
import os
import random
import numpy as np
import torch
import yaml
def generate_experiment_id():
""" A function for generating unique experiment id based on the current time"""
return str(datetime.datetime.now()).replace(' ', '_').replace(':', '_').replace('.', '_')
def generat... | 1,704 | 25.640625 | 93 | py |
deep-image-retrieval | deep-image-retrieval-master/dirtorch/test_dir.py | import sys
import os
import os.path as osp
import pdb
import json
import tqdm
import numpy as np
import torch
import torch.nn.functional as F
from dirtorch.utils.convenient import mkdir
from dirtorch.utils import common
from dirtorch.utils.common import tonumpy, matmul, pool
from dirtorch.utils.pytorch_loader import ... | 9,805 | 36.715385 | 131 | py |
deep-image-retrieval | deep-image-retrieval-master/dirtorch/extract_features.py | import sys
import os
import os.path as osp
import pdb
import json
import tqdm
import numpy as np
import torch
import torch.nn.functional as F
from dirtorch.utils.convenient import mkdir
from dirtorch.utils import common
from dirtorch.utils.common import tonumpy, matmul, pool
from dirtorch.utils.pytorch_loader import ... | 4,874 | 37.385827 | 131 | py |
deep-image-retrieval | deep-image-retrieval-master/dirtorch/loss.py | import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
class APLoss (nn.Module):
""" Differentiable AP loss, through quantization. From the paper:
Learning with Average Precision: Training Image Retrieval with a Listwise Loss
Jerome Revaud, Jon Almazan, Rafael Sampa... | 8,245 | 35.8125 | 120 | py |
deep-image-retrieval | deep-image-retrieval-master/dirtorch/extract_kapture.py | import os
import tqdm
import torch.nn.functional as F
from typing import Optional
os.environ['DB_ROOT'] = ''
from dirtorch.utils import common # noqa: E402
from dirtorch.utils.common import tonumpy, pool # noqa: E402
from dirtorch.datasets.generic import ImageList # noqa: E402
from dirtorch.test_dir import extract... | 7,658 | 49.388158 | 119 | py |
deep-image-retrieval | deep-image-retrieval-master/dirtorch/nets/rmac_resnet_fpn.py | import pdb
from .backbones.resnet import *
from .layers.pooling import GeneralizedMeanPooling, GeneralizedMeanPoolingP
def l2_normalize(x, axis=-1):
x = F.normalize(x, p=2, dim=axis)
return x
class ResNet_RMAC_FPN(ResNet):
""" ResNet for RMAC (without ROI pooling)
"""
def __init__(self, block, l... | 3,816 | 25.692308 | 96 | py |
deep-image-retrieval | deep-image-retrieval-master/dirtorch/nets/rmac_resnext.py | from .backbones.resnext101_features import *
from .layers.pooling import GeneralizedMeanPooling, GeneralizedMeanPoolingP
def l2_normalize(x, axis=-1):
x = F.normalize(x, p=2, dim=axis)
return x
class ResNext_RMAC(nn.Module):
""" ResNet for RMAC (without ROI pooling)
"""
def __init__(self, backbo... | 2,731 | 23.176991 | 112 | py |
deep-image-retrieval | deep-image-retrieval-master/dirtorch/nets/rmac_resnet.py | import pdb
import torch
from .backbones.resnet import *
from .layers.pooling import GeneralizedMeanPooling, GeneralizedMeanPoolingP
def l2_normalize(x, axis=-1):
x = F.normalize(x, p=2, dim=axis)
return x
class ResNet_RMAC(ResNet):
""" ResNet for RMAC (without ROI pooling)
"""
def __init__(self,... | 2,838 | 23.059322 | 112 | py |
deep-image-retrieval | deep-image-retrieval-master/dirtorch/nets/__init__.py | ''' List all architectures at the bottom of this file.
To list all available architectures, use:
python -m nets
'''
import os
import pdb
import torch
from collections import OrderedDict
internal_funcs = set(globals().keys())
from .backbones.resnet import resnet101, resnet50, resnet18, resnet152
from .rmac_resnet... | 3,084 | 23.484127 | 142 | py |
deep-image-retrieval | deep-image-retrieval-master/dirtorch/nets/layers/pooling.py | import pdb
import numpy as np
import torch
from torch.autograd import Variable
import torch.nn as nn
from torch.nn.modules import Module
from torch.nn.parameter import Parameter
import torch.nn.functional as F
import math
class GeneralizedMeanPooling(Module):
r"""Applies a 2D power-average adaptive pooling over a... | 1,815 | 30.859649 | 106 | py |
deep-image-retrieval | deep-image-retrieval-master/dirtorch/nets/backbones/resnet.py | import torch.nn as nn
import torch
import math
import numpy as np
from torch.autograd import Variable
import torch.nn.functional as F
def conv3x3(in_planes, out_planes, stride=1):
"""3x3 convolution with padding"""
return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride,
padd... | 7,827 | 33.333333 | 167 | py |
deep-image-retrieval | deep-image-retrieval-master/dirtorch/nets/backbones/resnext101_features.py | from __future__ import print_function, division, absolute_import
import torch
import torch.nn as nn
from torch.autograd import Variable
from functools import reduce
class LambdaBase(nn.Sequential):
def __init__(self, fn, *args):
super(LambdaBase, self).__init__(*args)
self.lambda_func = fn
def... | 57,499 | 41.942494 | 91 | py |
deep-image-retrieval | deep-image-retrieval-master/dirtorch/utils/pytorch_loader.py | import pdb
from PIL import Image
import numpy as np
import random
import torch
import torch.utils.data as data
def get_loader( dataset, trf_chain, iscuda,
preprocess = {}, # variables for preprocessing (input_size, mean, std, ...)
output = ('img','label'),
batch_size ... | 9,903 | 31.686469 | 119 | py |
deep-image-retrieval | deep-image-retrieval-master/dirtorch/utils/common.py | import os
import sys
import pdb
import shutil
from collections import OrderedDict
import numpy as np
import sklearn.decomposition
import torch
import torch.nn.functional as F
try:
import torch
import torch.nn as nn
except ImportError:
pass
def typename(x):
return type(x).__module__
def tonumpy(x):... | 7,499 | 30.120332 | 104 | py |
deep-image-retrieval | deep-image-retrieval-master/dirtorch/utils/evaluation.py | '''Evaluation metrics
'''
import pdb
import numpy as np
import torch
def accuracy_topk(output, target, topk=(1,)):
"""Computes the precision@k for the specified values of k
output: torch.FloatTensoror np.array(float)
shape = B * L [* H * W]
L: number of possible labels
target: to... | 3,382 | 31.219048 | 124 | py |
deep-image-retrieval | deep-image-retrieval-master/dirtorch/utils/transforms.py | import pdb
import numpy as np
from PIL import Image, ImageOps
import torchvision.transforms as tvf
import random
from math import ceil
from . import transforms_tools as F
def create(cmd_line, to_tensor=False, **vars):
''' Create a sequence of transformations.
cmd_line: (str)
Comma-separated list of ... | 25,933 | 32.945026 | 133 | py |
NeuralSpeech | NeuralSpeech-master/PriorGrad-vocoder/inference.py | # Copyright 2022 (c) Microsoft Corporation. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appl... | 9,379 | 44.533981 | 137 | py |
NeuralSpeech | NeuralSpeech-master/PriorGrad-vocoder/__main__.py | # Copyright 2022 (c) Microsoft Corporation. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appl... | 3,151 | 41.026667 | 107 | py |
NeuralSpeech | NeuralSpeech-master/PriorGrad-vocoder/learner.py | # Copyright 2022 (c) Microsoft Corporation. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appl... | 16,812 | 43.478836 | 146 | py |
NeuralSpeech | NeuralSpeech-master/PriorGrad-vocoder/model.py | # Copyright 2022 (c) Microsoft Corporation. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appl... | 7,288 | 38.4 | 116 | py |
NeuralSpeech | NeuralSpeech-master/PriorGrad-vocoder/dataset.py | # Copyright 2022 (c) Microsoft Corporation. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appl... | 8,838 | 42.328431 | 122 | py |
NeuralSpeech | NeuralSpeech-master/PriorGrad-vocoder/preprocess.py | # Copyright 2022 (c) Microsoft Corporation. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appl... | 6,176 | 41.6 | 138 | py |
NeuralSpeech | NeuralSpeech-master/FastCorrect2/eval_aishell_nbest.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import json
import sys
import torch
import argparse
import re
#from fairseq.models.transformer import TransformerModel
import os
import os.path
import time
import json
import numpy as np
#os.environ["CUDA_VISIBLE_DEVICES"] = '1'
from fairseq impo... | 4,507 | 39.981818 | 248 | py |
NeuralSpeech | NeuralSpeech-master/FastCorrect2/FC_utils/language_pair_dataset.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import logging
import numpy as np
import torch
from fairseq.data im... | 50,130 | 42.974561 | 211 | py |
NeuralSpeech | NeuralSpeech-master/FastCorrect2/FC_utils/hub_utils_fc.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
#!/usr/bin/env python3 -u
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import argparse
import copy
import logging... | 11,447 | 35.810289 | 146 | py |
NeuralSpeech | NeuralSpeech-master/FastCorrect2/FC_utils/binarizer_fc.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import os
from collections import Counter
import torch
from fairseq... | 5,757 | 37.386667 | 178 | py |
NeuralSpeech | NeuralSpeech-master/FastCorrect2/FC_utils/options_fc.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import argparse
from typing import Callable, List, Optional
import ... | 20,160 | 43.802222 | 120 | py |
NeuralSpeech | NeuralSpeech-master/FastCorrect2/FC_utils/fastcorrect_generator.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from collections import namedtuple
import numpy as np
import torch
... | 14,093 | 36.684492 | 198 | py |
NeuralSpeech | NeuralSpeech-master/FastCorrect2/FastCorrect/fastcorrect_task.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import os
import itertools
import logging
logger = logging.getLogge... | 14,497 | 35.427136 | 148 | py |
NeuralSpeech | NeuralSpeech-master/FastCorrect2/FastCorrect/fc_loss.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import math
import torch
import torch.nn.functional as F
from fairs... | 7,908 | 37.207729 | 134 | py |
NeuralSpeech | NeuralSpeech-master/FastCorrect2/FastCorrect/fastcorrect_model.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn.functional as F
from fairseq import uti... | 47,075 | 40.957219 | 265 | py |
NeuralSpeech | NeuralSpeech-master/CMatchASR/distances.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import torch
def CORAL(source, target):
DEVICE = source.device
d = source.size(1)
ns, nt = source.size(0), target.size(0)
# source covariance
tmp_s = torch.ones((1, ns)).to(DEVICE) @ source
cs = (source.t() @ source - (t... | 2,742 | 38.185714 | 113 | py |
NeuralSpeech | NeuralSpeech-master/CMatchASR/utils.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import torch
import logging
from espnet.asr.asr_utils import add_results_to_json
import argparse
import numpy as np
import collections
import json
def str2bool(str):
return True if str.lower() == 'true' else False
def setup_logging(verbose... | 10,200 | 36.503676 | 159 | py |
NeuralSpeech | NeuralSpeech-master/CMatchASR/ctc_aligner.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# Copyright 2019 Kyoto University (Hirofumi Inaguma)
# Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
# https://github.com/hirofumi0810/neural_sp
import torch
import numpy as np
LOG_0 = -1e10
LOG_1 = 0
def np2tensor(array, device=Non... | 11,085 | 39.312727 | 113 | py |
NeuralSpeech | NeuralSpeech-master/CMatchASR/e2e_asr_udatransformer.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import collections
from espnet.nets.pytorch_backend.e2e_asr_transformer import *
from espnet.nets.pytorch_backend.e2e_asr_transformer import E2E as SpeechTransformer
from espnet.nets.pytorch_backend.transformer.encoder import *
from espnet.nets.p... | 31,542 | 43.741844 | 154 | py |
NeuralSpeech | NeuralSpeech-master/CMatchASR/data_load.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from espnet.utils.training.batchfy import make_batchset
from torch.utils.data import DataLoader
from torch.nn.utils.rnn import pad_sequence
import torch
import os
import json
import kaldiio
import random
import logging
import sentencepiece as spm... | 12,738 | 41.042904 | 134 | py |
NeuralSpeech | NeuralSpeech-master/CMatchASR/train.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import logging
import os
import collections
from espnet.bin.asr_train import get_parser
from espnet.utils.dynamic_import import dynamic_import
from espnet.utils.deterministic_utils import set_deterministic_pytorch
from espnet.asr.pytorch_backend.... | 19,142 | 45.919118 | 320 | py |
NeuralSpeech | NeuralSpeech-master/SoftCorrect/eval_detector.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import sys
import torch
import argparse
import re
from fairseq.models.transformer import TransformerModel
import os
import os.path
import time
import json
import numpy as np
from fairseq import utils
utils.import_user_module(argparse.Namespace(... | 4,812 | 36.897638 | 177 | py |
NeuralSpeech | NeuralSpeech-master/SoftCorrect/eval_corrector.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import sys
import argparse
import torch
import re
import os
import os.path
import time
import json
import numpy as np
from fairseq import utils
utils.import_user_module(argparse.Namespace(user_dir='./softcorrect'))
from softcorrect.softcorrect_... | 6,563 | 37.840237 | 194 | py |
NeuralSpeech | NeuralSpeech-master/SoftCorrect/sc_utils/hub_utils_fc.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
#!/usr/bin/env python3 -u
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import argparse
import copy
import logging... | 11,655 | 36.844156 | 201 | py |
NeuralSpeech | NeuralSpeech-master/SoftCorrect/sc_utils/train_sc.py | #!/usr/bin/env python3 -u
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
"""
Train a new model on one or across mult... | 12,121 | 32.766017 | 93 | py |
NeuralSpeech | NeuralSpeech-master/SoftCorrect/sc_utils/softcorrect_corrector_generator.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from collections import namedtuple
import numpy as np
import torch
... | 10,257 | 37.56391 | 134 | py |
NeuralSpeech | NeuralSpeech-master/SoftCorrect/sc_utils/checkpoint_utils_sc.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import collections
import logging
import os
import re
import traceba... | 21,532 | 36.125862 | 114 | py |
NeuralSpeech | NeuralSpeech-master/SoftCorrect/sc_utils/binarizer_fc.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import os
from collections import Counter
import torch
from fairseq... | 4,394 | 33.606299 | 103 | py |
NeuralSpeech | NeuralSpeech-master/SoftCorrect/sc_utils/trainer_sc.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
"""
Train a network across multiple GPUs.
"""
import contextlib
imp... | 47,171 | 38.082022 | 178 | py |
NeuralSpeech | NeuralSpeech-master/SoftCorrect/sc_utils/data_utils_sc.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
try:
from collections.abc import Iterable
except ImportError:
... | 20,635 | 35.140105 | 120 | py |
NeuralSpeech | NeuralSpeech-master/SoftCorrect/sc_utils/dictionary_sc.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import os
from collections import Counter
from multiprocessing impor... | 12,677 | 31.259542 | 87 | py |
NeuralSpeech | NeuralSpeech-master/SoftCorrect/sc_utils/options_fc.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import argparse
from typing import Callable, List, Optional
import ... | 19,822 | 43.346756 | 120 | py |
NeuralSpeech | NeuralSpeech-master/SoftCorrect/sc_utils/corrector_ds.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import logging
import numpy as np
import torch
from fairseq.data im... | 48,975 | 43.082808 | 194 | py |
NeuralSpeech | NeuralSpeech-master/SoftCorrect/softcorrect/softcorrect_task.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import os
import itertools
import logging
logger = logging.getLogge... | 21,359 | 36.408056 | 216 | py |
NeuralSpeech | NeuralSpeech-master/SoftCorrect/softcorrect/softcorrect_model.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn.functional as F
from fairseq import uti... | 70,019 | 41.53949 | 289 | py |
NeuralSpeech | NeuralSpeech-master/SoftCorrect/softcorrect/softcorrect_loss.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import math
import torch
import torch.nn.functional as F
from fairs... | 7,985 | 37.956098 | 184 | py |
NeuralSpeech | NeuralSpeech-master/BinauralGrad/geowarp.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import sys
import librosa
import numpy as np
import scipy.linalg
from scipy.spatial.transform import Rotation as R
import torch as th
import torch.nn as nn
import torch.nn.functional as F
import soundfile
from binauralgrad.warping import Geometr... | 3,528 | 39.563218 | 121 | py |
NeuralSpeech | NeuralSpeech-master/BinauralGrad/metric.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import os
import argparse
import numpy as np
import torch as th
import torchaudio as ta
from src.binauralgrad.losses import L2Loss, AmplitudeLoss, PhaseLoss
import auraloss
import speechmetrics
import sys
result_folder = sys.argv[1]
ref_folder... | 3,130 | 35.835294 | 141 | py |
NeuralSpeech | NeuralSpeech-master/BinauralGrad/src/binauralgrad/inference.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import numpy as np
import os
import torch
import torchaudio
import math
from argparse import ArgumentParser
from binauralgrad.params import AttrDict
import binauralgrad.params as base_params
from binauralgrad.model import BinauralGrad
models = ... | 6,559 | 41.875817 | 198 | py |
NeuralSpeech | NeuralSpeech-master/BinauralGrad/src/binauralgrad/losses.py | """
Copyright (c) Facebook, Inc. and its affiliates.
All rights reserved.
This source code is licensed under the license found in the
LICENSE file in the root directory of this source tree.
"""
# reference: https://github.com/facebookresearch/BinauralSpeechSynthesis/blob/main/src/losses.py
import numpy as np
import t... | 9,657 | 39.751055 | 176 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.