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 |
|---|---|---|---|---|---|---|
speechbrain | speechbrain-main/tests/unittests/test_checkpoints.py | import pytest
def test_checkpointer(tmpdir, device):
from speechbrain.utils.checkpoints import Checkpointer
import torch
class Recoverable(torch.nn.Module):
def __init__(self, param):
super().__init__()
self.param = torch.nn.Parameter(torch.tensor([param]))
def fo... | 14,332 | 35.940722 | 93 | py |
speechbrain | speechbrain-main/tests/unittests/test_embedding.py | import torch
def test_embedding(device):
from speechbrain.nnet.embedding import Embedding
# create one hot vector and consider blank as zero vector
embedding_dim = 39
blank_id = 39
size_dict = 40
emb = Embedding(
num_embeddings=size_dict, consider_as_one_hot=True, blank_id=blank_id
... | 783 | 26.034483 | 78 | py |
speechbrain | speechbrain-main/tests/unittests/test_activations.py | import torch
import torch.nn
def test_softmax(device):
from speechbrain.nnet.activations import Softmax
inputs = torch.tensor([1, 2, 3], device=device).float()
act = Softmax(apply_log=False)
outputs = act(inputs)
assert torch.argmax(outputs) == 2
assert torch.jit.trace(act, inputs)
| 312 | 19.866667 | 59 | py |
speechbrain | speechbrain-main/tests/unittests/test_batching.py | import pytest
import torch
import numpy as np
def test_batch_pad_right_to(device):
from speechbrain.utils.data_utils import batch_pad_right
import random
n_channels = 40
batch_lens = [1, 5]
for b in batch_lens:
rand_lens = [random.randint(10, 53) for x in range(b)]
tensors = [
... | 2,404 | 28.329268 | 77 | py |
speechbrain | speechbrain-main/tests/unittests/test_linear.py | import torch
import torch.nn
def test_linear(device):
from speechbrain.nnet.linear import Linear
inputs = torch.rand(1, 2, 4, device=device)
lin_t = Linear(n_neurons=4, input_size=inputs.shape[-1], bias=False)
lin_t.w.weight = torch.nn.Parameter(
torch.eye(inputs.shape[-1], device=device)
... | 443 | 23.666667 | 72 | py |
speechbrain | speechbrain-main/tests/unittests/test_losses.py | import torch
import pytest
def test_nll(device):
from speechbrain.nnet.losses import nll_loss
predictions = torch.zeros(4, 10, 8, device=device)
targets = torch.zeros(4, 10, device=device)
lengths = torch.ones(4, device=device)
out_cost = nll_loss(predictions, targets, lengths)
assert torch.a... | 8,520 | 34.210744 | 80 | py |
speechbrain | speechbrain-main/tests/unittests/test_metrics.py | import torch
import torch.nn
import math
def test_metric_stats(device):
from speechbrain.utils.metric_stats import MetricStats
from speechbrain.nnet.losses import l1_loss
l1_stats = MetricStats(metric=l1_loss)
l1_stats.append(
ids=["utterance1", "utterance2"],
predictions=torch.tensor... | 6,686 | 32.268657 | 79 | py |
speechbrain | speechbrain-main/tests/unittests/test_CNN.py | import torch
import torch.nn
def test_SincConv(device):
from speechbrain.nnet.CNN import SincConv
input = torch.rand([4, 16000], device=device)
convolve = SincConv(
input_shape=input.shape, out_channels=8, kernel_size=65, padding="same"
).to(device)
output = convolve(input)
assert out... | 2,850 | 26.413462 | 80 | py |
speechbrain | speechbrain-main/tests/unittests/test_pooling.py | import torch
import torch.nn
def test_pooling1d(device):
from speechbrain.nnet.pooling import Pooling1d
input = (
torch.tensor([1, 3, 2], device=device)
.unsqueeze(0)
.unsqueeze(-1)
.float()
)
pool = Pooling1d("max", 3).to(device)
output = pool(input)
assert o... | 1,446 | 22.721311 | 80 | py |
speechbrain | speechbrain-main/tests/unittests/test_tokenizer.py | import os
import torch
def test_tokenizer():
from speechbrain.tokenizers.SentencePiece import SentencePiece
gt = [
["HELLO", "MORNING", "MORNING", "HELLO"],
["HELLO", "MORNING", "HELLO"],
]
# Word-level input test
dict_int2lab = {1: "HELLO", 2: "MORNING"}
spm = SentencePiece... | 3,846 | 25.531034 | 72 | py |
speechbrain | speechbrain-main/tests/unittests/test_dataloader.py | import torch
import pytest
def test_saveable_dataloader(tmpdir, device):
from speechbrain.dataio.dataloader import SaveableDataLoader
save_file = tmpdir + "/dataloader.ckpt"
dataset = torch.randn(10, 1, device=device)
dataloader = SaveableDataLoader(dataset, collate_fn=None)
data_iterator = iter(... | 3,274 | 36.215909 | 80 | py |
speechbrain | speechbrain-main/tests/unittests/test_attention.py | import torch
def test_rel_pos_MHA(device):
from speechbrain.nnet.attention import RelPosMHAXL
bsz = 2
emb_dim = 4
k_len = [12, 10]
q_len = [10, 12]
bias = [True, False]
head_dim = [4, None]
for kl in k_len:
for ql in q_len:
for b in bias:
for h in... | 792 | 27.321429 | 69 | py |
speechbrain | speechbrain-main/tests/unittests/test_data_io.py | import torch
import os
def test_read_audio(tmpdir, device):
from speechbrain.dataio.dataio import read_audio, write_audio
test_waveform = torch.rand(16000, device=device)
wavfile = os.path.join(tmpdir, "wave.wav")
write_audio(wavfile, test_waveform.cpu(), 16000)
# dummy annotation
for i in r... | 3,324 | 37.218391 | 85 | py |
speechbrain | speechbrain-main/tests/unittests/test_g2p.py | import torch
from torch.nn import functional as F
def _fake_probs(idx, count):
result = torch.zeros(count)
result[idx] = 2.0
return F.softmax(result, dim=-1)
def _batch_fake_probs(indexes, count):
p_seq = torch.zeros(indexes.shape + (count,))
for batch_idx in range(len(indexes)):
for it... | 2,629 | 29.229885 | 76 | py |
speechbrain | speechbrain-main/tests/integration/ASR_alignment_viterbi/example_asr_alignment_viterbi_experiment.py | #!/usr/bin/env/python3
"""This minimal example trains an HMM-based aligner with the Viterbi algorithm.
The encoder is based on a combination of convolutional, recurrent, and
feed-forward networks (CRDNN) that predict phoneme states.
Given the tiny dataset, the expected behavior is to overfit the training data
(with a v... | 5,017 | 32.677852 | 79 | py |
speechbrain | speechbrain-main/tests/integration/separation/example_conv_tasnet.py | #!/usr/bin/env/python3
"""This minimal example trains a speech separation system with on a tiny dataset.
The architecture is based on ConvTasnet and expects in input mixtures of two
speakers.
"""
import torch
import pathlib
import speechbrain as sb
import torch.nn.functional as F
from hyperpyyaml import load_hyperpyya... | 5,334 | 30.755952 | 81 | py |
speechbrain | speechbrain-main/tests/integration/G2P/example_g2p.py | #!/usr/bin/env/python3
"""This minimal example trains a grapheme-to-phoneme (G2P) converter
that turns a sequence of characters into a sequence of phonemes. The system uses
a standard attention-based encoder-decoder pipeline. The encoder is based on an
LSTM, while the decoder is based on a GRU. Greedy search applied o... | 6,166 | 34.854651 | 80 | py |
speechbrain | speechbrain-main/tests/integration/ASR_CTC/example_asr_ctc_experiment_complex_net.py | #!/usr/bin/env/python3
"""This minimal example trains a CTC-based speech recognizer on a tiny dataset.
The encoder is based on a combination of convolutional, recurrent, and
feed-forward networks (CRDNN) that predict phonemes. A greedy search is used on
top of the output probabilities.
Given the tiny dataset, the expe... | 5,107 | 33.053333 | 80 | py |
speechbrain | speechbrain-main/tests/integration/ASR_CTC/example_asr_ctc_experiment.py | #!/usr/bin/env/python3
"""This minimal example trains a CTC-based speech recognizer on a tiny dataset.
The encoder is based on a combination of convolutional, recurrent, and
feed-forward networks (CRDNN) that predict phonemes. A greedy search is used on
top of the output probabilities.
Given the tiny dataset, the expe... | 5,096 | 32.98 | 80 | py |
speechbrain | speechbrain-main/tests/integration/ASR_CTC/example_asr_ctc_experiment_quaternion_net.py | #!/usr/bin/env/python3
"""This minimal example trains a CTC-based speech recognizer on a tiny dataset.
The encoder is based on a combination of convolutional, recurrent, and
feed-forward networks (CRDNN) that predict phonemes. A greedy search is used on
top of the output probabilities.
Given the tiny dataset, the expe... | 5,110 | 33.073333 | 80 | py |
speechbrain | speechbrain-main/tests/integration/ASR_Transducer/example_asr_transducer_experiment.py | #!/usr/bin/env/python3
"""This minimal example trains a RNNT-based speech recognizer on a tiny dataset.
The encoder is based on a combination of convolutional, recurrent, and
feed-forward networks (CRDNN) that predict phonemes. A beamsearch is used on
top of the output probabilities.
Given the tiny dataset, the expect... | 6,161 | 34.011364 | 80 | py |
speechbrain | speechbrain-main/tests/integration/LM_RNN/example_lm_rnn_experiment.py | #!/usr/bin/env/python3
"""This minimal example trains a character-level language model that predicts
the next characters given the previous ones. The system uses a standard
attention-based encoder-decoder pipeline. The encoder is based on a simple LSTM.
Given the tiny dataset, the expected behavior is to overfit the t... | 4,471 | 33.666667 | 80 | py |
speechbrain | speechbrain-main/tests/integration/VAD/example_vad.py | """This minimal example trains a Voice Activity Detector (VAD) on a tiny dataset.
The network is based on a LSTM with a linear transformation on the top of that.
The system is trained with the binary cross-entropy metric.
"""
import os
import torch
import numpy as np
import speechbrain as sb
from hyperpyyaml import lo... | 4,976 | 31.109677 | 81 | py |
speechbrain | speechbrain-main/tests/integration/ASR_alignment_forward/example_asr_alignment_forward_experiment.py | #!/usr/bin/env/python3
"""This minimal example trains an HMM-based aligner with the forward algorithm.
The encoder is based on a combination of convolutional, recurrent, and
feed-forward networks (CRDNN) that predict phoneme states.
Given the tiny dataset, the expected behavior is to overfit the training data
(with a v... | 4,687 | 31.783217 | 79 | py |
speechbrain | speechbrain-main/tests/integration/ASR_seq2seq/example_asr_seq2seq_experiment.py | #!/usr/bin/env/python3
"""This minimal example trains a seq2seq attention-based model for speech
recognition on a tiny dataset. The encoder is based on a combination of
convolutional, recurrent, and feed-forward networks (CRDNN). The decoder is
based on a GRU. A greedy search is used on top of the output probabilitie... | 6,322 | 33.933702 | 80 | py |
speechbrain | speechbrain-main/tests/integration/enhance_GAN/example_enhance_gan_experiment.py | #!/usr/bin/env/python3
"""This minimal example trains a GAN speech enhancement system on a tiny dataset.
The generator and the discriminator are based on convolutional networks.
"""
import torch
import pathlib
import speechbrain as sb
from hyperpyyaml import load_hyperpyyaml
class EnhanceGanBrain(sb.Brain):
def ... | 6,058 | 33.821839 | 81 | py |
speechbrain | speechbrain-main/tests/integration/sampling/example_sorting.py | """This minimal example checks on sampling with ascending/descending sorting and random shuffling; w/ & w/o DDP.
"""
import os
import torch
import pickle
import pathlib
import itertools
import speechbrain as sb
import torch.multiprocessing as mp
from hyperpyyaml import load_hyperpyyaml
class SamplingBrain(sb.Brain):... | 7,867 | 33.358079 | 116 | py |
speechbrain | speechbrain-main/tests/integration/speaker_id/example_xvector_experiment.py | #!/usr/bin/env/python3
"""This minimal example trains a speaker identification system based on
x-vectors. The encoder is based on TDNNs. The classifier is a MLP.
"""
import pathlib
import speechbrain as sb
from hyperpyyaml import load_hyperpyyaml
# Trains xvector model
class XvectorBrain(sb.Brain):
def compute_f... | 4,655 | 32.021277 | 80 | py |
speechbrain | speechbrain-main/tests/utils/refactoring_checks.py | #!/usr/bin/env/python3
"""This is a test script for creating a list of expected outcomes (before refactoring);
then, manual editing might change YAMLs and/or code; another test runs to compare results
(after refactoring to before). The target is a list of known HF repos.
The goal is to identify to which extent changes... | 19,156 | 36.489237 | 197 | py |
speechbrain | speechbrain-main/docs/conf.py | # Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Path setup --------------------------------------------------------------
# If ex... | 4,241 | 26.192308 | 79 | py |
Dink-Net | Dink-Net-main/main.py | import os
import wandb
import argparse
from utils import *
from tqdm import tqdm
from model import DinkNet, DinkNet_dgl
def train(args=None):
# setup random seed
setup_seed(args.seed)
# load graph data
if args.dataset in ["cora", "citeseer"]:
x, adj, y, n, k, d = load_data(args.dataset)
... | 3,933 | 32.338983 | 122 | py |
Dink-Net | Dink-Net-main/utils.py | import dgl
import sys
import copy
import torch
import random
import numpy as np
import pickle as pkl
import networkx as nx
import scipy.sparse as sp
from munkres import Munkres
from collections import Counter
from sklearn.metrics import accuracy_score, f1_score
from sklearn.metrics import adjusted_rand_score as ari_sco... | 21,067 | 34.7691 | 124 | py |
Dink-Net | Dink-Net-main/model.py | from utils import *
import torch.nn as nn
import dgl.function as fn
import torch.nn.functional as F
from dgl.nn.pytorch import GraphConv
# ------------------------from scratch------------------------
class GCN(nn.Module):
def __init__(self, in_ft, out_ft, act):
super(GCN, self).__init__()
self.fc =... | 8,030 | 34.852679 | 124 | py |
ice-ice | ice-ice/legacy.py | # Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and re... | 16,502 | 50.411215 | 154 | py |
ice-ice | ice-ice/style_mixing.py | # Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and rel... | 4,891 | 40.109244 | 132 | py |
ice-ice | ice-ice/projector.py | # Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and rel... | 8,990 | 41.211268 | 136 | py |
ice-ice | ice-ice/generate.py | # Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and rel... | 5,338 | 40.069231 | 132 | py |
ice-ice | ice-ice/train.py | # Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and rel... | 24,067 | 43.487985 | 192 | py |
ice-ice | ice-ice/calc_metrics.py | # Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and rel... | 8,336 | 42.649215 | 142 | py |
ice-ice | ice-ice/training/loss.py | # Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and re... | 7,297 | 53.462687 | 160 | py |
ice-ice | ice-ice/training/augment.py | # Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and re... | 26,373 | 60.050926 | 366 | py |
ice-ice | ice-ice/training/dataset.py | # Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and re... | 8,551 | 35.084388 | 158 | py |
ice-ice | ice-ice/training/networks.py | # Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and re... | 39,286 | 49.23913 | 164 | py |
ice-ice | ice-ice/training/training_loop.py | # Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and re... | 21,596 | 50.177725 | 168 | py |
ice-ice | ice-ice/training/networks_old.py | # Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and re... | 37,392 | 50.223288 | 164 | py |
ice-ice | ice-ice/torch_utils/custom_ops.py | # Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and rel... | 5,644 | 43.448819 | 146 | py |
ice-ice | ice-ice/torch_utils/training_stats.py | # Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and rel... | 10,707 | 38.806691 | 118 | py |
ice-ice | ice-ice/torch_utils/persistence.py | # Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and re... | 9,708 | 37.527778 | 144 | py |
ice-ice | ice-ice/torch_utils/misc.py | # Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and re... | 10,992 | 40.798479 | 133 | py |
ice-ice | ice-ice/torch_utils/ops/bias_act.py | # Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and rel... | 10,047 | 46.173709 | 185 | py |
ice-ice | ice-ice/torch_utils/ops/grid_sample_gradfix.py | # Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and rel... | 3,299 | 38.285714 | 138 | py |
ice-ice | ice-ice/torch_utils/ops/conv2d_gradfix.py | # Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and rel... | 7,677 | 43.900585 | 197 | py |
ice-ice | ice-ice/torch_utils/ops/upfirdn2d.py | # Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and rel... | 16,287 | 41.306494 | 157 | py |
ice-ice | ice-ice/torch_utils/ops/conv2d_resample.py | # Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and rel... | 7,591 | 47.356688 | 130 | py |
ice-ice | ice-ice/torch_utils/ops/fma.py | # Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and rel... | 2,034 | 32.360656 | 105 | py |
ice-ice | ice-ice/metrics/metric_utils.py | # Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and re... | 11,806 | 41.778986 | 167 | py |
ice-ice | ice-ice/metrics/kernel_inception_distance.py | # Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and re... | 2,302 | 48 | 118 | py |
ice-ice | ice-ice/metrics/frechet_inception_distance.py | # Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and re... | 2,040 | 47.595238 | 118 | py |
ice-ice | ice-ice/metrics/perceptual_path_length.py | # Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and re... | 5,538 | 40.962121 | 131 | py |
ice-ice | ice-ice/metrics/inception_score.py | # Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and re... | 1,874 | 47.076923 | 126 | py |
ice-ice | ice-ice/metrics/metric_main.py | # Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and re... | 5,715 | 36.359477 | 147 | py |
ice-ice | ice-ice/metrics/precision_recall.py | # Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and re... | 3,617 | 56.428571 | 159 | py |
ice-ice | ice-ice/ice/landmark_interpolation.py | import numpy as np
import scipy.spatial
import skimage.draw
import torch
from torchvision import io
import face_alignment
import matplotlib.pyplot as plt
def interpolate_from_landmarks(image, landmarks, vertex_indices=None, weights=None, mask=None):
H, W = image.shape[-2:]
step = 4
rect = landmarks.new_... | 4,861 | 37.283465 | 136 | py |
ice-ice | ice-ice/ice/resnet.py | import torch.nn as nn
import torch.utils.model_zoo as model_zoo
__all__ = ['ResNet', 'resnet50']
model_urls = {
'resnet18': 'https://download.pytorch.org/models/resnet18-5c106cde.pth',
'resnet34': 'https://download.pytorch.org/models/resnet34-333f7ec4.pth',
'resnet50': 'https://download.pytorch.org/mode... | 7,115 | 31.792627 | 116 | py |
ice-ice | ice-ice/ice/wrapper.py | import matplotlib.pyplot as plt
import face_alignment
import kornia
import torch
from torch import nn
import torchvision.transforms as transforms
import torch.nn.functional as F
from torch_utils import misc
import dnnlib
import legacy
from external.identity.iresnet import iresnet50, iresnet100
from external.landmark.... | 10,977 | 36.986159 | 106 | py |
ice-ice | ice-ice/ice/criterions.py | import matplotlib.pyplot as plt
import kornia
import torch
from torch import nn
import torch.nn.functional as F
import torchvision.transforms as transforms
from wrapper import StyleGanWrapper, FaceSegmenter, KeyPointDetector
from landmark_interpolation import interpolate_from_landmarks
def masked_mean(x, mask):
... | 9,823 | 34.338129 | 94 | py |
ice-ice | ice-ice/ice/jtj_analysis.py | import functools
import itertools
import numpy as np
from pathlib import Path
import pickle
import matplotlib.pyplot as plt
import numpy as np
import torch
from torch import nn
import torch.nn.functional as F
import torchvision.transforms as transforms
from torch.utils.data import DataLoader, Dataset
from tqdm import t... | 7,312 | 32.240909 | 118 | py |
ice-ice | ice-ice/ice/external/identity/iresnet.py | import torch
from torch import nn
__all__ = ['iresnet18', 'iresnet34', 'iresnet50', 'iresnet100', 'iresnet200']
def conv3x3(in_planes, out_planes, stride=1, groups=1, dilation=1):
"""3x3 convolution with padding"""
return nn.Conv2d(in_planes,
out_planes,
kernel_size=... | 7,401 | 36.383838 | 97 | py |
ice-ice | ice-ice/ice/external/parsing/model.py | #!/usr/bin/python
# -*- encoding: utf-8 -*-
import torch
import torch.nn as nn
import torch.nn.functional as F
import torchvision
# from resnet import Resnet18
# from modules.bn import InPlaceABNSync as BatchNorm2d
# ---------------------------------------------------
import torch
import torch.nn as nn
import torch... | 14,108 | 35.742188 | 91 | py |
ice-ice | ice-ice/ice/external/attribution/resnet.py | import torch.nn as nn
import torch.utils.model_zoo as model_zoo
__all__ = ['ResNet', 'resnet50']
model_urls = {
'resnet18': 'https://download.pytorch.org/models/resnet18-5c106cde.pth',
'resnet34': 'https://download.pytorch.org/models/resnet34-333f7ec4.pth',
'resnet50': 'https://download.pytorch.org/mode... | 7,115 | 31.792627 | 116 | py |
MrMustard-develop | MrMustard-develop/mrmustard/__init__.py | # Copyright 2022 Xanadu Quantum Technologies Inc.
# 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 applicable law or agre... | 5,726 | 33.089286 | 100 | py |
MrMustard-develop | MrMustard-develop/mrmustard/math/torch.py | # Copyright 2021 Xanadu Quantum Technologies Inc.
# 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 applicable law or agre... | 12,620 | 32.745989 | 109 | py |
MrMustard-develop | MrMustard-develop/mrmustard/math/__init__.py | # Copyright 2021 Xanadu Quantum Technologies Inc.
# 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 applicable law or agre... | 2,161 | 33.870968 | 134 | py |
MrMustard-develop | MrMustard-develop/mrmustard/math/tensorflow.py | # Copyright 2021 Xanadu Quantum Technologies Inc.
# 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 applicable law or agre... | 22,806 | 35.785484 | 133 | py |
MrMustard-develop | MrMustard-develop/tests/test_math/test_interface.py | # Copyright 2022 Xanadu Quantum Technologies Inc.
# 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 applicable law or agre... | 2,035 | 29.848485 | 95 | py |
MrMustard-develop | MrMustard-develop/doc/conf.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Path setup -----------------------... | 4,913 | 30.299363 | 97 | py |
cGAN-KD | cGAN-KD-main/UTKFace/baseline_cnn.py | print("\n===================================================================================================")
import os
import argparse
import shutil
import timeit
import torch
import torchvision
import torchvision.transforms as transforms
import numpy as np
import torch.nn as nn
import torch.backends.cudnn as cudnn
... | 9,981 | 37.099237 | 433 | py |
cGAN-KD | cGAN-KD-main/UTKFace/eval_metrics.py | """
Compute
Inception Score (IS),
Frechet Inception Discrepency (FID), ref "https://github.com/mseitzer/pytorch-fid/blob/master/fid_score.py"
Maximum Mean Discrepancy (MMD)
for a set of fake images
use numpy array
Xr: high-level features for real images; nr by d array
Yr: labels for real images
Xg: high-level features... | 6,666 | 33.365979 | 143 | py |
cGAN-KD | cGAN-KD-main/UTKFace/train_net_for_label_embed.py |
import torch
import torch.nn as nn
from torchvision.utils import save_image
import numpy as np
import os
import timeit
from PIL import Image
### horizontally flip images
def hflip_images(batch_images):
uniform_threshold = np.random.uniform(0,1,len(batch_images))
indx_gt = np.where(uniform_threshold>0.5)[0]
... | 10,789 | 39.111524 | 262 | py |
cGAN-KD | cGAN-KD-main/UTKFace/DiffAugment_pytorch.py | # Differentiable Augmentation for Data-Efficient GAN Training
# Shengyu Zhao, Zhijian Liu, Ji Lin, Jun-Yan Zhu, and Song Han
# https://arxiv.org/pdf/2006.10738
import torch
import torch.nn.functional as F
def DiffAugment(x, policy='', channels_first=True):
if policy:
if not channels_first:
x ... | 3,025 | 38.298701 | 110 | py |
cGAN-KD | cGAN-KD-main/UTKFace/generate_synthetic_data.py | print("\n===================================================================================================")
import argparse
import copy
import gc
import numpy as np
import matplotlib.pyplot as plt
plt.switch_backend('agg')
import matplotlib as mpl
import h5py
import os
import random
from tqdm import tqdm, trange
im... | 34,527 | 45.659459 | 545 | py |
cGAN-KD | cGAN-KD-main/UTKFace/utils.py | """
Some helpful functions
"""
import numpy as np
import torch
import torch.nn as nn
import torchvision
import matplotlib.pyplot as plt
import matplotlib as mpl
from torch.nn import functional as F
import sys
import PIL
from PIL import Image
# ### import my stuffs ###
# from models import *
# ######################... | 5,139 | 29.595238 | 143 | py |
cGAN-KD | cGAN-KD-main/UTKFace/train_cdre.py | '''
Functions for Training Class-conditional Density-ratio model
'''
import torch
import torch.nn as nn
import numpy as np
import os
import timeit
import gc
from utils import *
from opts import gen_synth_data_opts
''' Settings '''
args = gen_synth_data_opts()
# some parameters in the opts
dim_gan = args.gan_dim_g... | 13,429 | 45.958042 | 323 | py |
cGAN-KD | cGAN-KD-main/UTKFace/test_infer_speed.py | import os
import argparse
import shutil
import timeit
import torch
import torchvision
import torchvision.transforms as transforms
import numpy as np
import torch.nn as nn
import torch.backends.cudnn as cudnn
import random
import matplotlib.pyplot as plt
import matplotlib as mpl
from torch import autograd
from torchvisi... | 3,059 | 30.22449 | 143 | py |
cGAN-KD | cGAN-KD-main/UTKFace/train_cnn.py | ''' For CNN training and testing. '''
import os
import timeit
import torch
import torch.nn as nn
import numpy as np
from torch.nn import functional as F
## horizontal flipping
def hflip_images(batch_images):
''' for numpy arrays '''
uniform_threshold = np.random.uniform(0,1,len(batch_images))
indx_gt = n... | 6,160 | 37.748428 | 249 | py |
cGAN-KD | cGAN-KD-main/UTKFace/train_sparseAE.py |
import torch
import torch.nn as nn
from torchvision.utils import save_image
import numpy as np
import os
import timeit
from utils import SimpleProgressBar
from opts import gen_synth_data_opts
''' Settings '''
args = gen_synth_data_opts()
# some parameters in the opts
epochs = args.dre_presae_epochs
base_lr = args.d... | 7,789 | 41.802198 | 328 | py |
cGAN-KD | cGAN-KD-main/UTKFace/train_ccgan.py | import torch
import numpy as np
import os
import timeit
from PIL import Image
from torchvision.utils import save_image
from utils import *
from opts import gen_synth_data_opts
from DiffAugment_pytorch import DiffAugment
''' Settings '''
args = gen_synth_data_opts()
# some parameters in opts
loss_type = args.gan_los... | 13,893 | 43.248408 | 261 | py |
cGAN-KD | cGAN-KD-main/UTKFace/models/shufflenetv2.py | '''ShuffleNetV2 in PyTorch.
See the paper "ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" for more details.
'''
import torch
import torch.nn as nn
import torch.nn.functional as F
class ShuffleBlock(nn.Module):
def __init__(self, groups=2):
super(ShuffleBlock, self).__init__()
... | 6,654 | 32.442211 | 107 | py |
cGAN-KD | cGAN-KD-main/UTKFace/models/SAGAN.py | '''
SAGAN arch
Adapted from https://github.com/voletiv/self-attention-GAN-pytorch/blob/master/sagan_models.py
'''
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.utils import spectral_norm
from torch.nn.init import xavier_uniform_
def init_weights(m):
if t... | 10,076 | 33.748276 | 129 | py |
cGAN-KD | cGAN-KD-main/UTKFace/models/efficientnet.py | '''EfficientNet in PyTorch.
Paper: "EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks".
Reference: https://github.com/keras-team/keras-applications/blob/master/keras_applications/efficientnet.py
'''
import torch
import torch.nn as nn
import torch.nn.functional as F
def swish(x):
return x * ... | 5,970 | 31.275676 | 106 | py |
cGAN-KD | cGAN-KD-main/UTKFace/models/ResNet_embed.py | '''
ResNet-based model to map an image from pixel space to a features space.
Need to be pretrained on the dataset.
if isometric_map = True, there is an extra step (elf.classifier_1 = nn.Linear(512, 32*32*3)) to increase the dimension of the feature map from 512 to 32*32*3. This selection is for desity-ratio estimation... | 6,302 | 32.526596 | 222 | py |
cGAN-KD | cGAN-KD-main/UTKFace/models/autoencoder_extract.py | import torch
from torch import nn
class encoder_extract(nn.Module):
def __init__(self, dim_bottleneck=64*64*3, ch=32):
super(encoder_extract, self).__init__()
self.ch = ch
self.dim_bottleneck = dim_bottleneck
self.conv = nn.Sequential(
nn.Conv2d(3, ch, kernel_size=4, ... | 5,073 | 30.320988 | 89 | py |
cGAN-KD | cGAN-KD-main/UTKFace/models/resnet.py | from __future__ import absolute_import
'''Resnet for cifar dataset.
Ported form
https://github.com/facebook/fb.resnet.torch
and
https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py
(c) YANG, Wei
'''
import torch.nn as nn
import torch.nn.functional as F
import math
__all__ = ['resnet']
def con... | 6,698 | 29.175676 | 116 | py |
cGAN-KD | cGAN-KD-main/UTKFace/models/vgg.py | '''VGG11/13/16/19 in Pytorch.'''
import torch
import torch.nn as nn
from torch.autograd import Variable
cfg = {
'VGG8': [64, 'M', 128, 'M', 256, 'M', 512, 'M', 512, 'M'],
'VGG11': [64, 'M', 128, 'M', 256, 256, 'M', 512, 512, 'M', 512, 512, 'M'],
'VGG13': [64, 64, 'M', 128, 128, 'M', 256, 256, 'M', 512, 5... | 2,119 | 24.853659 | 117 | py |
cGAN-KD | cGAN-KD-main/UTKFace/models/shufflenetv1.py | '''ShuffleNet in PyTorch.
See the paper "ShuffleNet: An Extremely Efficient Convolutional Neural Network for Mobile Devices" for more details.
To fit 128x128 images, I modified the first conv layer and add an extra max_pool2d after it (Following Table 5 of "ShuffleNet V2: Practical Guidelines for Efficient CNN Archite... | 4,440 | 33.968504 | 190 | py |
cGAN-KD | cGAN-KD-main/UTKFace/models/SNGAN.py | '''
https://github.com/christiancosgrove/pytorch-spectral-normalization-gan
chainer: https://github.com/pfnet-research/sngan_projection
'''
# ResNet generator and discriminator
import torch
from torch import nn
import torch.nn.functional as F
# from spectral_normalization import SpectralNorm
import numpy as np
from ... | 8,633 | 34.240816 | 96 | py |
cGAN-KD | cGAN-KD-main/UTKFace/models/densenet.py | '''DenseNet in PyTorch.
To fit 128x128 images, I modified the first conv layer and add an extra max_pool2d after it.
'''
import math
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
NC=3
IMG_SIZE = 64
class Bottleneck(nn.Module):
def __init__(self, in_plan... | 4,332 | 31.335821 | 96 | py |
cGAN-KD | cGAN-KD-main/UTKFace/models/resnetv2.py | '''
codes are based on
@article{
zhang2018mixup,
title={mixup: Beyond Empirical Risk Minimization},
author={Hongyi Zhang, Moustapha Cisse, Yann N. Dauphin, David Lopez-Paz},
journal={International Conference on Learning Representations},
year={2018},
url={https://openreview.net/forum?id=r1Ddp1-Rb},
}
'''
import torch... | 4,623 | 30.455782 | 102 | py |
cGAN-KD | cGAN-KD-main/UTKFace/models/cDR_MLP.py | '''
Conditional Density Ration Estimation via Multilayer Perceptron
Multilayer Perceptron : trained to model density ratio in a feature space
Its input is the output of a pretrained Deep CNN, say ResNet-34
'''
import torch
import torch.nn as nn
IMG_SIZE=64
NC=3
cfg = {"MLP3": [512,256,128],
"MLP5": [1024... | 2,157 | 29.394366 | 95 | py |
cGAN-KD | cGAN-KD-main/UTKFace/models/mobilenet.py | import torch
from torch import nn
# from .utils import load_state_dict_from_url
try:
from torch.hub import load_state_dict_from_url
except ImportError:
from torch.utils.model_zoo import load_url as load_state_dict_from_url
__all__ = ['MobileNetV2', 'mobilenet_v2']
model_urls = {
'mobilenet_v2': 'https:/... | 7,609 | 35.238095 | 116 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.