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
unified-generative-zoo
unified-generative-zoo-main/model/lib/stylenerf/training/dataset.py
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # 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 ...
10,285
36.268116
158
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/stylenerf/training/networks.py
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # 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 ...
74,128
46.488149
168
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/stylenerf/training/facial_recognition/model_irse.py
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved from torch.nn import Linear, Conv2d, BatchNorm1d, BatchNorm2d, PReLU, Dropout, Sequential, Module from training.facial_recognition.helpers import get_blocks, Flatten, bottleneck_IR, bottleneck_IR_SE, l2_norm """ Modified Backbone implementation fr...
2,920
32.574713
109
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/stylenerf/training/facial_recognition/helpers.py
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved from collections import namedtuple import torch from torch.nn import Conv2d, BatchNorm2d, PReLU, ReLU, Sigmoid, MaxPool2d, AdaptiveAvgPool2d, Sequential, Module """ ArcFace implementation from [TreB1eN](https://github.com/TreB1eN/InsightFace_Pytor...
3,628
28.745902
112
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/stylenerf/torch_utils/custom_ops.py
# Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. 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 sof...
6,666
41.196203
146
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/stylenerf/torch_utils/training_stats.py
# Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. 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 sof...
10,720
38.855019
118
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/stylenerf/torch_utils/persistence.py
# Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. 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 sof...
9,752
37.702381
144
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/stylenerf/torch_utils/misc.py
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. 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 t...
12,213
39.177632
133
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/stylenerf/torch_utils/distributed_utils.py
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import logging import os import pickle import random import socket import struct import subprocess import warnings import tempfile import uuid from datetime import date from pathlib import Path from collections import OrderedDict from typing impo...
6,869
31.102804
107
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/stylenerf/torch_utils/ops/hash_sample.py
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # Please refer to original code: https://github.com/NVlabs/instant-ngp # and the pytorch wrapper from https://github.com/ashawkey/torch-ngp import os import torch from .. import custom_ops from torch.cuda.amp import custom_bwd, custom_fwd _plugi...
4,112
34.456897
162
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/stylenerf/torch_utils/ops/bias_act.py
# Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. 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 sof...
9,813
45.733333
185
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/stylenerf/torch_utils/ops/grid_sample_gradfix.py
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. 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 ...
3,245
37.642857
132
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/stylenerf/torch_utils/ops/conv2d_gradfix.py
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. 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 t...
9,537
46.452736
197
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/stylenerf/torch_utils/ops/upfirdn2d.py
# Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. 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 sof...
16,400
41.053846
120
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/stylenerf/torch_utils/ops/filtered_lrelu.py
# Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. 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 sof...
12,884
45.854545
164
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/stylenerf/torch_utils/ops/conv2d_resample.py
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. 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 t...
6,837
45.835616
130
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/stylenerf/torch_utils/ops/nerf_utils.py
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import os import torch from .. import custom_ops _plugin = None def _init(): global _plugin if _plugin is None: _plugin = custom_ops.get_plugin( module_name='nerf_utils_plugin', sources=['nerf_utils.cu'],...
1,007
25.526316
97
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/stylenerf/torch_utils/ops/fma.py
# Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. 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 sof...
2,047
32.57377
105
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/stylenerf/viz/renderer.py
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. 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 t...
17,215
39.508235
164
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/stylenerf/dnnlib/camera.py
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import numpy as np from numpy.lib.function_base import angle import torch import torch.nn.functional as F import math from scipy.spatial.transform import Rotation as Rot HUGE_NUMBER = 1e10 TINY_NUMBER = 1e-6 # float32 only has 7 decimal digi...
25,027
35.377907
140
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/stylenerf/dnnlib/util.py
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # 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 ...
18,031
32.958569
151
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/stylenerf/dnnlib/geometry.py
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import torch import torch.nn.functional as F import math import random import numpy as np def positional_encoding(p, size, pe='normal', use_pos=False): if pe == 'gauss': p_transformed = np.pi * p @ size p_transformed = torch....
16,292
39.031941
163
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/stylenerf/dnnlib/filters.py
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import math import torch from torch import nn from torch.nn import functional as F def kaiser_attenuation(n_taps, f_h, sr): df = (2 * f_h) / (sr / 2) return 2.285 * (n_taps - 1) * math.pi * df + 7.95 def kaiser_beta(n_taps, f_h, sr): ...
1,946
22.743902
87
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/tools/inception.py
import torch import torch.nn as nn import torch.nn.functional as F import torchvision try: from torchvision.models.utils import load_state_dict_from_url except ImportError: from torch.utils.model_zoo import load_url as load_state_dict_from_url # Inception weights ported to Pytorch from # http://download.tenso...
12,193
36.06383
140
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/tools/fid_score.py
"""Calculates the Frechet Inception Distance (FID) to evalulate GANs The FID metric calculates the distance between two distributions of images. Typically, we have summary statistics (mean & covariance matrix) of one of these distributions, while the 2nd distribution is given by a GAN. When run as a stand-alone progr...
9,538
35.547893
98
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/core/criterions/base.py
import core.utils.managers as managers from core.utils import global_device, diagnose import torch class Criterion(object): def __init__(self, wrapper, models: managers.ModelsManager, optimizers: managers.OptimizersManager, lr_schedulers: manager...
1,996
31.737705
93
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/core/criterions/ddpm.py
__all__ = ["DTDSM", "DTDSDM", "DTDSDMErr", "CTDSDM", "CTDSDMErr", "CTDSM"] import torch from .base import NaiveCriterion import core.func as func import logging def dt_dsm(x0, wrapper, schedule): n, eps, xn = schedule.sample(x0) eps_pred = wrapper(xn, n) return func.sos(eps - eps_pred) def dt_dsdm(x0,...
5,444
36.040816
118
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/core/func/functions.py
import numpy as np import torch.nn.functional as F import torch import math def bipartition(ts): if ts.dim() == 4: # bs * 2c * w * w assert ts.size(1) % 2 == 0 c = ts.size(1) // 2 return ts.split(c, dim=1) else: raise NotImplementedError def stp(s, ts: torch.Tensor): # scal...
3,977
28.466667
105
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/core/func/differential.py
__all__ = ["RequiresGradContext", "differential"] import torch import torch.nn as nn import torch.autograd as autograd from typing import Union, List def judge_requires_grad(obj: Union[torch.Tensor, nn.Module]): if isinstance(obj, torch.Tensor): return obj.requires_grad elif isinstance(obj, nn.Modu...
1,741
31.867925
102
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/core/diffusion/likelihood.py
import core.func as func import torch from .trajectory import _choice_steps import logging from .dtdpm import DDPM from .utils import report_statistics import numpy as np from core.evaluate.score import score_on_dataset from .sde import ReverseSDE, ODE from scipy import integrate @ torch.no_grad() def nelbo_dtdpm(dtd...
6,853
38.165714
111
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/core/diffusion/sample.py
import torch import logging import math import numpy as np import core.func as func from .dtdpm import DTDPM from .sde import ReverseSDE, ODE from .utils import report_statistics from .trajectory import _choice_steps @ torch.no_grad() def sample_dtdpm(dtdpm, x_init, rev_var_type, trajectory='linear', sample_steps=Non...
2,908
40.557143
131
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/core/diffusion/wrapper.py
__all__ = ["DTWrapper", "DTCTWrapper", "CTWrapper", "SplitDTWrapper"] import numpy as np import torch import torch.nn as nn import logging from core.utils.compatible import Wrapper import core.func as func def _rescale_timesteps(n, N, flag): if flag: return n * 1000.0 / float(N) return n class DTWr...
4,167
33.163934
111
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/core/diffusion/dtdpm.py
__all__ = ["DTDPM", "DDPM", "DDIM"] import numpy as np import logging import core.func as func from core.utils import global_device import torch class DTDPM(object): # diffusion with discrete timesteps r""" E[xs|xt] = E[ E[xs|xt,x0] |xt] = E[xs|xt,x0=E[x0|xt]] in DDPM or DDIM forward process """ ...
9,619
43.331797
139
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/core/diffusion/schedule.py
import numpy as np import math import torch import core.func as func def get_skip(alphas, betas): N = len(betas) - 1 skip_alphas = np.ones([N + 1, N + 1], dtype=betas.dtype) for s in range(N + 1): skip_alphas[s, s + 1:] = alphas[s + 1:].cumprod() skip_betas = np.zeros([N + 1, N + 1], dtype=bet...
4,543
37.184874
94
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/core/diffusion/sde.py
import torch import numpy as np import math import core.func as func from .schedule import Schedule class SDE(object): r""" dx = f(x, t)dt + g(t) dw with 0 <= t <= 1 f(x, t) is the drift g(t) is the diffusion """ def drift(self, x, t): raise NotImplementedError def dif...
4,501
29.214765
93
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/core/evaluate/score.py
__all__ = ["score_on_dataset", "cat_score_on_dataset"] import torch from torch.utils.data import DataLoader, Dataset def score_on_dataset(dataset: Dataset, score_fn, batch_size): r""" Args: dataset: an instance of Dataset score_fn: a batch of data -> a batch of scalars batch_size: th...
1,525
32.911111
98
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/core/evaluate/sample.py
__all__ = ["grid_sample", "sample2dir"] import os import torch from torchvision.utils import make_grid, save_image from core.utils import amortize def grid_sample(fname, nrow, ncol, sample_fn, unpreprocess_fn=None): r""" Sample images in a grid Args: fname: the file name nrow: the number of ...
1,530
33.022222
94
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/core/utils/clip_grad.py
__all__ = ["clip_grad_norm_", "clip_grad_element_wise_"] import torch from typing import List, Union import math def clip_grad_norm_(grads: Union[torch.Tensor, List[torch.Tensor]], max_norm: float, norm_type: float = 2.): if isinstance(grads, torch.Tensor): grads = [grads] max_norm = float(max_norm...
1,056
29.2
108
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/core/utils/compatible.py
__all__ = ["Wrapper"] import torch.nn as nn class Wrapper(object): def __init__(self, model: [nn.Module, None]): self.model_ = model self.model = None if model is None else nn.DataParallel(model) def __call__(self, *args, **kwargs): raise NotImplementedError
294
23.583333
70
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/core/utils/managers.py
r""" Sometimes, we need manage multiple pytorch objects in a script, e.g., multiple models, multiple optimizers Manager provide a interface to manage them together """ import torch.nn as nn import torch.optim as optim from .ema import ema import logging from core.utils.compatible import Wrapper class Manager(obje...
4,808
29.630573
111
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/core/utils/diagnose.py
import torch.nn as nn from typing import Union, Iterator import torch from .device_utils import device_of, global_device def grad_norm_inf(inputs: Union[nn.Module, Iterator[torch.Tensor]]) -> float: if isinstance(inputs, nn.Module): inputs = inputs.parameters() s = float("-inf") for p in inputs: ...
1,796
32.90566
119
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/core/utils/device_utils.py
__all__ = ["device_of", "global_device"] import torch.nn as nn import torch from typing import Union from .managers import ModelsManager def device_of(inputs: Union[nn.Module, torch.Tensor, ModelsManager]) -> torch.device: if isinstance(inputs, nn.Module): return next(inputs.parameters()).device el...
643
25.833333
85
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/core/utils/ema.py
import torch.nn as nn def ema(model_dest: nn.Module, model_src: nn.Module, rate): param_dict_src = dict(model_src.named_parameters()) for p_name, p_dest in model_dest.named_parameters(): p_src = param_dict_src[p_name] assert p_src is not p_dest p_dest.data.mul_(rate).add_((1 - rate) * ...
332
32.3
60
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/interface/datasets/dataset_factory.py
from .utils import is_labelled, UnlabeledDataset from torch.utils.data import ConcatDataset import numpy as np class DatasetFactory(object): r""" Output dataset after two transformations to the raw data: 1. distribution transform (e.g. binarized, adding noise), often irreversible, a part of which is implement...
3,059
30.546392
112
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/interface/datasets/imagenet64.py
from PIL import Image import os import torchvision.transforms as transforms from .dataset_factory import DatasetFactory from .utils import * class ImageDataset(Dataset): def __init__(self, path): super().__init__() names = os.listdir(path) self.local_images = [os.path.join(path, name) for ...
1,569
26.068966
85
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/interface/datasets/lsun_bedroom.py
import torchvision.transforms as transforms from .dataset_factory import DatasetFactory from .lsun.lsun import LSUN from .utils import * import os class LSUNBedroom(DatasetFactory): def __init__(self, data_path): super().__init__() _transform = transforms.Compose([transforms.Resize(256), transform...
1,192
33.085714
116
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/interface/datasets/utils.py
import torch from torch.utils.data import Dataset import torchvision.transforms.functional as F def pad22pow(a): assert a % 2 == 0 bits = a.bit_length() ub = 2 ** bits pad = (ub - a) // 2 return pad, ub def is_labelled(dataset): labelled = False if isinstance(dataset[0], tuple) and len(d...
2,402
22.330097
82
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/interface/datasets/cifar10.py
from torch.utils.data import Subset from torchvision import datasets import torchvision.transforms as transforms from .dataset_factory import DatasetFactory from .utils import * class CIFAR10(DatasetFactory): r""" CIFAR10 dataset Information of the raw dataset: train: 40,000 val: 10,000 ...
1,658
31.529412
111
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/interface/datasets/celeba.py
from torchvision.datasets.utils import verify_str_arg import torchvision.transforms as transforms from .dataset_factory import DatasetFactory from .utils import * import numpy as np from collections import namedtuple import csv from functools import partial import PIL import os import torch import torch.utils.data as d...
15,119
38.477807
121
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/interface/datasets/mnist.py
from torch.utils.data import Subset from torchvision import datasets import torchvision.transforms as transforms from .dataset_factory import DatasetFactory from .utils import * class Mnist(DatasetFactory): r""" Mnist dataset Information of the raw dataset: train: 50,000 val: 10,000 ...
3,257
35.2
109
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/interface/datasets/lsun/lsun.py
from .vision import VisionDataset from PIL import Image import os import os.path import io from collections.abc import Iterable import pickle import torch def iterable_to_str(iterable: Iterable) -> str: return "'" + "', '".join([str(item) for item in iterable]) + "'" def verify_str_arg( value, arg=None, val...
6,426
30.048309
90
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/interface/datasets/lsun/vision.py
import os import torch import torch.utils.data as data class VisionDataset(data.Dataset): _repr_indent = 4 def __init__(self, root, transforms=None, transform=None, target_transform=None): if isinstance(root, torch._six.string_classes): root = os.path.expanduser(root) self.root = ...
3,266
37.435294
86
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/interface/evaluators/dtdpm_evaluator.py
import os from core.evaluate import grid_sample, sample2dir from .base import Evaluator from core.diffusion.sample import sample_dtdpm from core.diffusion.dtdpm import DDPM, DDIM, DTDPM from core.diffusion.likelihood import nelbo_dtdpm, get_nelbo_terms from core.evaluate.score import score_on_dataset, cat_score_on_data...
7,964
45.578947
154
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/interface/evaluators/utils.py
import torch def linear_interpolate(a, b, steps): a_shape = a.shape a = a.detach().cpu().view(-1) b = b.detach().cpu().view(-1) res = [] for aa, bb in zip(a, b): res.append(torch.linspace(aa, bb, steps=steps).unsqueeze(dim=1)) res = torch.cat(res, dim=1) res = res.view(len(res), *a...
658
23.407407
72
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/interface/evaluators/sde_evaluator.py
import os from core.evaluate import grid_sample, sample2dir from .base import Evaluator from core.diffusion.sample import euler_maruyama from core.diffusion.likelihood import ode_nll from core.diffusion.sde import ReverseSDE, ODE from core.evaluate.score import score_on_dataset, cat_score_on_dataset from core.diffusion...
5,096
44.508929
123
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/interface/runner/fit.py
from torch.utils.data import DataLoader from interface.utils.ckpt import CKPT import os import logging import math from core.utils.managers import ModelsManager def infinite_loader(dataset, batch_size): loader = DataLoader(dataset, batch_size=batch_size, shuffle=True) while True: for data in loader: ...
3,385
37.044944
129
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/interface/utils/reproducibility.py
__all__ = ['set_seed', 'set_deterministic', 'backup_codes', 'backup_config'] import torch import numpy as np import os import shutil import pprint def set_seed(seed: int): if seed is not None: torch.manual_seed(seed) np.random.seed(seed) def set_deterministic(flag: bool): if flag: ...
1,317
27.652174
84
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/interface/utils/config_utils.py
import core.utils.managers as managers import torch.optim as optim from .interact import Interact from core.evaluate import score_on_dataset import functools import torch import logging def create_instance(config): kwargs = config.get("kwargs", {}) return config.cls(**kwargs) ###############################...
6,786
37.782857
102
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/interface/utils/interact.py
import os import logging from torch.utils.tensorboard import SummaryWriter import socket def set_logger(fname): logger = logging.getLogger() logger.setLevel(level=logging.INFO) handler1 = logging.StreamHandler() handler2 = logging.FileHandler(fname, mode='w') formatter = logging.Formatter('%(ascti...
1,988
34.517857
99
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/interface/utils/ckpt.py
import torch import os import core.utils.managers as managers import logging def load_from_dir(path: str): dct = {} files = os.listdir(path) for file in files: p = os.path.join(path, file) if file.endswith("pth"): key = os.path.splitext(file)[0] dct[key] = torch.loa...
4,016
32.198347
122
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/configs/default.py
import ml_collections import interface.datasets as datasets import torch.optim as optim import os import datetime import core.criterions as criterions import interface.evaluators as evaluators import core.diffusion.wrapper as wrapper from torch.optim.lr_scheduler import LambdaLR ######################################...
12,962
34.225543
95
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/libs/ddpm/customized.py
import logging import torch from .model import Model, ResnetBlock, Normalize, get_timestep_embedding, nonlinearity class Model4Pretrained(Model): def __init__(self, head_out_ch, mode="simple", **kwargs): super().__init__(**kwargs) self.requires_grad_(False) self.mode = mode logging...
2,713
37.771429
86
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/libs/ddpm/model.py
import math import torch import torch.nn as nn def get_timestep_embedding(timesteps, embedding_dim): """ This matches the implementation in Denoising Diffusion Probabilistic Models: From Fairseq. Build sinusoidal embeddings. This matches the implementation in tensor2tensor, but differs slightly ...
12,381
36.295181
93
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/libs/ddpm/__init__.py
# codes from https://github.com/pesser/pytorch_diffusion from .model import Model from .customized import Model4Pretrained
124
24
56
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/libs/score_sde/customized.py
# the code added by us from .models import utils, layers, layerspp, normalization import torch.nn as nn import functools import torch import numpy as np from .models.ncsnpp import NCSNpp ResnetBlockDDPM = layerspp.ResnetBlockDDPMpp ResnetBlockBigGAN = layerspp.ResnetBlockBigGANpp Combine = layerspp.Combine conv3x3 = ...
15,107
32.648107
113
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/libs/score_sde/__init__.py
# codes from https://github.com/yang-song/score_sde_pytorch from .customized import get_nscnpp_model
102
24.75
59
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/libs/score_sde/models/up_or_down_sampling.py
"""Layers used for up-sampling or down-sampling images. Many functions are ported from https://github.com/NVlabs/stylegan2. """ import torch.nn as nn import torch import torch.nn.functional as F import numpy as np from ..op import upfirdn2d # Function ported from StyleGAN2 def get_weight(module, shap...
8,902
33.507752
91
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/libs/score_sde/models/utils.py
# coding=utf-8 # Copyright 2020 The Google Research Authors. # # 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 applicab...
1,872
26.144928
105
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/libs/score_sde/models/layers.py
# coding=utf-8 # Copyright 2020 The Google Research Authors. # # 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 applicab...
22,687
33.271903
112
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/libs/score_sde/models/ddpm.py
# coding=utf-8 # Copyright 2020 The Google Research Authors. # # 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 applicab...
6,082
32.423077
113
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/libs/score_sde/models/ncsnv2.py
# coding=utf-8 # Copyright 2020 The Google Research Authors. # # 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 applicab...
16,043
37.567308
120
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/libs/score_sde/models/normalization.py
# coding=utf-8 # Copyright 2020 The Google Research Authors. # # 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 applicab...
7,657
34.453704
106
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/libs/score_sde/models/ema.py
# Modified from https://raw.githubusercontent.com/fadel/pytorch_ema/master/torch_ema/ema.py from __future__ import division from __future__ import unicode_literals import torch # Partially based on: https://github.com/tensorflow/tensorflow/blob/r1.13/tensorflow/python/training/moving_averages.py class ExponentialMo...
3,414
33.846939
119
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/libs/score_sde/models/ncsnpp.py
# coding=utf-8 # Copyright 2020 The Google Research Authors. # # 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 applicab...
13,653
34.743455
113
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/libs/score_sde/models/layerspp.py
# coding=utf-8 # Copyright 2020 The Google Research Authors. # # 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 applicab...
9,001
31.734545
99
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/libs/score_sde/op/upfirdn2d.py
import os import torch from torch.nn import functional as F from torch.autograd import Function from torch.utils.cpp_extension import load module_path = os.path.dirname(__file__) upfirdn2d_op = load( "upfirdn2d", sources=[ os.path.join(module_path, "upfirdn2d.cpp"), os.path.join(module_path, ...
5,672
27.223881
108
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/libs/score_sde/op/fused_act.py
import os import torch from torch import nn from torch.nn import functional as F from torch.autograd import Function from torch.utils.cpp_extension import load module_path = os.path.dirname(__file__) fused = load( "fused", sources=[ os.path.join(module_path, "fused_bias_act.cpp"), os.path.joi...
2,690
26.459184
83
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/libs/iddpm/customized.py
from .unet import UNetModel, TimestepEmbedSequential, ResBlock import logging import torch as th import torch.nn as nn from .nn import ( SiLU, conv_nd, zero_module, normalization, timestep_embedding, ) class UNetModel3OutChannels(UNetModel): def __init__(self, **kwargs): super().__init...
2,991
32.244444
107
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/libs/iddpm/nn.py
""" Various utilities for neural networks. """ import math import torch as th import torch.nn as nn # PyTorch 1.7 has SiLU, but we support PyTorch 1.5. class SiLU(nn.Module): def forward(self, x): return x * th.sigmoid(x) class GroupNorm32(nn.GroupNorm): def forward(self, x): return super(...
4,544
27.765823
88
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/libs/iddpm/fp16_util.py
""" Helpers to train with 16-bit precision. """ import torch.nn as nn from torch._utils import _flatten_dense_tensors, _unflatten_dense_tensors def convert_module_to_f16(l): """ Convert primitive modules to float16. """ if isinstance(l, (nn.Conv1d, nn.Conv2d, nn.Conv3d)): l.weight.data = l.we...
2,282
28.649351
114
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/extended_adpm/libs/iddpm/unet.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 .fp16_util import convert_module_to_f16, convert_module_to_f32 from .nn import ( SiLU, conv_nd, linear, avg_pool_nd, zero_module, normalization, time...
18,907
33.315789
124
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/stylesdf/losses.py
import math import torch from torch import autograd from torch.nn import functional as F def viewpoints_loss(viewpoint_pred, viewpoint_target): loss = F.smooth_l1_loss(viewpoint_pred, viewpoint_target) return loss def eikonal_loss(eikonal_term, sdf=None, beta=100): if eikonal_term == None: eiko...
1,786
27.822581
83
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/stylesdf/utils.py
import torch import random import trimesh import numpy as np from torch import nn from torch.nn import functional as F from torch.utils import data from scipy.spatial import Delaunay from skimage.measure import marching_cubes from pytorch3d.structures import Meshes from pytorch3d.renderer import ( look_at_view_tra...
11,382
36.444079
111
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/stylesdf/model.py
import math import random import torch import numpy as np from torch import nn from torch.nn import functional as F from .volume_renderer import VolumeFeatureRenderer from .op import FusedLeakyReLU, fused_leaky_relu, upfirdn2d from .utils import ( create_cameras, add_textures, create_depth_mesh_renderer, )...
33,662
32.06778
152
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/stylesdf/generate_shapes_and_images.py
import os import torch import numpy as np from munch import * from tqdm import tqdm from torchvision import utils from .options import BaseOptions from .model import Generator from .utils import ( generate_camera_params, align_volume, extract_mesh_with_marching_cubes, xyz2mesh, ) def generate(opt, g_e...
11,520
47.817797
177
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/stylesdf/volume_renderer.py
import torch import torch.nn as nn import torch.nn.functional as F import torch.autograd as autograd import numpy as np # Basic SIREN fully connected layer class LinearLayer(nn.Module): def __init__(self, in_dim, out_dim, bias=True, bias_init=0, std_init=1, freq_init=False, is_first=False): super().__init...
15,063
41.196078
153
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/stylesdf/op/upfirdn2d.py
import os import torch from torch.nn import functional as F from torch.autograd import Function from torch.utils.cpp_extension import load from pdb import set_trace as st module_path = os.path.dirname(__file__) upfirdn2d_op = load( "upfirdn2d", sources=[ os.path.join(module_path, "upfirdn2d.cpp"), ...
5,704
27.242574
108
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/stylesdf/op/fused_act.py
import os import torch from torch import nn from torch.nn import functional as F from torch.autograd import Function from torch.utils.cpp_extension import load module_path = os.path.dirname(__file__) fused = load( "fused", sources=[ os.path.join(module_path, "fused_bias_act.cpp"), os.path.joi...
3,143
25.2
86
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/diffusion_stylegan/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,577
50.325077
154
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/diffusion_stylegan/training/diffusion.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,703
37.328358
102
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/diffusion_stylegan/training/adaaug.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...
27,527
60.173333
366
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/diffusion_stylegan/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...
37,595
50.081522
164
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/diffusion_stylegan/training/diffaug.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 class DiffAugment(torch.nn.Module): def __init__(self, policy='color,translation,cutout', channels_first=True...
3,586
37.569892
110
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/diffusion_stylegan/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
unified-generative-zoo
unified-generative-zoo-main/model/lib/diffusion_stylegan/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
unified-generative-zoo
unified-generative-zoo-main/model/lib/diffusion_stylegan/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
unified-generative-zoo
unified-generative-zoo-main/model/lib/diffusion_stylegan/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...
11,089
40.535581
133
py
unified-generative-zoo
unified-generative-zoo-main/model/lib/diffusion_stylegan/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
unified-generative-zoo
unified-generative-zoo-main/model/lib/diffusion_stylegan/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
unified-generative-zoo
unified-generative-zoo-main/model/lib/diffusion_stylegan/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