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
stablediffusion
stablediffusion-main/ldm/modules/ema.py
import torch from torch import nn class LitEma(nn.Module): def __init__(self, model, decay=0.9999, use_num_upates=True): super().__init__() if decay < 0.0 or decay > 1.0: raise ValueError('Decay must be between 0 and 1') self.m_name2s_name = {} self.register_buffer('de...
3,110
37.407407
102
py
stablediffusion
stablediffusion-main/ldm/modules/attention.py
from inspect import isfunction import math import torch import torch.nn.functional as F from torch import nn, einsum from einops import rearrange, repeat from typing import Optional, Any from ldm.modules.diffusionmodules.util import checkpoint try: import xformers import xformers.ops XFORMERS_IS_AVAILBLE...
11,806
33.523392
143
py
stablediffusion
stablediffusion-main/ldm/modules/midas/utils.py
"""Utils for monoDepth.""" import sys import re import numpy as np import cv2 import torch def read_pfm(path): """Read pfm file. Args: path (str): path to file Returns: tuple: (data, scale) """ with open(path, "rb") as file: color = None width = None heig...
4,582
23.121053
88
py
stablediffusion
stablediffusion-main/ldm/modules/midas/api.py
# based on https://github.com/isl-org/MiDaS import cv2 import torch import torch.nn as nn from torchvision.transforms import Compose from ldm.modules.midas.midas.dpt_depth import DPTDepthModel from ldm.modules.midas.midas.midas_net import MidasNet from ldm.modules.midas.midas.midas_net_custom import MidasNet_small fr...
5,338
30.222222
103
py
stablediffusion
stablediffusion-main/ldm/modules/midas/midas/base_model.py
import torch class BaseModel(torch.nn.Module): def load(self, path): """Load model from file. Args: path (str): file path """ parameters = torch.load(path, map_location=torch.device('cpu')) if "optimizer" in parameters: parameters = parameters["mod...
367
20.647059
71
py
stablediffusion
stablediffusion-main/ldm/modules/midas/midas/midas_net.py
"""MidashNet: Network for monocular depth estimation trained by mixing several datasets. This file contains code that is adapted from https://github.com/thomasjpfan/pytorch_refinenet/blob/master/pytorch_refinenet/refinenet/refinenet_4cascade.py """ import torch import torch.nn as nn from .base_model import BaseModel f...
2,709
34.194805
130
py
stablediffusion
stablediffusion-main/ldm/modules/midas/midas/vit.py
import torch import torch.nn as nn import timm import types import math import torch.nn.functional as F class Slice(nn.Module): def __init__(self, start_index=1): super(Slice, self).__init__() self.start_index = start_index def forward(self, x): return x[:, self.start_index :] class...
14,625
28.727642
96
py
stablediffusion
stablediffusion-main/ldm/modules/midas/midas/dpt_depth.py
import torch import torch.nn as nn import torch.nn.functional as F from .base_model import BaseModel from .blocks import ( FeatureFusionBlock, FeatureFusionBlock_custom, Interpolate, _make_encoder, forward_vit, ) def _make_fusion_block(features, use_bn): return FeatureFusionBlock_custom( ...
3,154
27.681818
89
py
stablediffusion
stablediffusion-main/ldm/modules/midas/midas/midas_net_custom.py
"""MidashNet: Network for monocular depth estimation trained by mixing several datasets. This file contains code that is adapted from https://github.com/thomasjpfan/pytorch_refinenet/blob/master/pytorch_refinenet/refinenet/refinenet_4cascade.py """ import torch import torch.nn as nn from .base_model import BaseModel f...
5,207
39.6875
168
py
stablediffusion
stablediffusion-main/ldm/modules/midas/midas/blocks.py
import torch import torch.nn as nn from .vit import ( _make_pretrained_vitb_rn50_384, _make_pretrained_vitl16_384, _make_pretrained_vitb16_384, forward_vit, ) def _make_encoder(backbone, features, use_pretrained, groups=1, expand=False, exportable=True, hooks=None, use_vit_only=False, use_readout="ign...
9,242
25.947522
150
py
stablediffusion
stablediffusion-main/ldm/modules/distributions/distributions.py
import torch import numpy as np class AbstractDistribution: def sample(self): raise NotImplementedError() def mode(self): raise NotImplementedError() class DiracDistribution(AbstractDistribution): def __init__(self, value): self.value = value def sample(self): retur...
2,970
30.946237
131
py
stablediffusion
stablediffusion-main/ldm/modules/karlo/diffusers_pipeline.py
# Copyright 2022 Kakao Brain and The HuggingFace Team. 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 requi...
23,391
44.6875
131
py
stablediffusion
stablediffusion-main/ldm/modules/karlo/kakao/sampler.py
# ------------------------------------------------------------------------------------ # Karlo-v1.0.alpha # Copyright (c) 2022 KakaoBrain. All Rights Reserved. # source: https://github.com/kakaobrain/karlo/blob/3c68a50a16d76b48a15c181d1c5a5e0879a90f85/karlo/sampler/t2i.py#L15 # ----------------------------------------...
8,718
30.937729
116
py
stablediffusion
stablediffusion-main/ldm/modules/karlo/kakao/template.py
# ------------------------------------------------------------------------------------ # Karlo-v1.0.alpha # Copyright (c) 2022 KakaoBrain. All Rights Reserved. # ------------------------------------------------------------------------------------ import os import logging import torch from omegaconf import OmegaConf ...
4,288
29.41844
102
py
stablediffusion
stablediffusion-main/ldm/modules/karlo/kakao/modules/resample.py
# ------------------------------------------------------------------------------------ # Modified from Guided-Diffusion (https://github.com/openai/guided-diffusion) # ------------------------------------------------------------------------------------ from abc import abstractmethod import torch as th def create_nam...
2,237
31.434783
86
py
stablediffusion
stablediffusion-main/ldm/modules/karlo/kakao/modules/nn.py
# ------------------------------------------------------------------------------------ # Adapted from Guided-Diffusion repo (https://github.com/openai/guided-diffusion) # ------------------------------------------------------------------------------------ import math import torch as th import torch.nn as nn import to...
3,233
27.121739
86
py
stablediffusion
stablediffusion-main/ldm/modules/karlo/kakao/modules/unet.py
# ------------------------------------------------------------------------------------ # Modified from Guided-Diffusion (https://github.com/openai/guided-diffusion) # ------------------------------------------------------------------------------------ import math from abc import abstractmethod import torch as th impo...
28,289
34.674653
124
py
stablediffusion
stablediffusion-main/ldm/modules/karlo/kakao/modules/xf.py
# ------------------------------------------------------------------------------------ # Adapted from the repos below: # (a) Guided-Diffusion (https://github.com/openai/guided-diffusion) # (b) CLIP ViT (https://github.com/openai/CLIP/) # ----------------------------------------------------------------------------------...
6,535
27.172414
86
py
stablediffusion
stablediffusion-main/ldm/modules/karlo/kakao/modules/diffusion/gaussian_diffusion.py
# ------------------------------------------------------------------------------------ # Adapted from Guided-Diffusion repo (https://github.com/openai/guided-diffusion) # ------------------------------------------------------------------------------------ import enum import math import numpy as np import torch as th ...
30,386
35.655006
129
py
stablediffusion
stablediffusion-main/ldm/modules/karlo/kakao/modules/diffusion/respace.py
# ------------------------------------------------------------------------------------ # Adapted from Guided-Diffusion repo (https://github.com/openai/guided-diffusion) # ------------------------------------------------------------------------------------ import torch as th from .gaussian_diffusion import GaussianDi...
4,768
41.20354
91
py
stablediffusion
stablediffusion-main/ldm/modules/karlo/kakao/models/clip.py
# ------------------------------------------------------------------------------------ # Karlo-v1.0.alpha # Copyright (c) 2022 KakaoBrain. All Rights Reserved. # ------------------------------------------------------------------------------------ # -----------------------------------------------------------------------...
6,071
32.180328
97
py
stablediffusion
stablediffusion-main/ldm/modules/karlo/kakao/models/sr_64_256.py
# ------------------------------------------------------------------------------------ # Karlo-v1.0.alpha # Copyright (c) 2022 KakaoBrain. All Rights Reserved. # ------------------------------------------------------------------------------------ import copy import torch from ldm.modules.karlo.kakao.modules.unet impo...
3,661
40.146067
115
py
stablediffusion
stablediffusion-main/ldm/modules/karlo/kakao/models/decoder_model.py
# ------------------------------------------------------------------------------------ # Karlo-v1.0.alpha # Copyright (c) 2022 KakaoBrain. All Rights Reserved. # ------------------------------------------------------------------------------------ import copy import torch from ldm.modules.karlo.kakao.modules import cr...
6,719
33.639175
86
py
stablediffusion
stablediffusion-main/ldm/modules/karlo/kakao/models/prior_model.py
# ------------------------------------------------------------------------------------ # Karlo-v1.0.alpha # Copyright (c) 2022 KakaoBrain. All Rights Reserved. # ------------------------------------------------------------------------------------ import copy import torch from ldm.modules.karlo.kakao.modules import cr...
5,101
35.705036
90
py
stablediffusion
stablediffusion-main/ldm/modules/image_degradation/bsrgan.py
# -*- coding: utf-8 -*- """ # -------------------------------------------- # Super-Resolution # -------------------------------------------- # # Kai Zhang (cskaizhang@gmail.com) # https://github.com/cszn # From 2019/03--2021/08 # -------------------------------------------- """ import numpy as np import cv2 import tor...
25,198
33.471956
147
py
stablediffusion
stablediffusion-main/ldm/modules/image_degradation/bsrgan_light.py
# -*- coding: utf-8 -*- import numpy as np import cv2 import torch from functools import partial import random from scipy import ndimage import scipy import scipy.stats as ss from scipy.interpolate import interp2d from scipy.linalg import orth import albumentations import ldm.modules.image_degradation.utils_image as ...
22,341
33.266871
147
py
stablediffusion
stablediffusion-main/ldm/modules/image_degradation/utils_image.py
import os import math import random import numpy as np import torch import cv2 from torchvision.utils import make_grid from datetime import datetime #import matplotlib.pyplot as plt # TODO: check with Dominik, also bsrgan.py vs bsrgan_light.py os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE" ''' # ----------------------...
29,022
30.684498
107
py
stablediffusion
stablediffusion-main/ldm/modules/encoders/modules.py
import torch import torch.nn as nn import kornia from torch.utils.checkpoint import checkpoint from transformers import T5Tokenizer, T5EncoderModel, CLIPTokenizer, CLIPTextModel import open_clip from ldm.util import default, count_params, autocast class AbstractEncoder(nn.Module): def __init__(self): su...
12,694
35.168091
120
py
stablediffusion
stablediffusion-main/ldm/modules/diffusionmodules/upscaling.py
import torch import torch.nn as nn import numpy as np from functools import partial from ldm.modules.diffusionmodules.util import extract_into_tensor, make_beta_schedule from ldm.util import default class AbstractLowScaleModel(nn.Module): # for concatenating a downsampled image to the latent representation d...
3,424
40.768293
110
py
stablediffusion
stablediffusion-main/ldm/modules/diffusionmodules/model.py
# pytorch_diffusion + derived encoder decoder import math import torch import torch.nn as nn import numpy as np from einops import rearrange from typing import Optional, Any from ldm.modules.attention import MemoryEfficientCrossAttention try: import xformers import xformers.ops XFORMERS_IS_AVAILBLE = True...
34,384
39.310668
138
py
stablediffusion
stablediffusion-main/ldm/modules/diffusionmodules/openaimodel.py
from abc import abstractmethod import math import numpy as np import torch as th import torch.nn as nn import torch.nn.functional as F from ldm.modules.diffusionmodules.util import ( checkpoint, conv_nd, linear, avg_pool_nd, zero_module, normalization, timestep_embedding, ) from ldm.module...
31,050
37.429455
143
py
stablediffusion
stablediffusion-main/ldm/modules/diffusionmodules/util.py
# adopted from # https://github.com/openai/improved-diffusion/blob/main/improved_diffusion/gaussian_diffusion.py # and # https://github.com/lucidrains/denoising-diffusion-pytorch/blob/7706bdfc6f527f58d33f84b7b522e61e6e3164b3/denoising_diffusion_pytorch/denoising_diffusion_pytorch.py # and # https://github.com/openai/gu...
10,102
35.21147
164
py
stablediffusion
stablediffusion-main/ldm/models/autoencoder.py
import torch import pytorch_lightning as pl import torch.nn.functional as F from contextlib import contextmanager from ldm.modules.diffusionmodules.model import Encoder, Decoder from ldm.modules.distributions.distributions import DiagonalGaussianDistribution from ldm.util import instantiate_from_config from ldm.modul...
8,560
37.913636
116
py
stablediffusion
stablediffusion-main/ldm/models/diffusion/ddim.py
"""SAMPLING ONLY.""" import torch import numpy as np from tqdm import tqdm from ldm.modules.diffusionmodules.util import make_ddim_sampling_parameters, make_ddim_timesteps, noise_like, extract_into_tensor class DDIMSampler(object): def __init__(self, model, schedule="linear", device=torch.device("cuda"), **kwar...
17,344
50.468843
136
py
stablediffusion
stablediffusion-main/ldm/models/diffusion/ddpm.py
""" wild mixture of https://github.com/lucidrains/denoising-diffusion-pytorch/blob/7706bdfc6f527f58d33f84b7b522e61e6e3164b3/denoising_diffusion_pytorch/denoising_diffusion_pytorch.py https://github.com/openai/improved-diffusion/blob/e94489283bb876ac1477d5dd7709bbbd2d9902ce/improved_diffusion/gaussian_diffusion.py https...
88,698
46.331377
162
py
stablediffusion
stablediffusion-main/ldm/models/diffusion/plms.py
"""SAMPLING ONLY.""" import torch import numpy as np from tqdm import tqdm from functools import partial from ldm.modules.diffusionmodules.util import make_ddim_sampling_parameters, make_ddim_timesteps, noise_like from ldm.models.diffusion.sampling_util import norm_thresholding class PLMSSampler(object): def __...
12,967
51.715447
131
py
stablediffusion
stablediffusion-main/ldm/models/diffusion/sampling_util.py
import torch import numpy as np def append_dims(x, target_dims): """Appends dimensions to the end of a tensor until it has target_dims dimensions. From https://github.com/crowsonkb/k-diffusion/blob/master/k_diffusion/utils.py""" dims_to_append = target_dims - x.ndim if dims_to_append < 0: rais...
753
33.272727
100
py
stablediffusion
stablediffusion-main/ldm/models/diffusion/dpm_solver/dpm_solver.py
import torch import torch.nn.functional as F import math from tqdm import tqdm class NoiseScheduleVP: def __init__( self, schedule='discrete', betas=None, alphas_cumprod=None, continuous_beta_0=0.1, continuous_beta_1=20., ): """Cr...
66,500
56.180567
308
py
stablediffusion
stablediffusion-main/ldm/models/diffusion/dpm_solver/sampler.py
"""SAMPLING ONLY.""" import torch from .dpm_solver import NoiseScheduleVP, model_wrapper, DPM_Solver MODEL_TYPES = { "eps": "noise", "v": "v" } class DPMSolverSampler(object): def __init__(self, model, device=torch.device("cuda"), **kwargs): super().__init__() self.model = model ...
3,530
35.402062
115
py
stablediffusion
stablediffusion-main/ldm/data/util.py
import torch from ldm.modules.midas.api import load_midas_transform class AddMiDaS(object): def __init__(self, model_type): super().__init__() self.transform = load_midas_transform(model_type) def pt2np(self, x): x = ((x + 1.0) * .5).detach().cpu().numpy() return x def n...
629
25.25
62
py
Generalization-of-Federated-Learning
Generalization-of-Federated-Learning-main/dataset/generate_mnist.py
import numpy as np import os import sys import random import torch import torchvision import torchvision.transforms as transforms from utils.dataset_utils import check, separate_data, split_data, save_file random.seed(1) np.random.seed(1) num_clients = 10 num_classes = 10 dir_path = "mnist/" # Allocate data to user...
2,976
35.304878
101
py
Generalization-of-Federated-Learning
Generalization-of-Federated-Learning-main/system/main.py
#!/usr/bin/env python import copy import torch import argparse import os import time import warnings import numpy as np import torchvision import logging from flcore.servers.serveravg import FedAvg from flcore.servers.serverpFedMe import pFedMe from flcore.servers.serverperavg import PerAvg from flcore.servers.serverp...
20,098
43.964206
151
py
Generalization-of-Federated-Learning
Generalization-of-Federated-Learning-main/system/flcore/clients/clientbase.py
import copy import torch import torch.nn as nn import numpy as np import os import torch.nn.functional as F from torch.utils.data import DataLoader from sklearn.preprocessing import label_binarize from sklearn import metrics from utils.data_utils import read_client_data class Client(object): """ Base class fo...
6,948
33.572139
102
py
Generalization-of-Federated-Learning
Generalization-of-Federated-Learning-main/system/flcore/servers/serverbase.py
import torch import os import numpy as np import pandas as pd import copy import time import random from utils.data_utils import read_client_data from utils.dlg import DLG class Server(object): def __init__(self, args, times): # Set up the main attributes self.args = args self.device = ar...
14,979
36.638191
173
py
Generalization-of-Federated-Learning
Generalization-of-Federated-Learning-main/system/flcore/servers/serverscaffold.py
import copy import random import time import torch from flcore.clients.clientscaffold import clientSCAFFOLD from flcore.servers.serverbase import Server from threading import Thread class SCAFFOLD(Server): def __init__(self, args, times): super().__init__(args, times) # select slow clients ...
6,029
38.155844
116
py
cfsl
cfsl-master/frameworks/cfsl/experiment_builder.py
import os import time import numpy as np import torchvision import matplotlib.pyplot as plt import matplotlib.cm as cm import tqdm from torch.utils.tensorboard import SummaryWriter from utils.storage import build_experiment_folder, save_statistics, save_to_json, save_config class ExperimentBuilder(object): def ...
24,993
50.427984
188
py
cfsl
cfsl-master/frameworks/cfsl/data.py
import concurrent.futures from collections import defaultdict import os import numpy as np import torch import tqdm from PIL import ImageFile from torch.utils.data import Dataset from utils.dataset_tools import get_label_set, load_dataset, load_image, check_download_dataset import re ImageFile.LOAD_TRUNCATED_IMAGES =...
12,561
45.354244
297
py
cfsl
cfsl-master/frameworks/cfsl/standard_neural_network_architectures.py
from collections import OrderedDict import numpy as np import torch import torch.nn as nn import torch.nn.functional as F # flag class Conv2dNormLeakyReLU(nn.Module): def __init__(self, input_shape, num_filters, kernel_size, dilation=1, stride=1, groups=1, padding=0, use_bias=False, normalization...
52,387
43.737831
246
py
cfsl
cfsl-master/frameworks/cfsl/meta_neural_network_architectures.py
import logging import math from copy import copy import numpy as np import torch import torch.nn as nn import torch.nn.functional as F from torch.nn.init import _calculate_fan_in_and_fan_out def extract_top_level_dict(current_dict): """ Builds a graph dictionary from the passed depth_keys, value pair. Useful...
52,354
46.85649
223
py
cfsl
cfsl-master/frameworks/cfsl/meta_optimizer.py
import torch import torch.nn as nn class GradientDescentLearningRule(nn.Module): """Simple (stochastic) gradient descent learning rule. For a scalar error function `E(p[0], p_[1] ... )` of some set of potentially multidimensional parameters this attempts to find a local minimum of the loss function by...
5,676
48.798246
111
py
cfsl
cfsl-master/frameworks/cfsl/pytorch_utils.py
import torch import torch.functional as F import torch.nn as nn import numpy as np def int_to_one_hot(int_labels): num_output_units = torch.max(int_labels).long() + 1 labels_one_hot = torch.zeros(int_labels.shape[0], num_output_units).long().to(int_labels.device) labels_one_hot.scatter_(1, int_labels.unsq...
430
27.733333
100
py
cfsl
cfsl-master/frameworks/cfsl/train_continual_learning_few_shot_system.py
from torch.utils.data import DataLoader from torch.utils.tensorboard import SummaryWriter from utils.parser_utils import get_args from utils.dataset_tools import check_download_dataset from data import ConvertToThreeChannels, FewShotLearningDatasetParallel from torchvision import transforms from experiment_builder im...
6,704
55.822034
119
py
cfsl
cfsl-master/frameworks/cfsl/models/fine_tune_from_pretrained_few_shot_classifier.py
import os from collections import OrderedDict, defaultdict import numpy as np import torch import torch.nn as nn import torch.nn.functional as F from torch import optim from torch.optim import AdamW from meta_neural_network_architectures import VGGActivationNormNetwork, \ VGGActivationNormNetworkWithAttention fro...
32,626
52.751236
163
py
cfsl
cfsl-master/frameworks/cfsl/models/matching_network_few_shot_classifier.py
import os from collections import OrderedDict, defaultdict import numpy as np import torch import torch.nn as nn import torch.nn.functional as F from torch import optim from torch.optim import AdamW from meta_neural_network_architectures import VGGActivationNormNetwork, \ VGGActivationNormNetworkWithAttention fro...
12,697
42.486301
131
py
cfsl
cfsl-master/frameworks/cfsl/models/vgg_aha_few_shot_classifier.py
from operator import sub import os import random from collections import OrderedDict, defaultdict, deque import re import numpy as np import torch import torch.nn as nn import torch.nn.functional as F from torch import optim from torch.optim import AdamW from meta_neural_network_architectures import VGGActivationNor...
37,618
51.687675
163
py
cfsl
cfsl-master/frameworks/cfsl/models/embedding_maml_few_shot_classifier.py
import os from collections import OrderedDict, defaultdict import numpy as np import torch import torch.nn as nn import torch.nn.functional as F from torch import optim from torch.optim import AdamW from meta_neural_network_architectures import VGGActivationNormNetwork, \ VGGActivationNormNetworkWithAttention fro...
31,000
53.292469
128
py
cfsl
cfsl-master/frameworks/cfsl/models/fine_tune_from_scratch_few_shot_classifier.py
import os from collections import OrderedDict, defaultdict import numpy as np import torch import torch.nn as nn import torch.nn.functional as F from torch import optim from torch.optim import AdamW from meta_neural_network_architectures import VGGActivationNormNetwork, \ VGGActivationNormNetworkWithAttention fro...
31,917
53.190153
149
py
cfsl
cfsl-master/frameworks/cfsl/models/vgg_maml_few_shot_classifier.py
import os from collections import OrderedDict, defaultdict import numpy as np import torch import torch.nn as nn import torch.nn.functional as F from torch import optim from torch.optim import AdamW from meta_neural_network_architectures import VGGActivationNormNetwork, \ VGGActivationNormNetworkWithAttention fro...
26,266
50.503922
128
py
cfsl
cfsl-master/frameworks/cfsl/models/cls_few_shot_classifier.py
"""cls_few_shot_classifier.py""" import os import random from collections import OrderedDict, defaultdict, deque import numpy as np import torch import torch.nn as nn import torch.optim as optim import torch.nn.functional as F from torch.utils.tensorboard import SummaryWriter import torchvision import matplotlib i...
19,502
39.378882
126
py
cfsl
cfsl-master/frameworks/cfsl/models/maml_few_shot_classifier.py
import os from collections import OrderedDict, defaultdict import numpy as np import torch import torch.nn as nn import torch.nn.functional as F from torch import optim from torch.optim import AdamW from meta_neural_network_architectures import VGGActivationNormNetwork, \ VGGActivationNormNetworkWithAttention fro...
14,763
48.710438
120
py
cfsl
cfsl-master/frameworks/cfsl/utils/matching.py
"""lake/utils.py""" import os import math import random import datetime import torch import numpy as np import matplotlib.pyplot as plt def get_summary_dir(): now = datetime.datetime.now() summary_dir = os.path.join('.', 'runs', now.strftime("%Y%m%d-%H%M%S")) return summary_dir def set_seed(seed): random....
10,438
31.930599
118
py
cfsl
cfsl-master/frameworks/cfsl/utils/parser_utils.py
import argparse import os import torch import json def get_args(): parser = argparse.ArgumentParser(description='Welcome to the meta-learning training and inference system') parser.add_argument('--batch_size', nargs="?", type=int, default=32, help='Batch_size for experiment') parser.add_argument('--imag...
11,506
49.030435
187
py
cfsl
cfsl-master/frameworks/cfsl/utils/generic.py
import torch import numpy as np def set_torch_seed(seed): """ Sets the pytorch seeds for current experiment run :param seed: The seed (int) :return: A random number generator to use """ rng = np.random.RandomState(seed=seed) torch_seed = rng.randint(0, 999999) torch.manual_seed(seed=torch_seed) ret...
1,272
30.04878
115
py
cfsl
cfsl-master/frameworks/cfsl/utils/dataset_tools.py
import os import json import shutil import urllib import pathlib import tarfile import tempfile import concurrent.futures import numpy as np import tqdm from PIL import Image from torchvision import transforms DOWNLOAD_URL = { 'omniglot_dataset': 'https://storage.googleapis.com/project-agi/datasets/omniglot/omnigl...
15,291
45.907975
161
py
espnet
espnet-master/setup.py
#!/usr/bin/env python3 """ESPnet setup script.""" import os from setuptools import find_packages, setup requirements = { "install": [ "setuptools>=38.5.1", "packaging", "configargparse>=1.2.1", "typeguard==2.13.3", "humanfriendly", "scipy>=1.4.1", "fileloc...
5,217
30.817073
94
py
espnet
espnet-master/tools/check_install.py
#!/usr/bin/env python3 """Script to check whether the installation is done correctly.""" # Copyright 2018 Nagoya University (Tomoki Hayashi) # Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0) import importlib import re import shutil import subprocess import sys from pathlib import Path from packaging.versi...
6,394
31.29798
83
py
espnet
espnet-master/test/test_e2e_compatibility.py
#!/usr/bin/env python3 # coding: utf-8 # Copyright 2019 Tomoki Hayashi # Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0) from __future__ import print_function import importlib import os import re import shutil import subprocess import tempfile from os.path import join import chainer import numpy as np imp...
3,521
30.72973
111
py
espnet
espnet-master/test/test_e2e_asr_conformer.py
import argparse import pytest import torch from espnet.nets.pytorch_backend.e2e_asr_conformer import E2E from espnet.nets.pytorch_backend.transformer import plot def make_arg(**kwargs): defaults = dict( adim=2, aheads=1, dropout_rate=0.0, transformer_attn_dropout_rate=None, ...
4,895
25.901099
83
py
espnet
espnet-master/test/test_custom_transducer.py
# coding: utf-8 import argparse import json import tempfile import pytest import torch from packaging.version import parse as V import espnet.lm.pytorch_backend.extlm as extlm_pytorch import espnet.nets.pytorch_backend.lm.default as lm_pytorch from espnet.asr.pytorch_backend.asr_init import load_trained_model from e...
21,623
30.33913
87
py
espnet
espnet-master/test/test_batch_beam_search.py
import os from argparse import Namespace from test.test_beam_search import prepare, transformer_args import numpy import pytest import torch from espnet.nets.batch_beam_search import BatchBeamSearch, BeamSearch from espnet.nets.beam_search import Hypothesis from espnet.nets.lm_interface import dynamic_import_lm from ...
5,863
30.026455
88
py
espnet
espnet-master/test/test_e2e_mt.py
# coding: utf-8 # Copyright 2019 Hirofumi Inaguma # Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0) from __future__ import division import argparse import importlib import os import tempfile from test.utils_test import make_dummy_json_mt import chainer import numpy as np import pytest import torch from e...
12,854
31.298995
88
py
espnet
espnet-master/test/test_multi_spkrs.py
# coding: utf-8 # Copyright 2018 Hiroshi Seki # Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0) import argparse import importlib import re import numpy import pytest import torch def make_arg(**kwargs): defaults = dict( aconv_chans=2, aconv_filts=20, adim=20, aheads=4,...
7,289
28.51417
86
py
espnet
espnet-master/test/test_positional_encoding.py
import pytest import torch from espnet.nets.pytorch_backend.transformer.embedding import ( LearnableFourierPosEnc, PositionalEncoding, ScaledPositionalEncoding, ) @pytest.mark.parametrize( "dtype, device", [(dt, dv) for dt in ("float32", "float64") for dv in ("cpu", "cuda")], ) def test_pe_extend...
5,074
30.32716
87
py
espnet
espnet-master/test/test_asr_init.py
# coding: utf-8 import argparse import json import os import tempfile import numpy as np import pytest import torch import espnet.nets.pytorch_backend.lm.default as lm_pytorch from espnet.asr.asr_utils import torch_save from espnet.asr.pytorch_backend.asr_init import freeze_modules, load_trained_modules from espnet....
7,583
25.989324
84
py
espnet
espnet-master/test/test_e2e_mt_transformer.py
# coding: utf-8 # Copyright 2019 Hirofumi Inaguma # Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0) import argparse import pytest import torch from espnet.nets.pytorch_backend.e2e_mt_transformer import E2E from espnet.nets.pytorch_backend.transformer import plot def make_arg(**kwargs): defaults = di...
3,754
26.014388
83
py
espnet
espnet-master/test/test_e2e_asr_transformer.py
import argparse import chainer import numpy import pytest import torch import espnet.nets.chainer_backend.e2e_asr_transformer as ch import espnet.nets.pytorch_backend.e2e_asr_transformer as th from espnet.nets.pytorch_backend.nets_utils import rename_state_dict from espnet.nets.pytorch_backend.transformer import plot...
8,385
29.717949
87
py
espnet
espnet-master/test/test_beam_search_timesync.py
from argparse import Namespace import pytest import torch from espnet.nets.asr_interface import dynamic_import_asr from espnet.nets.beam_search_timesync import BeamSearchTimeSync from espnet.nets.lm_interface import dynamic_import_lm from espnet.nets.scorers.length_bonus import LengthBonus rnn_args = Namespace( ...
5,619
26.149758
88
py
espnet
espnet-master/test/test_e2e_tts_transformer.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright 2019 Tomoki Hayashi # Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0) from argparse import Namespace import numpy as np import pytest import torch from espnet.nets.pytorch_backend.e2e_tts_transformer import Transformer, subsequent_mask from espnet...
15,609
32.354701
88
py
espnet
espnet-master/test/test_asr_interface.py
import pytest from espnet.nets.asr_interface import dynamic_import_asr @pytest.mark.parametrize( "name, backend", [(nn, backend) for nn in ("transformer", "rnn") for backend in ("pytorch",)], ) def test_asr_build(name, backend): model = dynamic_import_asr(name, backend).build( 10, 10, mtlalpha=0....
415
26.733333
81
py
espnet
espnet-master/test/test_e2e_asr.py
# coding: utf-8 # Copyright 2017 Shigeki Karita # Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0) from __future__ import division import argparse import importlib import os import tempfile from test.utils_test import make_dummy_json import chainer import numpy as np import pytest import torch import espn...
26,215
34.331536
88
py
espnet
espnet-master/test/test_asr_quantize.py
# Copyright 2021 Gaopeng Xu # Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0) import pytest import torch from espnet.nets.asr_interface import dynamic_import_asr @pytest.mark.parametrize( "name, backend", [(nn, backend) for nn in ("transformer", "rnn") for backend in ("pytorch",)], ) def test_asr_...
642
28.227273
81
py
espnet
espnet-master/test/test_optimizer.py
# coding: utf-8 # Copyright 2017 Shigeki Karita # Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0) import chainer import numpy import pytest import torch from espnet.optimizer.factory import dynamic_import_optimizer from espnet.optimizer.pytorch import OPTIMIZER_FACTORY_DICT class ChModel(chainer.Chain): ...
3,023
29.857143
83
py
espnet
espnet-master/test/test_loss.py
# Copyright 2017 Shigeki Karita # Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0) import chainer.functions as F import numpy import pytest import torch from espnet.nets.pytorch_backend.e2e_asr import pad_list from espnet.nets.pytorch_backend.nets_utils import th_accuracy @pytest.mark.parametrize("ctc_type"...
5,405
35.527027
86
py
espnet
espnet-master/test/test_beam_search.py
from argparse import Namespace import numpy import pytest import torch from espnet.nets.asr_interface import dynamic_import_asr from espnet.nets.beam_search import BeamSearch from espnet.nets.lm_interface import dynamic_import_lm from espnet.nets.scorers.length_bonus import LengthBonus rnn_args = Namespace( elay...
6,366
27.55157
88
py
espnet
espnet-master/test/test_lm.py
from test.test_beam_search import prepare, rnn_args import chainer import numpy import pytest import torch import espnet.lm.chainer_backend.lm as lm_chainer import espnet.nets.pytorch_backend.lm.default as lm_pytorch from espnet.nets.beam_search import beam_search from espnet.nets.lm_interface import dynamic_import_l...
6,647
33.268041
88
py
espnet
espnet-master/test/test_e2e_tts_fastspeech.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright 2019 Tomoki Hayashi # Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0) import json import os import shutil import tempfile from argparse import Namespace import numpy as np import pytest import torch from espnet.nets.pytorch_backend.e2e_tts_fastspe...
21,140
32.398104
87
py
espnet
espnet-master/test/test_distributed_launch.py
# coding: utf-8 # # SPDX-FileCopyrightText: # Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 # import argparse import itertools import os import sys from multiprocessing import Queue import pytest from espnet.distributed.pytorch_backend.launch import...
4,110
26.225166
76
py
espnet
espnet-master/test/test_e2e_st_transformer.py
# coding: utf-8 # Copyright 2019 Hirofumi Inaguma # Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0) import argparse import pytest import torch from espnet.nets.pytorch_backend.e2e_st_transformer import E2E from espnet.nets.pytorch_backend.transformer import plot def make_arg(**kwargs): defaults = dic...
5,352
28.738889
85
py
espnet
espnet-master/test/test_torch.py
# Copyright 2017 Shigeki Karita # Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0) import torch from espnet.nets.pytorch_backend.nets_utils import pad_list def test_pad_list(): xs = [[1, 2, 3], [1, 2], [1, 2, 3, 4]] xs = list(map(lambda x: torch.LongTensor(x), xs)) xpad = pad_list(xs, -1) e...
852
26.516129
74
py
espnet
espnet-master/test/test_initialization.py
# Copyright 2017 Shigeki Karita # Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0) import argparse import os import random import numpy import torch args = argparse.Namespace( elayers=4, subsample="1_2_2_1_1", etype="vggblstmp", eunits=320, eprojs=320, dtype="lstm", dlayers=2, ...
3,380
28.4
72
py
espnet
espnet-master/test/test_e2e_st.py
# coding: utf-8 # Copyright 2019 Hirofumi Inaguma # Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0) from __future__ import division import argparse import importlib import os import tempfile from test.utils_test import make_dummy_json_st import chainer import numpy as np import pytest import torch from e...
20,465
33.629442
88
py
espnet
espnet-master/test/test_e2e_asr_maskctc.py
import argparse import pytest import torch from espnet.nets.pytorch_backend.e2e_asr_maskctc import E2E from espnet.nets.pytorch_backend.maskctc.add_mask_token import mask_uniform from espnet.nets.pytorch_backend.transformer import plot def make_arg(**kwargs): defaults = dict( adim=2, aheads=2, ...
3,708
27.530769
83
py
espnet
espnet-master/test/test_e2e_asr_transducer.py
# coding: utf-8 import argparse import json import tempfile import numpy as np import pytest import torch from packaging.version import parse as V import espnet.lm.pytorch_backend.extlm as extlm_pytorch import espnet.nets.pytorch_backend.lm.default as lm_pytorch from espnet.asr.pytorch_backend.asr_init import load_t...
14,894
28.849699
88
py
espnet
espnet-master/test/test_e2e_vc_transformer.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright 2020 Wen-Chin Huang # Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0) from argparse import Namespace from math import floor import numpy as np import pytest import torch from espnet.nets.pytorch_backend.e2e_vc_transformer import Transformer, subse...
16,029
32.676471
88
py
espnet
espnet-master/test/test_e2e_asr_mulenc.py
# coding: utf-8 # Copyright 2019 Ruizhi Li # Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0) from __future__ import division import argparse import importlib import os import tempfile from test.utils_test import make_dummy_json import numpy as np import pytest import torch from espnet.nets.pytorch_backen...
21,844
35.408333
88
py
espnet
espnet-master/test/test_e2e_vc_tacotron2.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright 2020 Wen-Chin Huang # Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0) from __future__ import division, print_function from argparse import Namespace import numpy as np import pytest import torch from espnet.nets.pytorch_backend.e2e_vc_tacotron2 i...
8,638
27.417763
88
py
espnet
espnet-master/test/test_e2e_tts_tacotron2.py
#!/usr/bin/env python3 # Copyright 2019 Tomoki Hayashi # Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0) from __future__ import division, print_function from argparse import Namespace import numpy as np import pytest import torch from espnet.nets.pytorch_backend.e2e_tts_tacotron2 import Tacotron2 from es...
8,798
27.661238
88
py
espnet
espnet-master/test/test_train_dtype.py
import pytest import torch from espnet.nets.asr_interface import dynamic_import_asr @pytest.mark.parametrize( "dtype, device, model, conf", [ (dtype, device, nn, conf) for nn, conf in [ ( "transformer", dict(adim=4, eunits=3, dunits=3, elayers=2, dl...
2,795
28.125
85
py
espnet
espnet-master/test/test_transformer_decode.py
import numpy import pytest import torch from espnet.nets.pytorch_backend.transformer.decoder import Decoder from espnet.nets.pytorch_backend.transformer.encoder import Encoder from espnet.nets.pytorch_backend.transformer.mask import subsequent_mask RTOL = 1e-4 @pytest.mark.parametrize("normalize_before", [True, Fal...
4,486
30.159722
85
py
espnet
espnet-master/test/test_recog.py
# coding: utf-8 # Copyright 2018 Hiroshi Seki # Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0) import argparse import numpy import pytest import torch import espnet.lm.pytorch_backend.extlm as extlm_pytorch import espnet.nets.pytorch_backend.lm.default as lm_pytorch from espnet.nets.pytorch_backend impor...
4,644
28.967742
87
py