repo stringlengths 7 90 | file_url stringlengths 81 315 | file_path stringlengths 4 228 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 14:38:15 2026-01-05 02:33:18 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
xiaomoguhz/DeCLIP | https://github.com/xiaomoguhz/DeCLIP/blob/ed89f59c4d5939de0048e3622e6927274a63bcf7/src/training/train.py | src/training/train.py | import json
import logging
import math
import time
import torch
from training.misc import is_main_process
from open_clip import get_cast_dtype
from .distributed import is_master
from .zero_shot import multi_gpu_sync, zero_shot_eval
from .precision import get_autocast
import os
class AverageMeter(object):
"""Comput... | python | Apache-2.0 | ed89f59c4d5939de0048e3622e6927274a63bcf7 | 2026-01-05T07:08:37.834068Z | false |
xiaomoguhz/DeCLIP | https://github.com/xiaomoguhz/DeCLIP/blob/ed89f59c4d5939de0048e3622e6927274a63bcf7/src/training/file_utils.py | src/training/file_utils.py | import logging
import os
import multiprocessing
import subprocess
import time
import fsspec
import torch
from tqdm import tqdm
def remote_sync_s3(local_dir, remote_dir):
# skip epoch_latest which can change during sync.
result = subprocess.run(["aws", "s3", "sync", local_dir, remote_dir, '--exclude', '*epoch_l... | python | Apache-2.0 | ed89f59c4d5939de0048e3622e6927274a63bcf7 | 2026-01-05T07:08:37.834068Z | false |
xiaomoguhz/DeCLIP | https://github.com/xiaomoguhz/DeCLIP/blob/ed89f59c4d5939de0048e3622e6927274a63bcf7/src/training/declip.py | src/training/declip.py | import torch
import torch.nn.functional as F
from training.misc import is_main_process
import torch
class DeCLIP:
def __call__(self, batch, student, teacher, vfm_model, args):
losses={}
context_weight = args.loss_context_weight
content_weight = args.loss_content_weight
if args.dist... | python | Apache-2.0 | ed89f59c4d5939de0048e3622e6927274a63bcf7 | 2026-01-05T07:08:37.834068Z | false |
xiaomoguhz/DeCLIP | https://github.com/xiaomoguhz/DeCLIP/blob/ed89f59c4d5939de0048e3622e6927274a63bcf7/src/training/custom_transforms.py | src/training/custom_transforms.py | import random
import torch
import torch.nn as nn
import torchvision.transforms.functional as F
from torchvision.transforms import RandomCrop, InterpolationMode
class CustomRandomResize(nn.Module):
def __init__(self, scale=(0.5, 2.0), interpolation=InterpolationMode.BILINEAR):
super().__init__()
s... | python | Apache-2.0 | ed89f59c4d5939de0048e3622e6927274a63bcf7 | 2026-01-05T07:08:37.834068Z | false |
xiaomoguhz/DeCLIP | https://github.com/xiaomoguhz/DeCLIP/blob/ed89f59c4d5939de0048e3622e6927274a63bcf7/src/training/profile.py | src/training/profile.py | import argparse
import torch
import open_clip
import pandas as pd
from fvcore.nn import FlopCountAnalysis, flop_count_str, ActivationCountAnalysis
parser = argparse.ArgumentParser(description='OpenCLIP Profiler')
# benchmark specific args
parser.add_argument('--model', metavar='NAME', default='',
... | python | Apache-2.0 | ed89f59c4d5939de0048e3622e6927274a63bcf7 | 2026-01-05T07:08:37.834068Z | false |
xiaomoguhz/DeCLIP | https://github.com/xiaomoguhz/DeCLIP/blob/ed89f59c4d5939de0048e3622e6927274a63bcf7/src/training/coco_api.py | src/training/coco_api.py | # Copyright (c) OpenMMLab. All rights reserved.
# This file add snake case alias for coco api
import warnings
from collections import defaultdict
from typing import List, Optional, Union
import pycocotools
from pycocotools.coco import COCO as _COCO
from pycocotools.cocoeval import COCOeval as _COCOeval
class COCO(_... | python | Apache-2.0 | ed89f59c4d5939de0048e3622e6927274a63bcf7 | 2026-01-05T07:08:37.834068Z | false |
xiaomoguhz/DeCLIP | https://github.com/xiaomoguhz/DeCLIP/blob/ed89f59c4d5939de0048e3622e6927274a63bcf7/src/training/logger.py | src/training/logger.py | import logging
def setup_logging(log_file, level, include_host=False):
if include_host:
import socket
hostname = socket.gethostname()
formatter = logging.Formatter(
f'%(asctime)s | {hostname} | %(levelname)s | %(message)s', datefmt='%Y-%m-%d,%H:%M:%S')
else:
format... | python | Apache-2.0 | ed89f59c4d5939de0048e3622e6927274a63bcf7 | 2026-01-05T07:08:37.834068Z | false |
xiaomoguhz/DeCLIP | https://github.com/xiaomoguhz/DeCLIP/blob/ed89f59c4d5939de0048e3622e6927274a63bcf7/src/training/precision.py | src/training/precision.py | import torch
from contextlib import suppress
def get_autocast(precision):
if precision == 'amp':
return torch.cuda.amp.autocast
elif precision in ['bfloat16', 'bf16']:
return lambda: torch.cuda.amp.autocast(dtype=torch.bfloat16)
else:
return suppress | python | Apache-2.0 | ed89f59c4d5939de0048e3622e6927274a63bcf7 | 2026-01-05T07:08:37.834068Z | false |
xiaomoguhz/DeCLIP | https://github.com/xiaomoguhz/DeCLIP/blob/ed89f59c4d5939de0048e3622e6927274a63bcf7/src/training/dist_utils.py | src/training/dist_utils.py | # Copyright (c) Facebook, Inc. and its affiliates.
"""
This file contains primitives for multi-gpu communication.
This is useful when doing distributed training.
"""
import functools
import numpy as np
import torch
import torch.distributed as dist
_LOCAL_PROCESS_GROUP = None
_MISSING_LOCAL_PG_ERROR = (
"Local pro... | python | Apache-2.0 | ed89f59c4d5939de0048e3622e6927274a63bcf7 | 2026-01-05T07:08:37.834068Z | false |
xiaomoguhz/DeCLIP | https://github.com/xiaomoguhz/DeCLIP/blob/ed89f59c4d5939de0048e3622e6927274a63bcf7/src/training/main.py | src/training/main.py | import glob
import logging
import os
import re
import subprocess
import sys
import random
from datetime import datetime
from tools.k_means import run_kmeans
from tools.precompute_knns import run_knns
from tools.segmentation import run_seg
from training.misc import is_main_process
from training.declip import DeCLIP
impo... | python | Apache-2.0 | ed89f59c4d5939de0048e3622e6927274a63bcf7 | 2026-01-05T07:08:37.834068Z | false |
xiaomoguhz/DeCLIP | https://github.com/xiaomoguhz/DeCLIP/blob/ed89f59c4d5939de0048e3622e6927274a63bcf7/src/training/distributed.py | src/training/distributed.py | import os
import torch
import torch.distributed as dist
try:
import horovod.torch as hvd
except ImportError:
hvd = None
def is_global_master(args):
return args.rank == 0
def is_local_master(args):
return args.local_rank == 0
def is_master(args, local=False):
return is_local_master(args) if l... | python | Apache-2.0 | ed89f59c4d5939de0048e3622e6927274a63bcf7 | 2026-01-05T07:08:37.834068Z | false |
xiaomoguhz/DeCLIP | https://github.com/xiaomoguhz/DeCLIP/blob/ed89f59c4d5939de0048e3622e6927274a63bcf7/src/training/utils.py | src/training/utils.py |
import torch
import torch.nn.functional as F
import numpy as np
from contextlib import nullcontext
from src.segment_anything import sam_model_registry
def get_autocast(precision):
if precision == "bf16":
return lambda: torch.autocast("cuda", dtype=torch.bfloat16)
elif precision == "amp":
retu... | python | Apache-2.0 | ed89f59c4d5939de0048e3622e6927274a63bcf7 | 2026-01-05T07:08:37.834068Z | false |
xiaomoguhz/DeCLIP | https://github.com/xiaomoguhz/DeCLIP/blob/ed89f59c4d5939de0048e3622e6927274a63bcf7/src/training/misc.py | src/training/misc.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""
Misc functions, including distributed helpers.
Mostly copy-paste from torchvision references.
"""
import os
import random
import subprocess
import time
from collections import OrderedDict, defaultdict, deque
import datetime
import pickle
from ... | python | Apache-2.0 | ed89f59c4d5939de0048e3622e6927274a63bcf7 | 2026-01-05T07:08:37.834068Z | false |
xiaomoguhz/DeCLIP | https://github.com/xiaomoguhz/DeCLIP/blob/ed89f59c4d5939de0048e3622e6927274a63bcf7/src/training/__init__.py | src/training/__init__.py | python | Apache-2.0 | ed89f59c4d5939de0048e3622e6927274a63bcf7 | 2026-01-05T07:08:37.834068Z | false | |
xiaomoguhz/DeCLIP | https://github.com/xiaomoguhz/DeCLIP/blob/ed89f59c4d5939de0048e3622e6927274a63bcf7/src/training/zero_shot.py | src/training/zero_shot.py | import logging
import torch
import torch.nn.functional as F
from training.dist_utils import all_gather
from tqdm import tqdm
from .distributed import is_master
from open_clip import get_cast_dtype
from .precision import get_autocast
def run(model, dataloader, args):
cls_embeddings = dataloader.dataset.embeddings
... | python | Apache-2.0 | ed89f59c4d5939de0048e3622e6927274a63bcf7 | 2026-01-05T07:08:37.834068Z | false |
xiaomoguhz/DeCLIP | https://github.com/xiaomoguhz/DeCLIP/blob/ed89f59c4d5939de0048e3622e6927274a63bcf7/src/training/scheduler.py | src/training/scheduler.py | import numpy as np
def assign_learning_rate(optimizer, new_lr):
for param_group in optimizer.param_groups:
param_group["lr"] = new_lr
def _warmup_lr(base_lr, warmup_length, step):
return base_lr * (step + 1) / warmup_length
def const_lr(optimizer, base_lr, warmup_length, steps):
def _lr_adjust... | python | Apache-2.0 | ed89f59c4d5939de0048e3622e6927274a63bcf7 | 2026-01-05T07:08:37.834068Z | false |
xiaomoguhz/DeCLIP | https://github.com/xiaomoguhz/DeCLIP/blob/ed89f59c4d5939de0048e3622e6927274a63bcf7/src/training/data.py | src/training/data.py | import json
import logging
import os
import random
from dataclasses import dataclass
from multiprocessing import Value
from typing import List
import numpy as np
from training.misc import get_tokenizer
from training.utils import mask2box
import torch
from PIL import Image
from torch.utils.data import Dataset, DataLoade... | python | Apache-2.0 | ed89f59c4d5939de0048e3622e6927274a63bcf7 | 2026-01-05T07:08:37.834068Z | false |
xiaomoguhz/DeCLIP | https://github.com/xiaomoguhz/DeCLIP/blob/ed89f59c4d5939de0048e3622e6927274a63bcf7/src/training/region_clip.py | src/training/region_clip.py | import numpy as np
import torch
import torch.nn.functional as F
import torch.nn as nn
def get_fed_loss_inds(gt_classes, num_sample_cats, C):
appeared = torch.unique(gt_classes) # C'
prob = appeared.new_ones(C).float()
if len(appeared) < num_sample_cats:
prob[appeared] = 0
more_appeared = t... | python | Apache-2.0 | ed89f59c4d5939de0048e3622e6927274a63bcf7 | 2026-01-05T07:08:37.834068Z | false |
youfou/pianoteq-pi | https://github.com/youfou/pianoteq-pi/blob/b0519aaace427216d18af8d744bc1b4c74de1c08/setup.py | setup.py | #!/usr/bin/env python3
# coding: utf-8
import dbm
import os
import re
import stat
import subprocess
import sys
DEFAULT_INSTALL_LOCATION = '/home/pi/'
CONFIG_PATH = '/home/pi/.config/pianoteq-pi.dbm'
script_dir, script_filename = os.path.split(__file__)
def hl(text, style=1, margin=False):
# style: https://misc.... | python | Apache-2.0 | b0519aaace427216d18af8d744bc1b4c74de1c08 | 2026-01-05T07:08:48.222565Z | false |
justinlovelace/latent-diffusion-for-language | https://github.com/justinlovelace/latent-diffusion-for-language/blob/0bf9381e049ff288e5e79edc38e4a952a371bee2/train_text_diffusion.py | train_text_diffusion.py | import argparse
from utils import file_utils
from transformers import AutoConfig
import json
import os
import numpy as np
import torch
import CONSTANTS
from diffusion.text_denoising_diffusion import GaussianDiffusion, Trainer
from model.diffusion_transformer import DiffusionTransformer
ATTN_HEAD_DIM=64
def get_diffu... | python | MIT | 0bf9381e049ff288e5e79edc38e4a952a371bee2 | 2026-01-05T07:08:26.295297Z | false |
justinlovelace/latent-diffusion-for-language | https://github.com/justinlovelace/latent-diffusion-for-language/blob/0bf9381e049ff288e5e79edc38e4a952a371bee2/CONSTANTS.py | CONSTANTS.py | NUM_CLASSES = {'sst':2, 'ag_news':4}
CLASS_NAMES = {'sst':['negative', 'positive'], 'ag_news':['world', 'sports', 'business', 'sci_tech']} | python | MIT | 0bf9381e049ff288e5e79edc38e4a952a371bee2 | 2026-01-05T07:08:26.295297Z | false |
justinlovelace/latent-diffusion-for-language | https://github.com/justinlovelace/latent-diffusion-for-language/blob/0bf9381e049ff288e5e79edc38e4a952a371bee2/train_latent_model.py | train_latent_model.py | import numpy as np
import torch.nn.functional as F
import torch
import os
import json
import sys
from utils import file_utils
from latent_models.latent_finetuning import Trainer
import argparse
def main(args):
trainer = Trainer(
args=args,
dataset_name=args.dataset_name,
train_bat... | python | MIT | 0bf9381e049ff288e5e79edc38e4a952a371bee2 | 2026-01-05T07:08:26.295297Z | false |
justinlovelace/latent-diffusion-for-language | https://github.com/justinlovelace/latent-diffusion-for-language/blob/0bf9381e049ff288e5e79edc38e4a952a371bee2/latent_models/latent_finetuning.py | latent_models/latent_finetuning.py | import math
import copy
from pathlib import Path
import random
from functools import partial
from collections import namedtuple, Counter
from multiprocessing import cpu_count
import os
import numpy as np
from sklearn.metrics import f1_score, accuracy_score
from contextlib import nullcontext
import json
import torch
f... | python | MIT | 0bf9381e049ff288e5e79edc38e4a952a371bee2 | 2026-01-05T07:08:26.295297Z | false |
justinlovelace/latent-diffusion-for-language | https://github.com/justinlovelace/latent-diffusion-for-language/blob/0bf9381e049ff288e5e79edc38e4a952a371bee2/latent_models/t5_latent_model.py | latent_models/t5_latent_model.py | import torch
import torch.nn as nn
from dataclasses import dataclass
from transformers import T5ForConditionalGeneration, MT5ForConditionalGeneration
from latent_models.perceiver_ae import PerceiverAutoEncoder
from einops import rearrange
class T5ForConditionalGenerationLatent(T5ForConditionalGeneration):
def ... | python | MIT | 0bf9381e049ff288e5e79edc38e4a952a371bee2 | 2026-01-05T07:08:26.295297Z | false |
justinlovelace/latent-diffusion-for-language | https://github.com/justinlovelace/latent-diffusion-for-language/blob/0bf9381e049ff288e5e79edc38e4a952a371bee2/latent_models/bart_latent_model.py | latent_models/bart_latent_model.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from dataclasses import dataclass
from transformers.models.bart.modeling_bart import (
BartForConditionalGeneration,
)
from latent_models.perceiver_ae import PerceiverAutoEncoder
from einops import rearrange
class BARTForConditionalGenerationLat... | python | MIT | 0bf9381e049ff288e5e79edc38e4a952a371bee2 | 2026-01-05T07:08:26.295297Z | false |
justinlovelace/latent-diffusion-for-language | https://github.com/justinlovelace/latent-diffusion-for-language/blob/0bf9381e049ff288e5e79edc38e4a952a371bee2/latent_models/perceiver_ae.py | latent_models/perceiver_ae.py | import math
import numpy as np
import torch
from torch import nn, einsum
import torch.nn.functional as F
from einops import rearrange, reduce, repeat
from model.x_transformer import AbsolutePositionalEmbedding
def exists(x):
return x is not None
def divisible_by(numer, denom):
return (numer % denom) == 0... | python | MIT | 0bf9381e049ff288e5e79edc38e4a952a371bee2 | 2026-01-05T07:08:26.295297Z | false |
justinlovelace/latent-diffusion-for-language | https://github.com/justinlovelace/latent-diffusion-for-language/blob/0bf9381e049ff288e5e79edc38e4a952a371bee2/latent_models/latent_utils.py | latent_models/latent_utils.py | import re
from transformers import AutoTokenizer, PreTrainedTokenizerBase, T5ForConditionalGeneration, AutoModelForCausalLM, MBartTokenizerFast, MT5ForConditionalGeneration
from transformers.models.bart.modeling_bart import BartForConditionalGeneration
from transformers.models.mbart.modeling_mbart import MBartForCondit... | python | MIT | 0bf9381e049ff288e5e79edc38e4a952a371bee2 | 2026-01-05T07:08:26.295297Z | false |
justinlovelace/latent-diffusion-for-language | https://github.com/justinlovelace/latent-diffusion-for-language/blob/0bf9381e049ff288e5e79edc38e4a952a371bee2/model/diffusion_transformer.py | model/diffusion_transformer.py | import math
import copy
from pathlib import Path
from random import random
from functools import partial
from collections import namedtuple
from multiprocessing import cpu_count
import os
import torch
from torch import nn, einsum
import torch.nn.functional as F
from torch.utils.data import Dataset, DataLoader
from to... | python | MIT | 0bf9381e049ff288e5e79edc38e4a952a371bee2 | 2026-01-05T07:08:26.295297Z | false |
justinlovelace/latent-diffusion-for-language | https://github.com/justinlovelace/latent-diffusion-for-language/blob/0bf9381e049ff288e5e79edc38e4a952a371bee2/model/x_transformer.py | model/x_transformer.py | import math
from re import X
import torch
from torch import nn, einsum
import torch.nn.functional as F
from functools import partial, wraps
from inspect import isfunction
from collections import namedtuple
from einops import rearrange, repeat, reduce
from einops.layers.torch import Rearrange
# constants
DEFAULT_DIM... | python | MIT | 0bf9381e049ff288e5e79edc38e4a952a371bee2 | 2026-01-05T07:08:26.295297Z | true |
justinlovelace/latent-diffusion-for-language | https://github.com/justinlovelace/latent-diffusion-for-language/blob/0bf9381e049ff288e5e79edc38e4a952a371bee2/utils/torch_utils.py | utils/torch_utils.py | import torch
def compute_grad_norm(parameters):
# implementation adapted from https://pytorch.org/docs/stable/_modules/torch/nn/utils/clip_grad.html#clip_grad_norm_
parameters = [p for p in parameters if p.grad is not None]
total_norm = torch.norm(torch.stack([torch.norm(p.grad.detach(), p=2) for p in para... | python | MIT | 0bf9381e049ff288e5e79edc38e4a952a371bee2 | 2026-01-05T07:08:26.295297Z | false |
justinlovelace/latent-diffusion-for-language | https://github.com/justinlovelace/latent-diffusion-for-language/blob/0bf9381e049ff288e5e79edc38e4a952a371bee2/utils/file_utils.py | utils/file_utils.py | from datetime import datetime
import os
from pathlib import Path
def get_output_dir(args):
model_dir = f'{Path(args.dataset_name).stem}/{datetime.now().strftime("%Y-%m-%d_%H-%M-%S")}'
output_dir = os.path.join(args.save_dir, model_dir)
if not os.path.exists(output_dir):
os.makedirs(output_dir)
... | python | MIT | 0bf9381e049ff288e5e79edc38e4a952a371bee2 | 2026-01-05T07:08:26.295297Z | false |
justinlovelace/latent-diffusion-for-language | https://github.com/justinlovelace/latent-diffusion-for-language/blob/0bf9381e049ff288e5e79edc38e4a952a371bee2/utils/__init__.py | utils/__init__.py | python | MIT | 0bf9381e049ff288e5e79edc38e4a952a371bee2 | 2026-01-05T07:08:26.295297Z | false | |
justinlovelace/latent-diffusion-for-language | https://github.com/justinlovelace/latent-diffusion-for-language/blob/0bf9381e049ff288e5e79edc38e4a952a371bee2/diffusion/text_denoising_diffusion.py | diffusion/text_denoising_diffusion.py | import math
import copy
from pathlib import Path
import random
from functools import partial
from collections import namedtuple, Counter
from multiprocessing import cpu_count
import os
import numpy as np
import csv
import timeit
import json
import argparse
from collections import defaultdict
from contextlib import nul... | python | MIT | 0bf9381e049ff288e5e79edc38e4a952a371bee2 | 2026-01-05T07:08:26.295297Z | true |
justinlovelace/latent-diffusion-for-language | https://github.com/justinlovelace/latent-diffusion-for-language/blob/0bf9381e049ff288e5e79edc38e4a952a371bee2/diffusion/optimizer.py | diffusion/optimizer.py | from typing import Tuple, Optional, Callable
import torch
from torch.optim.optimizer import Optimizer
from torch.optim import AdamW
# functions
def exists(val):
return val is not None
def separate_weight_decayable_params(params):
# Exclude affine params in norms (e.g. LayerNorm, GroupNorm, etc.) and bias te... | python | MIT | 0bf9381e049ff288e5e79edc38e4a952a371bee2 | 2026-01-05T07:08:26.295297Z | false |
justinlovelace/latent-diffusion-for-language | https://github.com/justinlovelace/latent-diffusion-for-language/blob/0bf9381e049ff288e5e79edc38e4a952a371bee2/diffusion/constant.py | diffusion/constant.py | generate_kwargs = {
'beam':
{'max_length':64, 'min_length':5, 'do_sample':False, 'num_beams':4, 'no_repeat_ngram_size':3, 'repetition_penalty':1.2},}
# 'nucleus':
# {'max_length':64, 'min_length':5, 'do_sample':True, 'top_p':.95, 'num_beams':1, 'no_repeat_ngram_size':3, 'repetition_penalty':1.2}}
| python | MIT | 0bf9381e049ff288e5e79edc38e4a952a371bee2 | 2026-01-05T07:08:26.295297Z | false |
justinlovelace/latent-diffusion-for-language | https://github.com/justinlovelace/latent-diffusion-for-language/blob/0bf9381e049ff288e5e79edc38e4a952a371bee2/dataset_utils/text_dataset.py | dataset_utils/text_dataset.py | from multiprocessing.spawn import prepare
import os
import json
from datasets import load_dataset, Value
from torch.utils.data import Dataset, DataLoader
from transformers import PreTrainedTokenizerBase, default_data_collator
from dataset_utils.denoising_collator import DataCollatorForBartDenoisingLM
from dataset_uti... | python | MIT | 0bf9381e049ff288e5e79edc38e4a952a371bee2 | 2026-01-05T07:08:26.295297Z | false |
justinlovelace/latent-diffusion-for-language | https://github.com/justinlovelace/latent-diffusion-for-language/blob/0bf9381e049ff288e5e79edc38e4a952a371bee2/dataset_utils/denoising_collator.py | dataset_utils/denoising_collator.py | # Adapted from transformers pull request: https://github.com/huggingface/transformers/pull/18904
import math
from dataclasses import dataclass
from typing import Dict, List, Optional
import numpy as np
import torch
from torch.utils.data import DataLoader
from transformers import AutoTokenizer, BatchEncoding, PreTrain... | python | MIT | 0bf9381e049ff288e5e79edc38e4a952a371bee2 | 2026-01-05T07:08:26.295297Z | false |
justinlovelace/latent-diffusion-for-language | https://github.com/justinlovelace/latent-diffusion-for-language/blob/0bf9381e049ff288e5e79edc38e4a952a371bee2/dataset_utils/flan_collator.py | dataset_utils/flan_collator.py | # Adapted from transformers pull request: https://github.com/huggingface/transformers/pull/18904
import math
from dataclasses import dataclass
from typing import Dict, List, Optional
import numpy as np
import torch
from torch.utils.data import DataLoader
from transformers import AutoTokenizer, BatchEncoding, PreTrain... | python | MIT | 0bf9381e049ff288e5e79edc38e4a952a371bee2 | 2026-01-05T07:08:26.295297Z | false |
justinlovelace/latent-diffusion-for-language | https://github.com/justinlovelace/latent-diffusion-for-language/blob/0bf9381e049ff288e5e79edc38e4a952a371bee2/evaluation/evaluation.py | evaluation/evaluation.py | import torch
from evaluate import load
from transformers import PreTrainedTokenizerBase
from sentence_transformers import SentenceTransformer
from nltk.util import ngrams
from collections import defaultdict
import spacy
import numpy as np
import wandb
def compute_perplexity(all_texts_list, model_id='gpt2-large'):
... | python | MIT | 0bf9381e049ff288e5e79edc38e4a952a371bee2 | 2026-01-05T07:08:26.295297Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/train.py | train.py | """ BigGAN: The Authorized Unofficial PyTorch release
Code by A. Brock and A. Andonian
This code is an unofficial reimplementation of
"Large-Scale GAN Training for High Fidelity Natural Image Synthesis,"
by A. Brock, J. Donahue, and K. Simonyan (arXiv 1809.11096).
Let's go.
"""
import os
import fu... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/datasets.py | datasets.py | ''' Datasets
This file contains definitions for our CIFAR, ImageFolder, and HDF5 datasets
'''
import os
import os.path
import sys
from PIL import Image
from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True
import numpy as np
from tqdm import tqdm, trange
import torchvision.datasets as dset
import torchv... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/make_hdf5.py | make_hdf5.py | """ Convert dataset to HDF5
This script preprocesses a dataset and saves it (images and labels) to
an HDF5 file for improved I/O. """
import os
import sys
from argparse import ArgumentParser
from tqdm import tqdm, trange
import h5py as h5
import numpy as np
import torch
import torchvision.datasets as dset
imp... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/BigGAN.py | BigGAN.py | import numpy as np
import math
import functools
import torch
import torch.nn as nn
from torch.nn import init
import torch.optim as optim
import torch.nn.functional as F
from torch.nn import Parameter as P
import layers
from sync_batchnorm import SynchronizedBatchNorm2d as SyncBatchNorm2d
import pdb
# Architectures... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/inception_tf13.py | inception_tf13.py | ''' Tensorflow inception score code
Derived from https://github.com/openai/improved-gan
Code derived from tensorflow/tensorflow/models/image/imagenet/classify_image.py
THIS CODE REQUIRES TENSORFLOW 1.3 or EARLIER to run in PARALLEL BATCH MODE
To use this code, run sample.py on your model with --sample_npz, and then
... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/calculate_inception_moments.py | calculate_inception_moments.py | ''' Calculate Inception Moments
This script iterates over the dataset and calculates the moments of the
activations of the Inception net (needed for FID), and also returns
the Inception Score of the training data.
Note that if you don't shuffle the data, the IS of true data will be under-
estimated as it is lab... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/animal_hash.py | animal_hash.py | c = ['Aardvark', 'Abyssinian', 'Affenpinscher', 'Akbash', 'Akita', 'Albatross',
'Alligator', 'Alpaca', 'Angelfish', 'Ant', 'Anteater', 'Antelope', 'Ape',
'Armadillo', 'Ass', 'Avocet', 'Axolotl', 'Baboon', 'Badger', 'Balinese',
'Bandicoot', 'Barb', 'Barnacle', 'Barracuda', 'Bat', 'Beagle', 'Bear',
'B... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/inception_utils.py | inception_utils.py | ''' Inception utilities
This file contains methods for calculating IS and FID, using either
the original numpy code or an accelerated fully-pytorch version that
uses a fast newton-schulz approximation for the matrix sqrt. There are also
methods for acquiring a desired number of samples from the Generat... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/BigGANdeep.py | BigGANdeep.py | import numpy as np
import math
import functools
import torch
import torch.nn as nn
from torch.nn import init
import torch.optim as optim
import torch.nn.functional as F
from torch.nn import Parameter as P
import layers
from sync_batchnorm import SynchronizedBatchNorm2d as SyncBatchNorm2d
# BigGAN-deep: uses a differ... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/utils.py | utils.py | #!/usr/bin/env python
# -*- coding: utf-8 -*-
''' Utilities file
This file contains utility functions for bookkeeping, logging, and data loading.
Methods which directly affect training should either go in layers, the model,
or train_fns.py.
'''
from __future__ import print_function
import sys
import os
import numpy a... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | true |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/losses.py | losses.py | import torch
import torch.nn.functional as F
import pdb
# DCGAN loss
def loss_dcgan_dis(dis_fake, dis_real):
L1 = torch.mean(F.softplus(-dis_real))
L2 = torch.mean(F.softplus(dis_fake))
return L1, L2
def loss_dcgan_gen(dis_fake, M_regu=None):
loss = torch.mean(F.softplus(-dis_fake))
return loss
# Hinge L... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/train_fns.py | train_fns.py | ''' train_fns.py
Functions for the main loop of training different conditional image models
'''
import torch
import torch.nn as nn
import torchvision
import os
import utils
import losses
import pdb
# Dummy training function for debugging
def dummy_training_function():
def train(x, y):
return {}
return train
... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/sample.py | sample.py | ''' Sample
This script loads a pretrained net and a weightsfile and sample '''
import functools
import math
import numpy as np
from tqdm import tqdm, trange
import torch
import torch.nn as nn
from torch.nn import init
import torch.optim as optim
import torch.nn.functional as F
from torch.nn import Parameter as P
i... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/layers.py | layers.py | ''' Layers
This file contains various layers for the BigGAN models.
'''
import numpy as np
import torch
import torch.nn as nn
from torch.nn import init
import torch.optim as optim
import torch.nn.functional as F
from torch.nn import Parameter as P
from sync_batchnorm import SynchronizedBatchNorm2d as SyncBN2d
# ... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/styleGANv2/calc_inception.py | styleGANv2/calc_inception.py | import argparse
import pickle
import os
import torch
from torch import nn
from torch.nn import functional as F
from torch.utils.data import DataLoader
from torchvision import transforms
from torchvision.models import inception_v3, Inception3
import numpy as np
from tqdm import tqdm
from inception import InceptionV3
f... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/styleGANv2/precompute_acts.py | styleGANv2/precompute_acts.py | import argparse
import pickle
import random
import numpy as np
from tqdm import tqdm
import torch
from torchvision import transforms
from dataset import MultiResolutionDataset
from train import sample_data
from metric.inception import InceptionV3
if __name__ == '__main__':
parser = argparse.ArgumentParser(descript... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/styleGANv2/train.py | styleGANv2/train.py | import argparse
import math
import random
import os
import numpy as np
import torch
from torch import nn, autograd, optim
from torch.nn import functional as F
from torch.utils import data
import torch.distributed as dist
from torchvision import transforms, utils
from tqdm import tqdm
from metric.inception import Incep... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/styleGANv2/projector.py | styleGANv2/projector.py | import argparse
import math
import os
import torch
from torch import optim
from torch.nn import functional as F
from torchvision import transforms
from PIL import Image
from tqdm import tqdm
import lpips
from model import Generator
def noise_regularize(noises):
loss = 0
for noise in noises:
size = ... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/styleGANv2/ppl.py | styleGANv2/ppl.py | import argparse
import torch
from torch.nn import functional as F
import numpy as np
from tqdm import tqdm
import lpips
from model import Generator
def normalize(x):
return x / torch.sqrt(x.pow(2).sum(-1, keepdim=True))
def slerp(a, b, t):
a = normalize(a)
b = normalize(b)
d = (a * b).sum(-1, keep... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/styleGANv2/inception.py | styleGANv2/inception.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torchvision import models
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://do... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/styleGANv2/convert_weight.py | styleGANv2/convert_weight.py | import argparse
import os
import sys
import pickle
import math
import torch
import numpy as np
from torchvision import utils
from model import Generator, Discriminator
def convert_modconv(vars, source_name, target_name, flip=False):
weight = vars[source_name + "/weight"].value().eval()
mod_weight = vars[sou... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/styleGANv2/model.py | styleGANv2/model.py | import math
import random
import functools
import operator
import torch
from torch import nn
from torch.nn import functional as F
from torch.autograd import Function
from op import FusedLeakyReLU, fused_leaky_relu, upfirdn2d
class PixelNorm(nn.Module):
def __init__(self):
super().__init__()
def for... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/styleGANv2/fid.py | styleGANv2/fid.py | import argparse
import pickle
import torch
from torch import nn
import numpy as np
from scipy import linalg
from tqdm import tqdm
from model import Generator
from calc_inception import load_patched_inception_v3
@torch.no_grad()
def extract_feature_from_samples(
generator, inception, truncation, truncation_laten... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/styleGANv2/generate.py | styleGANv2/generate.py | import argparse
import torch
from torchvision import utils
from model import Generator
from tqdm import tqdm
def generate(args, g_ema, device, mean_latent):
with torch.no_grad():
g_ema.eval()
for i in tqdm(range(args.pics)):
sample_z = torch.randn(args.sample, args.latent, device=dev... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/styleGANv2/dataset.py | styleGANv2/dataset.py | from io import BytesIO
import lmdb
from PIL import Image
from torch.utils.data import Dataset
class MultiResolutionDataset(Dataset):
def __init__(self, path, transform, resolution=256):
self.env = lmdb.open(
path,
max_readers=32,
readonly=True,
lock=False,
... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/styleGANv2/non_leaking.py | styleGANv2/non_leaking.py | import math
import torch
from torch.nn import functional as F
from distributed import reduce_sum
from op import upfirdn2d
class AdaptiveAugment:
def __init__(self, ada_aug_target, ada_aug_len, update_every, device):
self.ada_aug_target = ada_aug_target
self.ada_aug_len = ada_aug_len
self... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/styleGANv2/distributed.py | styleGANv2/distributed.py | import math
import pickle
import torch
from torch import distributed as dist
from torch.utils.data.sampler import Sampler
def get_rank():
if not dist.is_available():
return 0
if not dist.is_initialized():
return 0
return dist.get_rank()
def synchronize():
if not dist.is_available(... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/styleGANv2/apply_factor.py | styleGANv2/apply_factor.py | import argparse
import torch
from torchvision import utils
from model import Generator
if __name__ == "__main__":
torch.set_grad_enabled(False)
parser = argparse.ArgumentParser(description="Apply closed form factorization")
parser.add_argument(
"-i", "--index", type=int, default=0, help="index... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/styleGANv2/closed_form_factorization.py | styleGANv2/closed_form_factorization.py | import argparse
import torch
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Extract factor/eigenvectors of latent spaces using closed form factorization"
)
parser.add_argument(
"--out", type=str, default="factor.pt", help="name of the result factor file"
)
... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/styleGANv2/prepare_data.py | styleGANv2/prepare_data.py | import argparse
from io import BytesIO
import multiprocessing
from functools import partial
from PIL import Image
import lmdb
from tqdm import tqdm
from torchvision import datasets
from torchvision.transforms import functional as trans_fn
def resize_and_convert(img, size, resample, quality=100):
img = trans_fn.r... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/styleGANv2/lpips/base_model.py | styleGANv2/lpips/base_model.py | import os
import numpy as np
import torch
from torch.autograd import Variable
from pdb import set_trace as st
from IPython import embed
class BaseModel():
def __init__(self):
pass;
def name(self):
return 'BaseModel'
def initialize(self, use_gpu=True, gpu_ids=[0]):
self.use... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/styleGANv2/lpips/dist_model.py | styleGANv2/lpips/dist_model.py |
from __future__ import absolute_import
import sys
import numpy as np
import torch
from torch import nn
import os
from collections import OrderedDict
from torch.autograd import Variable
import itertools
from .base_model import BaseModel
from scipy.ndimage import zoom
import fractions
import functools
import skimage.tr... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/styleGANv2/lpips/networks_basic.py | styleGANv2/lpips/networks_basic.py |
from __future__ import absolute_import
import sys
import torch
import torch.nn as nn
import torch.nn.init as init
from torch.autograd import Variable
import numpy as np
from pdb import set_trace as st
from skimage import color
from IPython import embed
from . import pretrained_networks as pn
import lpips as util
de... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/styleGANv2/lpips/__init__.py | styleGANv2/lpips/__init__.py |
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
from skimage.measure import compare_ssim
import torch
from torch.autograd import Variable
from lpips import dist_model
class PerceptualLoss(torch.nn.Module):
def __init__(self, model='... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/styleGANv2/lpips/pretrained_networks.py | styleGANv2/lpips/pretrained_networks.py | from collections import namedtuple
import torch
from torchvision import models as tv
from IPython import embed
class squeezenet(torch.nn.Module):
def __init__(self, requires_grad=False, pretrained=True):
super(squeezenet, self).__init__()
pretrained_features = tv.squeezenet1_1(pretrained=pretrained... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/styleGANv2/metric/inception.py | styleGANv2/metric/inception.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torchvision import models
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://do... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/styleGANv2/metric/fid_score.py | styleGANv2/metric/fid_score.py | #!/usr/bin/env python3
"""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 a... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/styleGANv2/metric/metric.py | styleGANv2/metric/metric.py | import time
import functools
import numpy as np
from tqdm import tqdm
import torch
from torch.utils.data import TensorDataset, DataLoader
from .fid_score import calculate_frechet_distance
# from .kid_score import polynomial_mmd_averages
from .swd_score import calculate_swd
def get_fake_images_and_acts_I2I(args, Enc... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/styleGANv2/metric/swd_score.py | styleGANv2/metric/swd_score.py | # https://github.com/koshian2/swd-pytorch/blob/master/swd.py
from PIL import Image
import math
import numpy as np
import torch
import torch.nn.functional as F
import torchvision
# Gaussian blur kernel
def get_gaussian_kernel(device="cpu"):
kernel = np.array([
[1, 4, 6, 4, 1],
[4, 16, 24, 16, 4],
[6, 24, 36, 24... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/styleGANv2/metric/kid_score.py | styleGANv2/metric/kid_score.py | # https://github.com/mbinkowski/MMD-GAN/blob/master/gan/compute_scores.py
"""Calculates the Kernel Inception Distance (KID) to evalulate GANs
"""
import os
import sys
import numpy as np
from sklearn.metrics.pairwise import polynomial_kernel
def polynomial_mmd_averages(codes_r, codes_g, n_subsets=100, subset_size=1000... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/styleGANv2/op/fused_act.py | styleGANv2/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... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/styleGANv2/op/__init__.py | styleGANv2/op/__init__.py | from .fused_act import FusedLeakyReLU, fused_leaky_relu
from .upfirdn2d import upfirdn2d
| python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/styleGANv2/op/upfirdn2d.py | styleGANv2/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, ... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/MNISTtf/MNISTtf_old/conditional_continue/off_manifold/teacher_output_d.py | MNISTtf/MNISTtf_old/conditional_continue/off_manifold/teacher_output_d.py |
import os, sys
sys.path.append(os.getcwd())
import numpy as np
import tensorflow as tf
import tflib as lib
import tflib.ops.linear
import tflib.ops.conv2d
import tflib.ops.batchnorm
import tflib.ops.deconv2d
import tflib.save_images
import tflib.mnist
import tflib.plot
import pdb
def teacher_model(noise, fake_dat... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/MNISTtf/MNISTtf_old/conditional_continue/off_manifold/cgan_super_g_d_two_class_unbalance_one_D.py | MNISTtf/MNISTtf_old/conditional_continue/off_manifold/cgan_super_g_d_two_class_unbalance_one_D.py | import os, sys
sys.path.append(os.getcwd())
import time
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
import sklearn.datasets
import tensorflow as tf
import tflib as lib
import tflib.ops.linear
import tflib.ops.conv2d
import tflib.ops.batchnorm
import tflib.ops.deconv2d
i... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/MNISTtf/MNISTtf_old/conditional_continue/off_manifold/teacher.py | MNISTtf/MNISTtf_old/conditional_continue/off_manifold/teacher.py |
import os, sys
sys.path.append(os.getcwd())
import numpy as np
import tensorflow as tf
import tflib as lib
import tflib.ops.linear
import tflib.ops.conv2d
import tflib.ops.batchnorm
import tflib.ops.deconv2d
import tflib.save_images
import tflib.mnist
import tflib.plot
import pdb
def teacher_model(noise, fake_data... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/MNISTtf/MNISTtf_old/conditional_continue/off_manifold/cgan_mnist_knowledge_distillation_adaptor_step1.py | MNISTtf/MNISTtf_old/conditional_continue/off_manifold/cgan_mnist_knowledge_distillation_adaptor_step1.py | import os, sys
sys.path.append(os.getcwd())
import time
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
import sklearn.datasets
import tensorflow as tf
import tflib as lib
import tflib.ops.linear
import tflib.ops.conv2d
import tflib.ops.batchnorm
import tflib.ops.deconv2d
i... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/MNISTtf/MNISTtf_old/conditional_continue/off_manifold/cgan_super_g_d_two_class_unbalance_one_D_no_share_latent.py | MNISTtf/MNISTtf_old/conditional_continue/off_manifold/cgan_super_g_d_two_class_unbalance_one_D_no_share_latent.py | import os, sys
sys.path.append(os.getcwd())
import time
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
import sklearn.datasets
import tensorflow as tf
import tflib as lib
import tflib.ops.linear
import tflib.ops.conv2d
import tflib.ops.batchnorm
import tflib.ops.deconv2d
i... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/MNISTtf/MNISTtf_old/conditional_continue/off_manifold/tflib/lsun_label.py | MNISTtf/MNISTtf_old/conditional_continue/off_manifold/tflib/lsun_label.py |
from os import listdir
import numpy as np
import scipy.misc
import time
import pdb
Label={'bedroom':0,
'kitchen':1,
'dining_room':2,
'conference_room':3,
'living_room':4,
'bridge':5,
'tower':6,
'classroom':7,
'church_outdoor':8,
'restaurant':9}
def make_g... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/MNISTtf/MNISTtf_old/conditional_continue/off_manifold/tflib/plot.py | MNISTtf/MNISTtf_old/conditional_continue/off_manifold/tflib/plot.py | import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
import collections
import time
import cPickle as pickle
_since_beginning = collections.defaultdict(lambda: {})
_since_last_flush = collections.defaultdict(lambda: {})
_iter = [0]
def tick():
_iter[0] += 1
def plot(name, valu... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/MNISTtf/MNISTtf_old/conditional_continue/off_manifold/tflib/mnist_step1.py | MNISTtf/MNISTtf_old/conditional_continue/off_manifold/tflib/mnist_step1.py | import numpy
import os
import urllib
import gzip
import cPickle as pickle
import pdb
def mnist_generator(data, batch_size, n_labelled, limit=None, selecting_label = None, bias = None):
images, targets = data
if bias is not None :
images = images[targets!=bias]
targets = targets[targets!=bias]... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/MNISTtf/MNISTtf_old/conditional_continue/off_manifold/tflib/mnist_step2.py | MNISTtf/MNISTtf_old/conditional_continue/off_manifold/tflib/mnist_step2.py | import numpy
import os
import urllib
import gzip
import cPickle as pickle
import pdb
import os
from scipy.misc import imsave
def mnist_generator(data, batch_size, n_labelled, limit=None, selecting_label = None):
images, targets = data
#for index, i in enumerate(targets):
# if not os.path.exists('datase... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/MNISTtf/MNISTtf_old/conditional_continue/off_manifold/tflib/mnist.py | MNISTtf/MNISTtf_old/conditional_continue/off_manifold/tflib/mnist.py | import numpy
import os
import urllib
import gzip
import cPickle as pickle
import pdb
def mnist_generator(data, batch_size, n_labelled, limit=None, selecting_label = None, bias = None):
images, targets = data
if bias is not None :
images = images[targets!=bias]
targets = targets[targets!=bias]... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/MNISTtf/MNISTtf_old/conditional_continue/off_manifold/tflib/__init__.py | MNISTtf/MNISTtf_old/conditional_continue/off_manifold/tflib/__init__.py | import numpy as np
import tensorflow as tf
#import locale
#locale.setlocale(locale.LC_ALL, '')
_params = {}
_param_aliases = {}
def param(name, *args, **kwargs):
"""
A wrapper for `tf.Variable` which enables parameter sharing in models.
Creates and returns theano shared variables similarly to `tf.Va... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/MNISTtf/MNISTtf_old/conditional_continue/off_manifold/tflib/lsun.py | MNISTtf/MNISTtf_old/conditional_continue/off_manifold/tflib/lsun.py | import numpy as np
import scipy.misc
import time
import cv2
from os import listdir
def make_generator(path, n_files, batch_size, image_size):
epoch_count = [1]
images_name = listdir(path)
if n_files == 0:
n_files = len(images_name)
else:
n_files = n_files
def get_epoch():
... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/MNISTtf/MNISTtf_old/conditional_continue/off_manifold/tflib/save_images.py | MNISTtf/MNISTtf_old/conditional_continue/off_manifold/tflib/save_images.py | """
Image grid saver, based on color_grid_vis from github.com/Newmu
"""
import numpy as np
import scipy.misc
from scipy.misc import imsave
def save_images(X, save_path):
# [0, 1] -> [0,255]
if isinstance(X.flatten()[0], np.floating):
X = (255.99*X).astype('uint8')
n_samples = X.shape[0]
rows ... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/MNISTtf/MNISTtf_old/conditional_continue/off_manifold/tflib/mnist_mask_digit.py | MNISTtf/MNISTtf_old/conditional_continue/off_manifold/tflib/mnist_mask_digit.py |
import numpy
import os
import urllib
import gzip
import cPickle as pickle
import pdb
def mnist_generator(data, batch_size, n_labelled, limit=None, selecting_label = None):
images, targets = data
# if selecting_label is None:
# rng_state = numpy.random.get_state()
# numpy.random.shuffle(images)
... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/MNISTtf/MNISTtf_old/conditional_continue/off_manifold/tflib/ops/layernorm.py | MNISTtf/MNISTtf_old/conditional_continue/off_manifold/tflib/ops/layernorm.py | import tflib as lib
import numpy as np
import tensorflow as tf
def Layernorm(name, norm_axes, inputs):
mean, var = tf.nn.moments(inputs, norm_axes, keep_dims=True)
# Assume the 'neurons' axis is the first of norm_axes. This is the case for fully-connected and BCHW conv layers.
n_neurons = inputs.get_shap... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/MNISTtf/MNISTtf_old/conditional_continue/off_manifold/tflib/ops/deconv2d.py | MNISTtf/MNISTtf_old/conditional_continue/off_manifold/tflib/ops/deconv2d.py | import tflib as lib
import numpy as np
import tensorflow as tf
_default_weightnorm = False
def enable_default_weightnorm():
global _default_weightnorm
_default_weightnorm = True
_weights_stdev = None
def set_weights_stdev(weights_stdev):
global _weights_stdev
_weights_stdev = weights_stdev
def unset... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/MNISTtf/MNISTtf_old/conditional_continue/off_manifold/tflib/ops/__init__.py | MNISTtf/MNISTtf_old/conditional_continue/off_manifold/tflib/ops/__init__.py | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false | |
yaxingwang/MineGAN | https://github.com/yaxingwang/MineGAN/blob/a810f2d77f36ea9cf6993dede958b6f5d458f4b6/MNISTtf/MNISTtf_old/conditional_continue/off_manifold/tflib/ops/conv1d.py | MNISTtf/MNISTtf_old/conditional_continue/off_manifold/tflib/ops/conv1d.py | import tflib as lib
import numpy as np
import tensorflow as tf
_default_weightnorm = False
def enable_default_weightnorm():
global _default_weightnorm
_default_weightnorm = True
def Conv1D(name, input_dim, output_dim, filter_size, inputs, he_init=True, mask_type=None, stride=1, weightnorm=None, biases=True, ... | python | MIT | a810f2d77f36ea9cf6993dede958b6f5d458f4b6 | 2026-01-05T07:08:28.063149Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.