repo stringlengths 2 99 | file stringlengths 13 225 | code stringlengths 0 18.3M | file_length int64 0 18.3M | avg_line_length float64 0 1.36M | max_line_length int64 0 4.26M | extension_type stringclasses 1
value |
|---|---|---|---|---|---|---|
benchmarks | benchmarks-master/scripts/tf_cnn_benchmarks/benchmark_cnn.py | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applica... | 119,614 | 45.005769 | 155 | py |
benchmarks | benchmarks-master/scripts/tf_cnn_benchmarks/flags.py | # Copyright 2018 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applica... | 3,534 | 38.719101 | 126 | py |
benchmarks | benchmarks-master/scripts/tf_cnn_benchmarks/allreduce.py | # # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
# #
# # Licensed under the Apache License, Version 2.0 (the "License");
# # you may not use this file except in compliance with the License.
# # You may obtain a copy of the License at
# #
# # http://www.apache.org/licenses/LICENSE-2.0
# #
# # Unless r... | 23,559 | 36.575758 | 82 | py |
benchmarks | benchmarks-master/scripts/tf_cnn_benchmarks/benchmark_storage.py | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applica... | 1,679 | 39 | 80 | py |
benchmarks | benchmarks-master/scripts/tf_cnn_benchmarks/cbuild_benchmark_storage.py | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applica... | 3,511 | 34.12 | 110 | py |
benchmarks | benchmarks-master/scripts/tf_cnn_benchmarks/platforms/util.py | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applica... | 1,129 | 40.851852 | 85 | py |
benchmarks | benchmarks-master/scripts/tf_cnn_benchmarks/platforms/__init__.py | 0 | 0 | 0 | py | |
benchmarks | benchmarks-master/scripts/tf_cnn_benchmarks/platforms/default/util.py | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applica... | 2,226 | 27.551282 | 80 | py |
benchmarks | benchmarks-master/scripts/tf_cnn_benchmarks/platforms/default/__init__.py | 0 | 0 | 0 | py | |
benchmarks | benchmarks-master/scripts/tf_cnn_benchmarks/models/mobilenet_v2.py | # Copyright 2018 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applica... | 7,317 | 35.59 | 80 | py |
benchmarks | benchmarks-master/scripts/tf_cnn_benchmarks/models/nasnet_model.py | # Copyright 2018 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applica... | 20,624 | 34.683391 | 80 | py |
benchmarks | benchmarks-master/scripts/tf_cnn_benchmarks/models/overfeat_model.py | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applica... | 1,554 | 30.734694 | 80 | py |
benchmarks | benchmarks-master/scripts/tf_cnn_benchmarks/models/vgg_model.py | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applica... | 2,263 | 27.3 | 80 | py |
benchmarks | benchmarks-master/scripts/tf_cnn_benchmarks/models/densenet_model.py | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applica... | 3,693 | 37.479167 | 80 | py |
benchmarks | benchmarks-master/scripts/tf_cnn_benchmarks/models/model_config.py | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applica... | 5,300 | 40.093023 | 80 | py |
benchmarks | benchmarks-master/scripts/tf_cnn_benchmarks/models/nasnet_utils.py | # Copyright 2018 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applica... | 18,310 | 36.21748 | 80 | py |
benchmarks | benchmarks-master/scripts/tf_cnn_benchmarks/models/lenet_model.py | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applica... | 1,249 | 30.25 | 80 | py |
benchmarks | benchmarks-master/scripts/tf_cnn_benchmarks/models/mobilenet_conv_blocks.py | # Copyright 2018 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applica... | 13,014 | 35.456583 | 80 | py |
benchmarks | benchmarks-master/scripts/tf_cnn_benchmarks/models/model.py | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applica... | 4,910 | 36.204545 | 80 | py |
benchmarks | benchmarks-master/scripts/tf_cnn_benchmarks/models/squeezenet_model.py | # Copyright 2017 Ioannis Athanasiadis(supernlogn) one of the wanna be TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/li... | 3,937 | 32.372881 | 110 | py |
benchmarks | benchmarks-master/scripts/tf_cnn_benchmarks/models/alexnet_model.py | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applica... | 3,004 | 33.147727 | 80 | py |
benchmarks | benchmarks-master/scripts/tf_cnn_benchmarks/models/googlenet_model.py | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applica... | 2,173 | 36.482759 | 80 | py |
benchmarks | benchmarks-master/scripts/tf_cnn_benchmarks/models/trivial_model.py | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applica... | 1,312 | 31.02439 | 80 | py |
benchmarks | benchmarks-master/scripts/tf_cnn_benchmarks/models/__init__.py | 0 | 0 | 0 | py | |
benchmarks | benchmarks-master/scripts/tf_cnn_benchmarks/models/official_resnet_model.py | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applica... | 3,225 | 38.82716 | 80 | py |
benchmarks | benchmarks-master/scripts/tf_cnn_benchmarks/models/inception_model.py | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applica... | 8,393 | 39.747573 | 80 | py |
benchmarks | benchmarks-master/scripts/tf_cnn_benchmarks/models/mobilenet.py | # Copyright 2018 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applica... | 17,378 | 36.214133 | 80 | py |
benchmarks | benchmarks-master/scripts/tf_cnn_benchmarks/models/resnet_model.py | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applica... | 12,347 | 33.783099 | 80 | py |
tensorflow-mnist-MLP-batch_normalization-weight_initializers | tensorflow-mnist-MLP-batch_normalization-weight_initializers-master/run_main.py | from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
from six.moves import urllib
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
from tensorflow.contrib.layers.python.layers import batch_norm as batch_norm
SOURCE_U... | 9,299 | 39.434783 | 155 | py |
Geometric_Transformation_CMR | Geometric_Transformation_CMR-main/dataloader.py | import random
import shutil
import cv2
import torch
from PIL import Image
from matplotlib import pylab as plt
import nibabel as nib
from nibabel import nifti1
import torchvision
from torch.utils.data import Dataset, DataLoader
import torchvision.transforms as transforms
import os
import numpy as np
class MyData(Datas... | 5,273 | 34.635135 | 120 | py |
Geometric_Transformation_CMR | Geometric_Transformation_CMR-main/GeoNet.py | import torch
from torch import nn
from torch.nn import Sequential, Conv2d, MaxPool2d, Flatten, Linear, BatchNorm2d, ReLU, BatchNorm1d
class GeoNet(nn.Module):
def __init__(self):
super(GeoNet, self).__init__()
self.conv1 = Conv2d(1, 32, kernel_size=5, padding=2)
self.conv2 = Conv2d(32, 64... | 1,344 | 27.020833 | 99 | py |
Geometric_Transformation_CMR | Geometric_Transformation_CMR-main/OtherExperiment.py | from torchvision.transforms import transforms
from dataloader import *
from GeoNet import *
def predict(model):
model.eval()
total_LGE_accuracy = 0
total_C0_accuracy = 0
data_aug = transforms.Compose([
transforms.ToTensor(),
transforms.Grayscale(num_output_channels=1),
... | 1,827 | 44.7 | 158 | py |
Geometric_Transformation_CMR | Geometric_Transformation_CMR-main/train.py | import cv2
import torch
from torch import nn
from torch.utils.tensorboard import SummaryWriter
from dataloader import *
from GeoNet import *
from d2l import torch as d2l
def train(image_datasets, data_loaders, epochs, learning_rate, wt_decay):
train_data_size = len(image_datasets['train'])
test_data_size = le... | 4,003 | 33.817391 | 116 | py |
chatgpt-failures | chatgpt-failures-main/scripts/kid1/main.py |
import random
SEQUENCES = [['East', 'South', 'West', 'North'], ['Alpha', 'Beta', 'Gamma', 'Delta'], ['Qui', 'Quo', 'Qua'], ['Donald', 'Duck', 'Dunn'],
['Mambo #1', 'Mambo #2', 'Mambo #3', 'Mambo #4', 'Mambo #5'], ['Pippo', 'Pluto', 'Paperino'], ['Apple', 'Banana', 'Cherry'],
['Jesse Pinkma... | 2,231 | 54.8 | 144 | py |
ZeCon | ZeCon-main/main.py | from optimization.image_editor_zecon import ImageEditor
from optimization.arguments import get_arguments
if __name__ == "__main__":
args = get_arguments()
image_editor = ImageEditor(args)
image_editor.edit_image_by_prompt()
| 247 | 23.8 | 55 | py |
ZeCon | ZeCon-main/optimization/losses.py | # PatchNCE loss from https://github.com/taesungp/contrastive-unpaired-translation
from torch.nn import functional as F
import torch
import numpy as np
import torch.nn as nn
def d_clip_loss(x, y, use_cosine=False):
x = F.normalize(x, dim=-1)
y = F.normalize(y, dim=-1)
if use_cosine:
distance = 1 - ... | 4,600 | 29.879195 | 95 | py |
ZeCon | ZeCon-main/optimization/arguments.py | import argparse
def get_arguments() -> argparse.Namespace:
parser = argparse.ArgumentParser()
# Inputs
parser.add_argument(
"-p_t", "--prompt_tgt", type=str, help="The prompt for the desired editing", required=False
)
parser.add_argument(
"-p_s", "--prompt_src", type=str, help="Th... | 4,838 | 27.298246 | 100 | py |
ZeCon | ZeCon-main/optimization/constants.py | ASSETS_DIR_NAME = "assets"
RANKED_RESULTS_DIR = "ranked" | 56 | 27.5 | 29 | py |
ZeCon | ZeCon-main/optimization/augmentations.py | import torch
from torch import nn
import kornia.augmentation as K
# import ipdb
class ImageAugmentations(nn.Module):
def __init__(self, output_size, aug_prob, p_min, p_max, patch=False):
super().__init__()
self.output_size = output_size
self.aug_prob = aug_prob
self.patch =... | 1,974 | 34.267857 | 105 | py |
ZeCon | ZeCon-main/optimization/image_editor_zecon.py | import os
from pathlib import Path
from optimization.constants import ASSETS_DIR_NAME
from utils.metrics_accumulator import MetricsAccumulator
from numpy import random
from optimization.augmentations import ImageAugmentations as ImageAugmentations
from PIL import Image
import torch
from torchvision import transforms
i... | 17,010 | 43.648294 | 152 | py |
ZeCon | ZeCon-main/CLIP/setup.py | import os
import pkg_resources
from setuptools import setup, find_packages
setup(
name="clip",
py_modules=["clip"],
version="1.0",
description="",
author="OpenAI",
packages=find_packages(exclude=["tests*"]),
install_requires=[
str(r)
for r in pkg_resources.parse_requirement... | 491 | 21.363636 | 77 | py |
ZeCon | ZeCon-main/CLIP/clip/simple_tokenizer.py | import gzip
import html
import os
from functools import lru_cache
import ftfy
import regex as re
@lru_cache()
def default_bpe():
return os.path.join(os.path.dirname(os.path.abspath(__file__)), "bpe_simple_vocab_16e6.txt.gz")
@lru_cache()
def bytes_to_unicode():
"""
Returns list of utf-8 byte and a corr... | 4,628 | 33.804511 | 144 | py |
ZeCon | ZeCon-main/CLIP/clip/clip.py | import hashlib
import os
import urllib
import warnings
from typing import Any, Union, List
import torch
from PIL import Image
from torchvision.transforms import Compose, Resize, CenterCrop, ToTensor, Normalize
from tqdm import tqdm
from .model import build_model
from .simple_tokenizer import SimpleTokenizer as _Token... | 8,433 | 36.484444 | 149 | py |
ZeCon | ZeCon-main/CLIP/clip/model.py | from collections import OrderedDict
from typing import Tuple, Union
import numpy as np
import torch
import torch.nn.functional as F
from torch import nn
class Bottleneck(nn.Module):
expansion = 4
def __init__(self, inplanes, planes, stride=1):
super().__init__()
# all conv layers have strid... | 17,242 | 38.822171 | 178 | py |
ZeCon | ZeCon-main/CLIP/clip/__init__.py | from .clip import *
| 20 | 9.5 | 19 | py |
ZeCon | ZeCon-main/CLIP/tests/test_consistency.py | import numpy as np
import pytest
import torch
from PIL import Image
import clip
@pytest.mark.parametrize('model_name', clip.available_models())
def test_consistency(model_name):
device = "cpu"
jit_model, transform = clip.load(model_name, device=device, jit=True)
py_model, _ = clip.load(model_name, device... | 812 | 30.269231 | 73 | py |
ZeCon | ZeCon-main/guided_diffusion/setup.py | from setuptools import setup
setup(
name="guided-diffusion",
py_modules=["guided_diffusion"],
install_requires=["blobfile>=1.0.5", "torch", "tqdm"],
)
| 164 | 19.625 | 58 | py |
ZeCon | ZeCon-main/guided_diffusion/scripts/image_train.py | """
Train a diffusion model on images.
"""
import argparse
from guided_diffusion import dist_util, logger
from guided_diffusion.image_datasets import load_data
from guided_diffusion.resample import create_named_schedule_sampler
from guided_diffusion.script_util import (
model_and_diffusion_defaults,
create_mo... | 2,298 | 26.369048 | 86 | py |
ZeCon | ZeCon-main/guided_diffusion/scripts/image_sample.py | """
Generate a large batch of image samples from a model and save them as a large
numpy array. This can be used to produce samples for FID evaluation.
"""
import argparse
import os
import numpy as np
import torch as th
import torch.distributed as dist
from guided_diffusion import dist_util, logger
from guided_diffus... | 3,398 | 30.183486 | 88 | py |
ZeCon | ZeCon-main/guided_diffusion/scripts/super_res_sample.py | """
Generate a large batch of samples from a super resolution model, given a batch
of samples from a regular model from image_sample.py.
"""
import argparse
import os
import blobfile as bf
import numpy as np
import torch as th
import torch.distributed as dist
from guided_diffusion import dist_util, logger
from guide... | 3,725 | 30.05 | 84 | py |
ZeCon | ZeCon-main/guided_diffusion/scripts/classifier_sample.py | """
Like image_sample.py, but use a noisy image classifier to guide the sampling
process towards more realistic images.
"""
import argparse
import os
import numpy as np
import torch as th
import torch.distributed as dist
import torch.nn.functional as F
from guided_diffusion import dist_util, logger
from guided_diffu... | 4,266 | 31.325758 | 88 | py |
ZeCon | ZeCon-main/guided_diffusion/scripts/classifier_train.py | """
Train a noised image classifier on ImageNet.
"""
import argparse
import os
import blobfile as bf
import torch as th
import torch.distributed as dist
import torch.nn.functional as F
from torch.nn.parallel.distributed import DistributedDataParallel as DDP
from torch.optim import AdamW
from guided_diffusion import ... | 7,313 | 31.220264 | 99 | py |
ZeCon | ZeCon-main/guided_diffusion/scripts/image_nll.py | """
Approximate the bits/dimension for an image model.
"""
import argparse
import os
import numpy as np
import torch.distributed as dist
from guided_diffusion import dist_util, logger
from guided_diffusion.image_datasets import load_data
from guided_diffusion.script_util import (
model_and_diffusion_defaults,
... | 2,934 | 29.257732 | 86 | py |
ZeCon | ZeCon-main/guided_diffusion/scripts/super_res_train.py | """
Train a super-resolution model.
"""
import argparse
import torch.nn.functional as F
from guided_diffusion import dist_util, logger
from guided_diffusion.image_datasets import load_data
from guided_diffusion.resample import create_named_schedule_sampler
from guided_diffusion.script_util import (
sr_model_and_... | 2,695 | 26.232323 | 87 | py |
ZeCon | ZeCon-main/guided_diffusion/datasets/lsun_bedroom.py | """
Convert an LSUN lmdb database into a directory of images.
"""
import argparse
import io
import os
from PIL import Image
import lmdb
import numpy as np
def read_images(lmdb_path, image_size):
env = lmdb.open(lmdb_path, map_size=1099511627776, max_readers=100, readonly=True)
with env.begin(write=False) as... | 1,722 | 30.327273 | 86 | py |
ZeCon | ZeCon-main/guided_diffusion/guided_diffusion/resample.py | from abc import ABC, abstractmethod
import numpy as np
import torch as th
import torch.distributed as dist
def create_named_schedule_sampler(name, diffusion):
"""
Create a ScheduleSampler from a library of pre-defined samplers.
:param name: the name of the sampler.
:param diffusion: the diffusion ob... | 5,689 | 35.709677 | 87 | py |
ZeCon | ZeCon-main/guided_diffusion/guided_diffusion/losses.py | """
Helpers for various likelihood-based losses. These are ported from the original
Ho et al. diffusion models codebase:
https://github.com/hojonathanho/diffusion/blob/1e0dceb3b3495bbe19116a5e1b3596cd0706c543/diffusion_tf/utils.py
"""
import numpy as np
import torch as th
def normal_kl(mean1, logvar1, mean2, logvar... | 2,534 | 31.5 | 109 | py |
ZeCon | ZeCon-main/guided_diffusion/guided_diffusion/image_datasets.py | import math
import random
from PIL import Image
import blobfile as bf
from mpi4py import MPI
import numpy as np
from torch.utils.data import DataLoader, Dataset
def load_data(
*,
data_dir,
batch_size,
image_size,
class_cond=False,
deterministic=False,
random_crop=False,
random_flip=Tr... | 5,930 | 34.303571 | 88 | py |
ZeCon | ZeCon-main/guided_diffusion/guided_diffusion/logger.py | """
Logger copied from OpenAI baselines to avoid extra RL-based dependencies:
https://github.com/openai/baselines/blob/ea25b9e8b234e6ee1bca43083f8f3cf974143998/baselines/logger.py
"""
import os
import sys
import shutil
import os.path as osp
import json
import time
import datetime
import tempfile
import warnings
from c... | 13,979 | 27.185484 | 132 | py |
ZeCon | ZeCon-main/guided_diffusion/guided_diffusion/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(... | 5,020 | 28.362573 | 88 | py |
ZeCon | ZeCon-main/guided_diffusion/guided_diffusion/fp16_util.py | """
Helpers to train with 16-bit precision.
"""
import numpy as np
import torch as th
import torch.nn as nn
from torch._utils import _flatten_dense_tensors, _unflatten_dense_tensors
from . import logger
INITIAL_LOG_LOSS_SCALE = 20.0
def convert_module_to_f16(l):
"""
Convert primitive modules to float16.
... | 7,941 | 32.510549 | 114 | py |
ZeCon | ZeCon-main/guided_diffusion/guided_diffusion/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 (
checkpoint,
conv_nd,
linear,
avg_pool_nd,
zero_module,
normalization,
... | 32,001 | 33.822633 | 124 | py |
ZeCon | ZeCon-main/guided_diffusion/guided_diffusion/script_util.py | import argparse
import inspect
from . import gaussian_diffusion as gd
from .respace import SpacedDiffusion, space_timesteps
from .unet import SuperResModel, UNetModel, EncoderUNetModel
NUM_CLASSES = 1000
# def diffusion_defaults():
# """
# Defaults for image and classifier training.
# """
# return d... | 12,997 | 26.538136 | 88 | py |
ZeCon | ZeCon-main/guided_diffusion/guided_diffusion/gaussian_diffusion.py | """
This code started out as a PyTorch port of Ho et al's diffusion models:
https://github.com/hojonathanho/diffusion/blob/1e0dceb3b3495bbe19116a5e1b3596cd0706c543/diffusion_tf/diffusion_utils_2.py
Docstrings have been added, as well as DDIM sampling and a new collection of beta schedules.
"""
import enum
import math... | 36,586 | 38.130481 | 129 | py |
ZeCon | ZeCon-main/guided_diffusion/guided_diffusion/__init__.py | """
Codebase for "Improved Denoising Diffusion Probabilistic Models".
"""
| 74 | 17.75 | 65 | py |
ZeCon | ZeCon-main/guided_diffusion/guided_diffusion/train_util.py | import copy
import functools
import os
import blobfile as bf
import torch as th
import torch.distributed as dist
from torch.nn.parallel.distributed import DistributedDataParallel as DDP
from torch.optim import AdamW
from . import dist_util, logger
from .fp16_util import MixedPrecisionTrainer
from .nn import update_em... | 10,604 | 34.115894 | 88 | py |
ZeCon | ZeCon-main/guided_diffusion/guided_diffusion/respace.py | import numpy as np
import torch as th
from .gaussian_diffusion import GaussianDiffusion
def space_timesteps(num_timesteps, section_counts):
"""
Create a list of timesteps to use from an original diffusion process,
given the number of timesteps we want to take from equally-sized portions
of the origin... | 5,193 | 39.263566 | 85 | py |
ZeCon | ZeCon-main/guided_diffusion/guided_diffusion/dist_util.py | """
Helpers for distributed training.
"""
import io
import os
import socket
import blobfile as bf
from mpi4py import MPI
import torch as th
import torch.distributed as dist
# Change this to reflect your cluster layout.
# The GPU for a given rank is (rank % GPUS_PER_NODE).
GPUS_PER_NODE = 8
SETUP_RETRY_COUNT = 3
d... | 2,424 | 24.797872 | 87 | py |
ZeCon | ZeCon-main/utils/visualization.py | from pathlib import Path
import matplotlib.pyplot as plt
from typing import Optional, Union
from PIL.Image import Image
def show_edited_masked_image(
title: str,
source_image: Image,
edited_image: Image,
mask: Optional[Image] = None,
path: Optional[Union[str, Path]] = None,
distance: Optional[... | 1,237 | 21.925926 | 46 | py |
ZeCon | ZeCon-main/utils/metrics_accumulator.py | from collections import defaultdict
import numpy as np
class MetricsAccumulator:
def __init__(self) -> None:
self.accumulator = defaultdict(lambda: [])
def update_metric(self, metric_name, metric_value):
self.accumulator[metric_name].append(metric_value)
def print_average_metric(self):
... | 478 | 24.210526 | 58 | py |
Few-NERD | Few-NERD-main/run_supervised.py | # coding=utf-8
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a cop... | 28,048 | 52.940385 | 184 | py |
Few-NERD | Few-NERD-main/train_demo.py | from transformers import BertTokenizer
from util.data_loader import get_loader
from util.framework import FewShotNERFramework
from util.word_encoder import BERTWordEncoder
from model.proto import Proto
from model.nnshot import NNShot
import sys
import torch
from torch import optim, nn
import numpy as np
import json
imp... | 8,044 | 42.02139 | 191 | py |
Few-NERD | Few-NERD-main/util/fewshotsampler.py | import random
class FewshotSampleBase:
'''
Abstract Class
DO NOT USE
Build your own Sample class and inherit from this class
'''
def __init__(self):
self.class_count = {}
def get_class_count(self):
'''
return a dictionary of {class_name:count} in format {any : int}
... | 4,636 | 36.395161 | 137 | py |
Few-NERD | Few-NERD-main/util/word_encoder.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import math
import numpy as np
import os
from torch import optim
from transformers import BertTokenizer, BertModel, BertForMaskedLM, BertForSequenceClassification, RobertaModel, RobertaTokenizer, RobertaForSequenceClassification
class BERTWordEncoder(n... | 1,047 | 42.666667 | 163 | py |
Few-NERD | Few-NERD-main/util/data_loader.py | import torch
import torch.utils.data as data
import os
from .fewshotsampler import FewshotSampler, FewshotSampleBase
import numpy as np
import json
def get_class_name(rawtag):
# get (finegrained) class name
if rawtag.startswith('B-') or rawtag.startswith('I-'):
return rawtag[2:]
else:
retur... | 13,114 | 39.353846 | 162 | py |
Few-NERD | Few-NERD-main/util/viterbi.py | import torch
import torch.nn as nn
START_ID = 0
O_ID = 1
class ViterbiDecoder:
"""
Generalized Viterbi decoding
"""
def __init__(self, n_tag, abstract_transitions, tau):
"""
We assume the batch size is 1, so no need to worry about PAD for now
n_tag: START, O, and I_Xs
... | 4,150 | 38.533333 | 93 | py |
Few-NERD | Few-NERD-main/util/supervised_util.py | # coding=utf-8
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a cop... | 9,352 | 42.300926 | 113 | py |
Few-NERD | Few-NERD-main/util/framework.py | import os
import sklearn.metrics
import numpy as np
import sys
import time
from . import word_encoder
from . import data_loader
import torch
from torch import autograd, optim, nn
from torch.autograd import Variable
from torch.nn import functional as F
# from pytorch_pretrained_bert import BertAdam
from transformers imp... | 22,526 | 38.59051 | 158 | py |
Few-NERD | Few-NERD-main/util/metric.py | class Metrics():
def __init__(self, ignore_index=-100):
'''
word_encoder: Sentence encoder
You need to set self.cost as your own loss function.
'''
self.ignore_index = ignore_index
def __get_class_span_dict__(self, label, is_string=False):
'''
re... | 5,764 | 38.486301 | 107 | py |
Few-NERD | Few-NERD-main/model/nnshot.py | import sys
sys.path.append('..')
import util
import torch
from torch import autograd, optim, nn
from torch.autograd import Variable
from torch.nn import functional as F
class NNShot(util.framework.FewShotNERModel):
def __init__(self,word_encoder, dot=False, ignore_index=-1):
util.framework.FewShotNERM... | 3,140 | 40.88 | 123 | py |
Few-NERD | Few-NERD-main/model/proto.py | import sys
sys.path.append('..')
import util
import torch
from torch import autograd, optim, nn
from torch.autograd import Variable
from torch.nn import functional as F
class Proto(util.framework.FewShotNERModel):
def __init__(self,word_encoder, dot=False, ignore_index=-1):
util.framework.FewShotNERMo... | 3,166 | 39.088608 | 124 | py |
pycbc | pycbc-master/setup.py | #!/usr/bin/env python
# Copyright (C) 2012 Alex Nitz, Duncan Brown, Andrew Miller, Josh Willis
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# op... | 10,715 | 31.18018 | 111 | py |
pycbc | pycbc-master/tools/benchmarking/absolute_times.py | #!/usr/bin/env python
import sys
try:
tottime = float(sys.argv[1])
except:
print("usage: %s total_time_in_seconds" % sys.argv[0])
print()
print("Typical use case is: ")
print(" gprof2dot.py -f pstats profile_file | %s total_time_in_seconds | dot -Tpng -o output.png" % sys.argv[0])
sys.exit(... | 822 | 23.939394 | 118 | py |
pycbc | pycbc-master/tools/timing/fft_perf.py | #!/usr/bin/python
from pycbc.scheme import *
from pycbc.types import *
from pycbc.fft import *
import pycbc
from optparse import OptionParser
import gc
parser = OptionParser()
parser.add_option('--scheme','-s', type = 'choice',
choices = ('cpu','cuda','opencl'),
default = 'cpu'... | 2,935 | 33.139535 | 122 | py |
pycbc | pycbc-master/tools/timing/wav_perf.py | #!/usr/bin/python
from pycbc.scheme import *
from pycbc.types import *
from pycbc.waveform import *
import pycbc
from optparse import OptionParser
import gc
parser = OptionParser()
parser.add_option('--scheme','-s', type = 'choice',
choices = ('cpu','cuda','opencl'),
default = ... | 2,472 | 31.973333 | 119 | py |
pycbc | pycbc-master/tools/timing/match_perf.py | #!/usr/bin/env python
from pycbc.scheme import *
from pycbc.types import *
from pycbc.filter import *
from pycbc.psd import *
import pycbc
from math import log
import numpy
import numpy.random
from optparse import OptionParser
import gc
parser = OptionParser()
import logging
logging.basicConfig(format='%(asctime)s : %... | 3,154 | 27.169643 | 96 | py |
pycbc | pycbc-master/tools/timing/arr_perf.py | #!/usr/bin/python
from pycbc.scheme import *
from pycbc.types import *
from pycbc.fft import *
from pycbc.events import *
import pycbc
from optparse import OptionParser
from math import sin, log
import gc
parser = OptionParser()
parser.add_option('--scheme','-s', type = 'choice',
choices = ('cpu',... | 2,286 | 22.10101 | 96 | py |
pycbc | pycbc-master/tools/timing/correlate_perf.py | from pycbc.filter import correlate
from pycbc.filter.matchedfilter import BatchCorrelator, Correlator
from pycbc.types import zeros, complex64, complex128, Array
from time import time
from numpy.random import uniform
niter = 2000
for N in [2**10, 2**15, 2**18]:
a = zeros(N, dtype=complex64)
a.data += uniform(... | 1,489 | 26.592593 | 82 | py |
pycbc | pycbc-master/tools/timing/banksim/banksim.py | #! /usr/bin/env python
# Copyright (C) 2012 Alex Nitz
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 3 of the License, or (at your
# option) any later version.
#
# This program ... | 12,160 | 40.64726 | 177 | py |
pycbc | pycbc-master/tools/einsteinathome/check_GW150914_detection.py | # Read a pycbc_inspiral HDF5 trigger file and check that it contains triggers
# compatible with GW150914
# 2016 Tito Dal Canton
import sys
import h5py
import numpy as np
# GW150914 params from my run
# https://www.atlas.aei.uni-hannover.de/~tito/LSC/er8/er8b_c00_1.2.0_run1
gw150914_time = 1126259462.4
gw150914_snr =... | 1,290 | 32.973684 | 77 | py |
pycbc | pycbc-master/tools/static/runtime-tkinter.py | import os, sys
d = os.path.join(sys._MEIPASS, 'tcl')
if not os.path.exists(d):
os.makedirs(d)
d = os.path.join(sys._MEIPASS, 'tk')
if not os.path.exists(d):
os.makedirs(d)
| 180 | 21.625 | 37 | py |
pycbc | pycbc-master/tools/static/runtime-scipy.py | import os, distutils.sysconfig, sys, os.path
import scipy.misc
import scipy, fnmatch
def find(pattern, path):
result = []
for root, dirs, files in os.walk(path):
for name in files:
if fnmatch.fnmatch(name, pattern):
result.append(os.path.join(root, name))
return result
... | 734 | 29.625 | 60 | py |
pycbc | pycbc-master/tools/static/hooks/hook-pycbc.py | #-----------------------------------------------------------------------------
# Copyright (c) 2013, PyInstaller Development Team.
#
# Distributed under the terms of the GNU General Public License with exception
# for distributing bootloader.
#
# The full license is in the file COPYING.txt, distributed with this softwa... | 3,570 | 35.070707 | 84 | py |
pycbc | pycbc-master/pycbc/boundaries.py | # Copyright (C) 2016 Collin Capano
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 3 of the License, or (at your
# option) any later version.
#
# This program is distributed in t... | 15,026 | 34.357647 | 79 | py |
pycbc | pycbc-master/pycbc/pnutils.py | # Copyright (C) 2012 Alex Nitz
#
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 3 of the License, or (at your
# option) any later version.
#
# This program is distributed in t... | 40,056 | 34.990117 | 153 | py |
pycbc | pycbc-master/pycbc/_version_helper.py | # Based on generateGitID.sh by Reinhard Prix
#
# Copyright (C) 2009,2010, Adam Mercer <adam.mercer@ligo.org>
# Copyright (C) 2009,2010, Nickolas Fotopoulos <nvf@gravity.phys.uwm.edu>
# Copyright (C) 2008,2009, John T. Whelan <john.whelan@ligo.org>
# Copyright (C) 2008, Reinhard Prix <reinhard.ligo.org>
#
# This program... | 6,380 | 29.5311 | 80 | py |
pycbc | pycbc-master/pycbc/conversions.py | # Copyright (C) 2017 Collin Capano, Christopher M. Biwer, Duncan Brown,
# and Steven Reyes
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 3 of the License, or (at your
# option)... | 62,478 | 34.239143 | 79 | py |
pycbc | pycbc-master/pycbc/cosmology.py | # Copyright (C) 2017 Collin Capano
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 3 of the License, or (at your
# option) any later version.
#
# This program is distributed in t... | 23,038 | 39.137631 | 79 | py |
pycbc | pycbc-master/pycbc/rate.py | import numpy
import bisect
from . import bin_utils
def integral_element(mu, pdf):
'''
Returns an array of elements of the integrand dP = p(mu) dmu
for a density p(mu) defined at sample values mu ; samples need
not be equally spaced. Uses a simple trapezium rule.
Number of dP elements is 1 - (numb... | 12,540 | 35.9941 | 81 | py |
pycbc | pycbc-master/pycbc/mchirp_area.py | # Module with utilities for estimating candidate events source probabilities
# Initial code by A. Curiel Barroso, August 2019
# Modified by V. Villa-Ortega, January 2020, March 2021
"""Functions to compute the area corresponding to different CBC on the m1 & m2
plane when given a central mchirp value and uncertainty.
I... | 13,070 | 42.57 | 79 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.