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 |
|---|---|---|---|---|---|---|
OpusTools | OpusTools-master/opustools_pkg/opustools/readopusdata.py | import urllib.request
import sqlite3
import logging
import os
from ruamel.yaml import YAML, scanner, reader
def read_url(url):
return urllib.request.urlopen(url).read().decode('utf-8').split('\n')
def read_url_yaml(url, yaml):
raw = urllib.request.urlopen(url).read().decode('utf-8')
data = yaml.load(raw)... | 9,987 | 41.502128 | 163 | py |
OpusTools | OpusTools-master/opustools_pkg/opustools/opus_get.py | import urllib.request
import json
import argparse
import sys
import os.path
import gzip
from .db_operations import DbOperations
class OpusGet:
def __init__(self, source=None, target=None, directory=None,
release='latest', preprocess='xml', list_resources=False,
list_languages=False, list_... | 7,854 | 35.03211 | 136 | py |
OpusTools | OpusTools-master/opustools_pkg/opustools/opus_langid.py | import os
import shutil
import zipfile
import argparse
import cgi
import tempfile
import re
import pycld2
from langid.langid import LanguageIdentifier, model
identifier = LanguageIdentifier.from_modelstring(model, norm_probs=True)
from .parse.block_parser import Block, BlockParser
class LanguageIdAdder(BlockParser):... | 7,070 | 37.851648 | 110 | py |
OpusTools | OpusTools-master/opustools_pkg/opustools/util.py | """Utility functions"""
import bz2
import gzip
def file_open(filename, mode='r', encoding='utf8'):
"""Open file with implicit gzip/bz2 support
Uses text mode by default regardless of the compression.
"""
if filename.endswith('.bz2'):
if mode in {'r', 'w', 'x', 'a'}:
mode += 't'
... | 603 | 26.454545 | 64 | py |
OpusTools | OpusTools-master/opustools_pkg/opustools/__init__.py | from .opus_cat import OpusCat
from .opus_read import OpusRead
from .opus_get import OpusGet
from .db_operations import DbOperations
from .readopusdata import update_db
| 169 | 23.285714 | 39 | py |
OpusTools | OpusTools-master/opustools_pkg/opustools/db_operations.py | import os
import sqlite3
class DbOperations:
def __init__(self, db_file=None):
if db_file:
self.db_file=db_file
else:
self.db_file = os.environ.get('OPUSAPI_DB')
def clean_up_parameters(self, parameters):
remove = []
valid_keys = ['corpus', 'id', 'late... | 5,063 | 40.170732 | 229 | py |
OpusTools | OpusTools-master/opustools_pkg/opustools/parse/alignment_parser.py | from .block_parser import BlockParser, BlockParserError
class AlignmentParserError(Exception):
def __init__(self, message):
"""Raise error when alignment parsing fails.
Arguments:
message -- Error message to be printed
"""
self.message = message
def range_filter_type(src_... | 4,973 | 34.528571 | 102 | py |
OpusTools | OpusTools-master/opustools_pkg/opustools/parse/sentence_parser.py | from .block_parser import BlockParser, BlockParserError
class SentenceParserError(Exception):
def __init__(self, message):
"""Raise error when sentence parsing fails.
Arguments:
message -- Error message to be printed
"""
self.message = message
def parse_type(preprocess, p... | 7,082 | 33.891626 | 85 | py |
OpusTools | OpusTools-master/opustools_pkg/opustools/parse/block_parser.py | import xml.parsers.expat
from ..util import file_open
class BlockParserError(Exception):
def __init__(self, message):
"""Raise error when block parsing fails.
Arguments:
message -- Error message to be printed
"""
self.message = message
class Block:
def __init__(self,... | 4,605 | 33.118519 | 98 | py |
OpusTools | OpusTools-master/opustools_pkg/opustools/parse/__init__.py | 0 | 0 | 0 | py | |
cGAN-KD | cGAN-KD-main/UTKFace/baseline_cnn.py | print("\n===================================================================================================")
import os
import argparse
import shutil
import timeit
import torch
import torchvision
import torchvision.transforms as transforms
import numpy as np
import torch.nn as nn
import torch.backends.cudnn as cudnn
... | 9,981 | 37.099237 | 433 | py |
cGAN-KD | cGAN-KD-main/UTKFace/eval_metrics.py | """
Compute
Inception Score (IS),
Frechet Inception Discrepency (FID), ref "https://github.com/mseitzer/pytorch-fid/blob/master/fid_score.py"
Maximum Mean Discrepancy (MMD)
for a set of fake images
use numpy array
Xr: high-level features for real images; nr by d array
Yr: labels for real images
Xg: high-level features... | 6,666 | 33.365979 | 143 | py |
cGAN-KD | cGAN-KD-main/UTKFace/train_net_for_label_embed.py |
import torch
import torch.nn as nn
from torchvision.utils import save_image
import numpy as np
import os
import timeit
from PIL import Image
### horizontally flip images
def hflip_images(batch_images):
uniform_threshold = np.random.uniform(0,1,len(batch_images))
indx_gt = np.where(uniform_threshold>0.5)[0]
... | 10,789 | 39.111524 | 262 | py |
cGAN-KD | cGAN-KD-main/UTKFace/DiffAugment_pytorch.py | # Differentiable Augmentation for Data-Efficient GAN Training
# Shengyu Zhao, Zhijian Liu, Ji Lin, Jun-Yan Zhu, and Song Han
# https://arxiv.org/pdf/2006.10738
import torch
import torch.nn.functional as F
def DiffAugment(x, policy='', channels_first=True):
if policy:
if not channels_first:
x ... | 3,025 | 38.298701 | 110 | py |
cGAN-KD | cGAN-KD-main/UTKFace/opts.py | import argparse
'''
Options for Some Baseline CNN Training
'''
def cnn_opts():
parser = argparse.ArgumentParser()
''' Overall settings '''
parser.add_argument('--root_path', type=str, default='')
parser.add_argument('--data_path', type=str, default='')
parser.add_argument('--fake_data_path', t... | 9,734 | 55.929825 | 157 | py |
cGAN-KD | cGAN-KD-main/UTKFace/generate_synthetic_data.py | print("\n===================================================================================================")
import argparse
import copy
import gc
import numpy as np
import matplotlib.pyplot as plt
plt.switch_backend('agg')
import matplotlib as mpl
import h5py
import os
import random
from tqdm import tqdm, trange
im... | 34,527 | 45.659459 | 545 | py |
cGAN-KD | cGAN-KD-main/UTKFace/utils.py | """
Some helpful functions
"""
import numpy as np
import torch
import torch.nn as nn
import torchvision
import matplotlib.pyplot as plt
import matplotlib as mpl
from torch.nn import functional as F
import sys
import PIL
from PIL import Image
# ### import my stuffs ###
# from models import *
# ######################... | 5,139 | 29.595238 | 143 | py |
cGAN-KD | cGAN-KD-main/UTKFace/train_cdre.py | '''
Functions for Training Class-conditional Density-ratio model
'''
import torch
import torch.nn as nn
import numpy as np
import os
import timeit
import gc
from utils import *
from opts import gen_synth_data_opts
''' Settings '''
args = gen_synth_data_opts()
# some parameters in the opts
dim_gan = args.gan_dim_g... | 13,429 | 45.958042 | 323 | py |
cGAN-KD | cGAN-KD-main/UTKFace/test_infer_speed.py | import os
import argparse
import shutil
import timeit
import torch
import torchvision
import torchvision.transforms as transforms
import numpy as np
import torch.nn as nn
import torch.backends.cudnn as cudnn
import random
import matplotlib.pyplot as plt
import matplotlib as mpl
from torch import autograd
from torchvisi... | 3,059 | 30.22449 | 143 | py |
cGAN-KD | cGAN-KD-main/UTKFace/train_cnn.py | ''' For CNN training and testing. '''
import os
import timeit
import torch
import torch.nn as nn
import numpy as np
from torch.nn import functional as F
## horizontal flipping
def hflip_images(batch_images):
''' for numpy arrays '''
uniform_threshold = np.random.uniform(0,1,len(batch_images))
indx_gt = n... | 6,160 | 37.748428 | 249 | py |
cGAN-KD | cGAN-KD-main/UTKFace/train_sparseAE.py |
import torch
import torch.nn as nn
from torchvision.utils import save_image
import numpy as np
import os
import timeit
from utils import SimpleProgressBar
from opts import gen_synth_data_opts
''' Settings '''
args = gen_synth_data_opts()
# some parameters in the opts
epochs = args.dre_presae_epochs
base_lr = args.d... | 7,789 | 41.802198 | 328 | py |
cGAN-KD | cGAN-KD-main/UTKFace/train_ccgan.py | import torch
import numpy as np
import os
import timeit
from PIL import Image
from torchvision.utils import save_image
from utils import *
from opts import gen_synth_data_opts
from DiffAugment_pytorch import DiffAugment
''' Settings '''
args = gen_synth_data_opts()
# some parameters in opts
loss_type = args.gan_los... | 13,893 | 43.248408 | 261 | py |
cGAN-KD | cGAN-KD-main/UTKFace/models/shufflenetv2.py | '''ShuffleNetV2 in PyTorch.
See the paper "ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" for more details.
'''
import torch
import torch.nn as nn
import torch.nn.functional as F
class ShuffleBlock(nn.Module):
def __init__(self, groups=2):
super(ShuffleBlock, self).__init__()
... | 6,654 | 32.442211 | 107 | py |
cGAN-KD | cGAN-KD-main/UTKFace/models/SAGAN.py | '''
SAGAN arch
Adapted from https://github.com/voletiv/self-attention-GAN-pytorch/blob/master/sagan_models.py
'''
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.utils import spectral_norm
from torch.nn.init import xavier_uniform_
def init_weights(m):
if t... | 10,076 | 33.748276 | 129 | py |
cGAN-KD | cGAN-KD-main/UTKFace/models/efficientnet.py | '''EfficientNet in PyTorch.
Paper: "EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks".
Reference: https://github.com/keras-team/keras-applications/blob/master/keras_applications/efficientnet.py
'''
import torch
import torch.nn as nn
import torch.nn.functional as F
def swish(x):
return x * ... | 5,970 | 31.275676 | 106 | py |
cGAN-KD | cGAN-KD-main/UTKFace/models/ResNet_embed.py | '''
ResNet-based model to map an image from pixel space to a features space.
Need to be pretrained on the dataset.
if isometric_map = True, there is an extra step (elf.classifier_1 = nn.Linear(512, 32*32*3)) to increase the dimension of the feature map from 512 to 32*32*3. This selection is for desity-ratio estimation... | 6,302 | 32.526596 | 222 | py |
cGAN-KD | cGAN-KD-main/UTKFace/models/autoencoder_extract.py | import torch
from torch import nn
class encoder_extract(nn.Module):
def __init__(self, dim_bottleneck=64*64*3, ch=32):
super(encoder_extract, self).__init__()
self.ch = ch
self.dim_bottleneck = dim_bottleneck
self.conv = nn.Sequential(
nn.Conv2d(3, ch, kernel_size=4, ... | 5,073 | 30.320988 | 89 | py |
cGAN-KD | cGAN-KD-main/UTKFace/models/resnet.py | from __future__ import absolute_import
'''Resnet for cifar dataset.
Ported form
https://github.com/facebook/fb.resnet.torch
and
https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py
(c) YANG, Wei
'''
import torch.nn as nn
import torch.nn.functional as F
import math
__all__ = ['resnet']
def con... | 6,698 | 29.175676 | 116 | py |
cGAN-KD | cGAN-KD-main/UTKFace/models/vgg.py | '''VGG11/13/16/19 in Pytorch.'''
import torch
import torch.nn as nn
from torch.autograd import Variable
cfg = {
'VGG8': [64, 'M', 128, 'M', 256, 'M', 512, 'M', 512, 'M'],
'VGG11': [64, 'M', 128, 'M', 256, 256, 'M', 512, 512, 'M', 512, 512, 'M'],
'VGG13': [64, 64, 'M', 128, 128, 'M', 256, 256, 'M', 512, 5... | 2,119 | 24.853659 | 117 | py |
cGAN-KD | cGAN-KD-main/UTKFace/models/shufflenetv1.py | '''ShuffleNet in PyTorch.
See the paper "ShuffleNet: An Extremely Efficient Convolutional Neural Network for Mobile Devices" for more details.
To fit 128x128 images, I modified the first conv layer and add an extra max_pool2d after it (Following Table 5 of "ShuffleNet V2: Practical Guidelines for Efficient CNN Archite... | 4,440 | 33.968504 | 190 | py |
cGAN-KD | cGAN-KD-main/UTKFace/models/SNGAN.py | '''
https://github.com/christiancosgrove/pytorch-spectral-normalization-gan
chainer: https://github.com/pfnet-research/sngan_projection
'''
# ResNet generator and discriminator
import torch
from torch import nn
import torch.nn.functional as F
# from spectral_normalization import SpectralNorm
import numpy as np
from ... | 8,633 | 34.240816 | 96 | py |
cGAN-KD | cGAN-KD-main/UTKFace/models/densenet.py | '''DenseNet in PyTorch.
To fit 128x128 images, I modified the first conv layer and add an extra max_pool2d after it.
'''
import math
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
NC=3
IMG_SIZE = 64
class Bottleneck(nn.Module):
def __init__(self, in_plan... | 4,332 | 31.335821 | 96 | py |
cGAN-KD | cGAN-KD-main/UTKFace/models/resnetv2.py | '''
codes are based on
@article{
zhang2018mixup,
title={mixup: Beyond Empirical Risk Minimization},
author={Hongyi Zhang, Moustapha Cisse, Yann N. Dauphin, David Lopez-Paz},
journal={International Conference on Learning Representations},
year={2018},
url={https://openreview.net/forum?id=r1Ddp1-Rb},
}
'''
import torch... | 4,623 | 30.455782 | 102 | py |
cGAN-KD | cGAN-KD-main/UTKFace/models/cDR_MLP.py | '''
Conditional Density Ration Estimation via Multilayer Perceptron
Multilayer Perceptron : trained to model density ratio in a feature space
Its input is the output of a pretrained Deep CNN, say ResNet-34
'''
import torch
import torch.nn as nn
IMG_SIZE=64
NC=3
cfg = {"MLP3": [512,256,128],
"MLP5": [1024... | 2,157 | 29.394366 | 95 | py |
cGAN-KD | cGAN-KD-main/UTKFace/models/__init__.py | from .autoencoder_extract import *
from .cDR_MLP import cDR_MLP
from .SNGAN import SNGAN_Generator, SNGAN_Discriminator
from .SAGAN import SAGAN_Generator, SAGAN_Discriminator
from .shufflenetv1 import ShuffleV1
from .shufflenetv2 import ShuffleV2
from .mobilenet import mobilenet_v2
from .efficientnet import EfficientN... | 1,423 | 32.116279 | 83 | py |
cGAN-KD | cGAN-KD-main/UTKFace/models/mobilenet.py | import torch
from torch import nn
# from .utils import load_state_dict_from_url
try:
from torch.hub import load_state_dict_from_url
except ImportError:
from torch.utils.model_zoo import load_url as load_state_dict_from_url
__all__ = ['MobileNetV2', 'mobilenet_v2']
model_urls = {
'mobilenet_v2': 'https:/... | 7,609 | 35.238095 | 116 | py |
cGAN-KD | cGAN-KD-main/UTKFace/models/wrn.py | import math
import torch
import torch.nn as nn
import torch.nn.functional as F
"""
Original Author: Wei Yang
"""
__all__ = ['wrn']
class BasicBlock(nn.Module):
def __init__(self, in_planes, out_planes, stride, dropRate=0.0):
super(BasicBlock, self).__init__()
self.bn1 = nn.BatchNorm2d(in_planes)... | 4,962 | 32.308725 | 116 | py |
cGAN-KD | cGAN-KD-main/SteeringAngle/baseline_cnn.py | print("\n===================================================================================================")
import os
import argparse
import shutil
import timeit
import torch
import torchvision
import torchvision.transforms as transforms
import numpy as np
import torch.nn as nn
import torch.backends.cudnn as cudnn
... | 8,254 | 36.017937 | 433 | py |
cGAN-KD | cGAN-KD-main/SteeringAngle/eval_metrics.py | """
Compute
Inception Score (IS),
Frechet Inception Discrepency (FID), ref "https://github.com/mseitzer/pytorch-fid/blob/master/fid_score.py"
Maximum Mean Discrepancy (MMD)
for a set of fake images
use numpy array
Xr: high-level features for real images; nr by d array
Yr: labels for real images
Xg: high-level features... | 6,666 | 33.365979 | 143 | py |
cGAN-KD | cGAN-KD-main/SteeringAngle/train_net_for_label_embed.py |
import torch
import torch.nn as nn
from torchvision.utils import save_image
import numpy as np
import os
import timeit
from PIL import Image
## normalize images
def normalize_images(batch_images):
batch_images = batch_images/255.0
batch_images = (batch_images - 0.5)/0.5
return batch_images
#------------... | 10,156 | 38.675781 | 262 | py |
cGAN-KD | cGAN-KD-main/SteeringAngle/DiffAugment_pytorch.py | # Differentiable Augmentation for Data-Efficient GAN Training
# Shengyu Zhao, Zhijian Liu, Ji Lin, Jun-Yan Zhu, and Song Han
# https://arxiv.org/pdf/2006.10738
import torch
import torch.nn.functional as F
def DiffAugment(x, policy='', channels_first=True):
if policy:
if not channels_first:
x ... | 3,025 | 38.298701 | 110 | py |
cGAN-KD | cGAN-KD-main/SteeringAngle/opts.py | import argparse
'''
Options for Some Baseline CNN Training
'''
def cnn_opts():
parser = argparse.ArgumentParser()
''' Overall settings '''
parser.add_argument('--root_path', type=str, default='')
parser.add_argument('--data_path', type=str, default='')
parser.add_argument('--fake_data_path', t... | 9,154 | 54.823171 | 157 | py |
cGAN-KD | cGAN-KD-main/SteeringAngle/generate_synthetic_data.py | print("\n===================================================================================================")
import argparse
import copy
import gc
import numpy as np
import matplotlib.pyplot as plt
plt.switch_backend('agg')
import matplotlib as mpl
import h5py
import os
import random
from tqdm import tqdm, trange
im... | 34,078 | 45.940771 | 545 | py |
cGAN-KD | cGAN-KD-main/SteeringAngle/utils.py | """
Some helpful functions
"""
import numpy as np
import torch
import torch.nn as nn
import torchvision
import matplotlib.pyplot as plt
import matplotlib as mpl
from torch.nn import functional as F
import sys
import PIL
from PIL import Image
# ### import my stuffs ###
# from models import *
# ######################... | 5,139 | 29.595238 | 143 | py |
cGAN-KD | cGAN-KD-main/SteeringAngle/train_cdre.py | '''
Functions for Training Class-conditional Density-ratio model
'''
import torch
import torch.nn as nn
import numpy as np
import os
import timeit
import gc
from utils import *
from opts import gen_synth_data_opts
''' Settings '''
args = gen_synth_data_opts()
# some parameters in the opts
dim_gan = args.gan_dim_g... | 12,763 | 46.099631 | 323 | py |
cGAN-KD | cGAN-KD-main/SteeringAngle/train_cnn.py | ''' For CNN training and testing. '''
import os
import timeit
import torch
import torch.nn as nn
import numpy as np
from torch.nn import functional as F
## normalize images
def normalize_images(batch_images):
batch_images = batch_images/255.0
batch_images = (batch_images - 0.5)/0.5
return batch_images
'... | 5,752 | 37.353333 | 249 | py |
cGAN-KD | cGAN-KD-main/SteeringAngle/train_sparseAE.py |
import torch
import torch.nn as nn
from torchvision.utils import save_image
import numpy as np
import os
import timeit
from utils import SimpleProgressBar
from opts import gen_synth_data_opts
''' Settings '''
args = gen_synth_data_opts()
# some parameters in the opts
epochs = args.dre_presae_epochs
base_lr = args.d... | 7,406 | 41.815029 | 328 | py |
cGAN-KD | cGAN-KD-main/SteeringAngle/train_ccgan.py | import torch
import numpy as np
import os
import timeit
from PIL import Image
from torchvision.utils import save_image
from utils import *
from opts import gen_synth_data_opts
from DiffAugment_pytorch import DiffAugment
''' Settings '''
args = gen_synth_data_opts()
# some parameters in opts
loss_type = args.gan_los... | 13,362 | 43.395349 | 261 | py |
cGAN-KD | cGAN-KD-main/SteeringAngle/models/shufflenetv2.py | '''ShuffleNetV2 in PyTorch.
See the paper "ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" for more details.
'''
import torch
import torch.nn as nn
import torch.nn.functional as F
class ShuffleBlock(nn.Module):
def __init__(self, groups=2):
super(ShuffleBlock, self).__init__()
... | 6,654 | 32.442211 | 107 | py |
cGAN-KD | cGAN-KD-main/SteeringAngle/models/SAGAN.py | '''
SAGAN arch
Adapted from https://github.com/voletiv/self-attention-GAN-pytorch/blob/master/sagan_models.py
'''
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.utils import spectral_norm
from torch.nn.init import xavier_uniform_
def init_weights(m):
if t... | 10,076 | 33.748276 | 129 | py |
cGAN-KD | cGAN-KD-main/SteeringAngle/models/efficientnet.py | '''EfficientNet in PyTorch.
Paper: "EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks".
Reference: https://github.com/keras-team/keras-applications/blob/master/keras_applications/efficientnet.py
'''
import torch
import torch.nn as nn
import torch.nn.functional as F
def swish(x):
return x * ... | 5,970 | 31.275676 | 106 | py |
cGAN-KD | cGAN-KD-main/SteeringAngle/models/ResNet_embed.py | '''
ResNet-based model to map an image from pixel space to a features space.
Need to be pretrained on the dataset.
if isometric_map = True, there is an extra step (elf.classifier_1 = nn.Linear(512, 32*32*3)) to increase the dimension of the feature map from 512 to 32*32*3. This selection is for desity-ratio estimation... | 6,302 | 32.526596 | 222 | py |
cGAN-KD | cGAN-KD-main/SteeringAngle/models/autoencoder_extract.py | import torch
from torch import nn
class encoder_extract(nn.Module):
def __init__(self, dim_bottleneck=64*64*3, ch=32):
super(encoder_extract, self).__init__()
self.ch = ch
self.dim_bottleneck = dim_bottleneck
self.conv = nn.Sequential(
nn.Conv2d(3, ch, kernel_size=4, ... | 5,073 | 30.320988 | 89 | py |
cGAN-KD | cGAN-KD-main/SteeringAngle/models/resnet.py | from __future__ import absolute_import
'''Resnet for cifar dataset.
Ported form
https://github.com/facebook/fb.resnet.torch
and
https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py
(c) YANG, Wei
'''
import torch.nn as nn
import torch.nn.functional as F
import math
__all__ = ['resnet']
def con... | 6,698 | 29.175676 | 116 | py |
cGAN-KD | cGAN-KD-main/SteeringAngle/models/vgg.py | '''VGG11/13/16/19 in Pytorch.'''
import torch
import torch.nn as nn
from torch.autograd import Variable
cfg = {
'VGG8': [64, 'M', 128, 'M', 256, 'M', 512, 'M', 512, 'M'],
'VGG11': [64, 'M', 128, 'M', 256, 256, 'M', 512, 512, 'M', 512, 512, 'M'],
'VGG13': [64, 64, 'M', 128, 128, 'M', 256, 256, 'M', 512, 5... | 2,119 | 24.853659 | 117 | py |
cGAN-KD | cGAN-KD-main/SteeringAngle/models/shufflenetv1.py | '''ShuffleNet in PyTorch.
See the paper "ShuffleNet: An Extremely Efficient Convolutional Neural Network for Mobile Devices" for more details.
To fit 128x128 images, I modified the first conv layer and add an extra max_pool2d after it (Following Table 5 of "ShuffleNet V2: Practical Guidelines for Efficient CNN Archite... | 4,440 | 33.968504 | 190 | py |
cGAN-KD | cGAN-KD-main/SteeringAngle/models/SNGAN.py | '''
https://github.com/christiancosgrove/pytorch-spectral-normalization-gan
chainer: https://github.com/pfnet-research/sngan_projection
'''
# ResNet generator and discriminator
import torch
from torch import nn
import torch.nn.functional as F
# from spectral_normalization import SpectralNorm
import numpy as np
from ... | 8,633 | 34.240816 | 96 | py |
cGAN-KD | cGAN-KD-main/SteeringAngle/models/densenet.py | '''DenseNet in PyTorch.
To fit 128x128 images, I modified the first conv layer and add an extra max_pool2d after it.
'''
import math
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
NC=3
IMG_SIZE = 64
class Bottleneck(nn.Module):
def __init__(self, in_plan... | 4,332 | 31.335821 | 96 | py |
cGAN-KD | cGAN-KD-main/SteeringAngle/models/resnetv2.py | '''
codes are based on
@article{
zhang2018mixup,
title={mixup: Beyond Empirical Risk Minimization},
author={Hongyi Zhang, Moustapha Cisse, Yann N. Dauphin, David Lopez-Paz},
journal={International Conference on Learning Representations},
year={2018},
url={https://openreview.net/forum?id=r1Ddp1-Rb},
}
'''
import torch... | 4,623 | 30.455782 | 102 | py |
cGAN-KD | cGAN-KD-main/SteeringAngle/models/cDR_MLP.py | '''
Conditional Density Ration Estimation via Multilayer Perceptron
Multilayer Perceptron : trained to model density ratio in a feature space
Its input is the output of a pretrained Deep CNN, say ResNet-34
'''
import torch
import torch.nn as nn
IMG_SIZE=64
NC=3
cfg = {"MLP3": [512,256,128],
"MLP5": [1024... | 2,157 | 29.394366 | 95 | py |
cGAN-KD | cGAN-KD-main/SteeringAngle/models/__init__.py | from .autoencoder_extract import *
from .cDR_MLP import cDR_MLP
from .SNGAN import SNGAN_Generator, SNGAN_Discriminator
from .SAGAN import SAGAN_Generator, SAGAN_Discriminator
from .shufflenetv1 import ShuffleV1
from .shufflenetv2 import ShuffleV2
from .mobilenet import mobilenet_v2
from .efficientnet import EfficientN... | 1,423 | 32.116279 | 83 | py |
cGAN-KD | cGAN-KD-main/SteeringAngle/models/mobilenet.py | import torch
from torch import nn
# from .utils import load_state_dict_from_url
try:
from torch.hub import load_state_dict_from_url
except ImportError:
from torch.utils.model_zoo import load_url as load_state_dict_from_url
__all__ = ['MobileNetV2', 'mobilenet_v2']
model_urls = {
'mobilenet_v2': 'https:/... | 7,609 | 35.238095 | 116 | py |
cGAN-KD | cGAN-KD-main/SteeringAngle/models/wrn.py | import math
import torch
import torch.nn as nn
import torch.nn.functional as F
"""
Original Author: Wei Yang
"""
__all__ = ['wrn']
class BasicBlock(nn.Module):
def __init__(self, in_planes, out_planes, stride, dropRate=0.0):
super(BasicBlock, self).__init__()
self.bn1 = nn.BatchNorm2d(in_planes)... | 4,962 | 32.308725 | 116 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/make_fake_datasets/main.py | print("\n ===================================================================================================")
#----------------------------------------
import argparse
import os
import timeit
import torch
import torchvision
import torchvision.transforms as transforms
import numpy as np
import torch.nn as nn
import t... | 34,203 | 49.3 | 548 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/make_fake_datasets/eval_metrics.py | """
Compute
Inception Score (IS),
Frechet Inception Discrepency (FID), ref "https://github.com/mseitzer/pytorch-fid/blob/master/fid_score.py"
Maximum Mean Discrepancy (MMD)
for a set of fake images
use numpy array
Xr: high-level features for real images; nr by d array
Yr: labels for real images
Xg: high-level features... | 7,055 | 33.758621 | 140 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/make_fake_datasets/opts.py | import argparse
def gen_synth_data_opts():
parser = argparse.ArgumentParser()
''' Overall settings '''
parser.add_argument('--root_path', type=str, default='')
parser.add_argument('--data_path', type=str, default='')
parser.add_argument('--eval_ckpt_path', type=str, default='')
parser.add_arg... | 4,778 | 57.280488 | 131 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/make_fake_datasets/utils.py | import numpy as np
import torch
import torch.nn as nn
import torchvision
import matplotlib.pyplot as plt
import matplotlib as mpl
from torch.nn import functional as F
import sys
import PIL
from PIL import Image
### import my stuffs ###
from models import *
# ##########################################################... | 5,464 | 30.959064 | 143 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/make_fake_datasets/train_cdre.py | '''
Functions for Training Class-conditional Density-ratio model
'''
import torch
import torch.nn as nn
import numpy as np
import os
import timeit
from utils import SimpleProgressBar
from opts import gen_synth_data_opts
''' Settings '''
args = gen_synth_data_opts()
# training function
def train_cdre(trainloader... | 5,355 | 35.435374 | 189 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/make_fake_datasets/train_cnn.py | ''' For CNN training and testing. '''
import os
import timeit
import torch
import torch.nn as nn
import numpy as np
from torch.nn import functional as F
def denorm(x, means, stds):
'''
x: torch tensor
means: means for normalization
stds: stds for normalization
'''
x_ch0 = torch.unsqueeze(x[:... | 6,774 | 42.152866 | 296 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/make_fake_datasets/models/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
from models import layers
# import layers
# from sync_batchnorm import SynchronizedBatchNorm2d as SyncBatchNorm2d... | 23,873 | 42.25 | 126 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/make_fake_datasets/models/efficientnet.py | '''EfficientNet in PyTorch.
Paper: "EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks".
Reference: https://github.com/keras-team/keras-applications/blob/master/keras_applications/efficientnet.py
'''
import torch
import torch.nn as nn
import torch.nn.functional as F
def swish(x):
return x * ... | 6,221 | 32.272727 | 106 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/make_fake_datasets/models/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
from models import layers
# import layers
# from sync_batchnorm import SynchronizedBatchNorm2d as SyncBatchNorm2d... | 19,745 | 42.493392 | 98 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/make_fake_datasets/models/resnet.py | from __future__ import absolute_import
'''Resnet for cifar dataset.
Ported form
https://github.com/facebook/fb.resnet.torch
and
https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py
(c) YANG, Wei
'''
import torch.nn as nn
import torch.nn.functional as F
import math
__all__ = ['resnet']
def con... | 7,967 | 29.764479 | 122 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/make_fake_datasets/models/mobilenetv2.py | """
MobileNetV2 implementation used in
<Knowledge Distillation via Route Constrained Optimization>
"""
import torch
import torch.nn as nn
import math
import torch.nn.functional as F
__all__ = ['mobilenetv2_T_w', 'mobile_half']
BN = None
def conv_bn(inp, oup, stride):
return nn.Sequential(
nn.Conv2d(inp... | 5,822 | 27.404878 | 115 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/make_fake_datasets/models/vgg.py | '''VGG '''
import torch.nn as nn
import torch.nn.functional as F
import math
__all__ = [
'VGG', 'vgg11', 'vgg11_bn', 'vgg13', 'vgg13_bn', 'vgg16', 'vgg16_bn',
'vgg19_bn', 'vgg19',
]
model_urls = {
'vgg11': 'https://download.pytorch.org/models/vgg11-bbd30ac9.pth',
'vgg13': 'https://download.pytorch.o... | 7,304 | 28.695122 | 98 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/make_fake_datasets/models/densenet.py | '''DenseNet in PyTorch.
To fit 128x128 images, I modified the first conv layer and add an extra max_pool2d after it.
'''
import math
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
NC=3
IMG_SIZE = 128
class Bottleneck(nn.Module):
def __init__(self, in_pla... | 4,125 | 32.544715 | 96 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/make_fake_datasets/models/ResNet_extract.py | '''
ResNet-based model to map an image from pixel space to a features space.
Need to be pretrained on the dataset.
codes are based on
@article{
zhang2018mixup,
title={mixup: Beyond Empirical Risk Minimization},
author={Hongyi Zhang, Moustapha Cisse, Yann N. Dauphin, David Lopez-Paz},
journal={International Conference ... | 5,781 | 34.042424 | 107 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/make_fake_datasets/models/resnetv2.py | '''ResNet in PyTorch.
For Pre-activation ResNet, see 'preact_resnet.py'.
Reference:
[1] Kaiming He, Xiangyu Zhang, Shaoqing Ren, Jian Sun
Deep Residual Learning for Image Recognition. arXiv:1512.03385
'''
import torch
import torch.nn as nn
import torch.nn.functional as F
class BasicBlock(nn.Module):
expansion... | 7,123 | 34.442786 | 110 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/make_fake_datasets/models/cDR_MLP.py | '''
Conditional Density Ration Estimation via Multilayer Perceptron
Multilayer Perceptron : trained to model density ratio in a feature space
Its input is the output of a pretrained Deep CNN, say ResNet-34
'''
import torch
import torch.nn as nn
IMG_SIZE=128
NC=3
N_CLASS = 100
cfg = {"MLP3": [512,256,128],
... | 2,393 | 30.92 | 101 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/make_fake_datasets/models/InceptionV3.py | '''
Inception v3
'''
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.utils.model_zoo as model_zoo
__all__ = ['Inception3', 'inception_v3']
model_urls = {
# Inception v3 ported from TensorFlow
'inception_v3_google': 'https://download.pytorch.org/models/inception_v3_google-1a... | 12,702 | 36.252199 | 102 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/make_fake_datasets/models/ShuffleNetv1.py | '''ShuffleNet in PyTorch.
See the paper "ShuffleNet: An Extremely Efficient Convolutional Neural Network for Mobile Devices" for more details.
To fit 128x128 images, I modified the first conv layer and add an extra max_pool2d after it (Following Table 5 of "ShuffleNet V2: Practical Guidelines for Efficient CNN Archite... | 5,107 | 34.472222 | 190 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/make_fake_datasets/models/ShuffleNetv2.py | '''ShuffleNetV2 in PyTorch.
See the paper "ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" for more details.
To fit 128x128 images, I modified the first conv layer and add an extra max_pool2d after it (Following Table 5 of "ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture D... | 7,241 | 33.160377 | 190 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/make_fake_datasets/models/__init__.py | from .sync_batchnorm import *
from .layers import *
from .BigGAN import BigGAN_Generator
from .BigGANdeep import BigGANdeep_Generator
from .cDR_MLP import cDR_MLP
from .InceptionV3 import Inception3, inception_v3
from .ResNet_extract import ResNet34_extract
from .resnet import resnet8, resnet14, resnet20, resnet32, res... | 1,547 | 29.352941 | 111 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/make_fake_datasets/models/wrn.py | import math
import torch
import torch.nn as nn
import torch.nn.functional as F
"""
Original Author: Wei Yang
"""
__all__ = ['wrn']
class BasicBlock(nn.Module):
def __init__(self, in_planes, out_planes, stride, dropRate=0.0):
super(BasicBlock, self).__init__()
self.bn1 = nn.BatchNorm2d(in_planes)... | 5,807 | 32.188571 | 116 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/make_fake_datasets/models/sync_batchnorm/replicate.py | # -*- coding: utf-8 -*-
# File : replicate.py
# Author : Jiayuan Mao
# Email : maojiayuan@gmail.com
# Date : 27/01/2018
#
# This file is part of Synchronized-BatchNorm-PyTorch.
# https://github.com/vacancy/Synchronized-BatchNorm-PyTorch
# Distributed under MIT License.
import functools
from torch.nn.parallel.da... | 3,226 | 32.968421 | 115 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/make_fake_datasets/models/sync_batchnorm/unittest.py | # -*- coding: utf-8 -*-
# File : unittest.py
# Author : Jiayuan Mao
# Email : maojiayuan@gmail.com
# Date : 27/01/2018
#
# This file is part of Synchronized-BatchNorm-PyTorch.
# https://github.com/vacancy/Synchronized-BatchNorm-PyTorch
# Distributed under MIT License.
import unittest
import torch
class TorchTes... | 746 | 23.9 | 59 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/make_fake_datasets/models/sync_batchnorm/batchnorm.py | # -*- coding: utf-8 -*-
# File : batchnorm.py
# Author : Jiayuan Mao
# Email : maojiayuan@gmail.com
# Date : 27/01/2018
#
# This file is part of Synchronized-BatchNorm-PyTorch.
# https://github.com/vacancy/Synchronized-BatchNorm-PyTorch
# Distributed under MIT License.
import collections
import torch
import torc... | 14,882 | 41.644699 | 159 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/make_fake_datasets/models/sync_batchnorm/batchnorm_reimpl.py | #! /usr/bin/env python3
# -*- coding: utf-8 -*-
# File : batchnorm_reimpl.py
# Author : acgtyrant
# Date : 11/01/2018
#
# This file is part of Synchronized-BatchNorm-PyTorch.
# https://github.com/vacancy/Synchronized-BatchNorm-PyTorch
# Distributed under MIT License.
import torch
import torch.nn as nn
import torch... | 2,383 | 30.786667 | 95 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/make_fake_datasets/models/sync_batchnorm/comm.py | # -*- coding: utf-8 -*-
# File : comm.py
# Author : Jiayuan Mao
# Email : maojiayuan@gmail.com
# Date : 27/01/2018
#
# This file is part of Synchronized-BatchNorm-PyTorch.
# https://github.com/vacancy/Synchronized-BatchNorm-PyTorch
# Distributed under MIT License.
import queue
import collections
import threading... | 4,449 | 31.246377 | 117 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/make_fake_datasets/models/sync_batchnorm/__init__.py | # -*- coding: utf-8 -*-
# File : __init__.py
# Author : Jiayuan Mao
# Email : maojiayuan@gmail.com
# Date : 27/01/2018
#
# This file is part of Synchronized-BatchNorm-PyTorch.
# https://github.com/vacancy/Synchronized-BatchNorm-PyTorch
# Distributed under MIT License.
from .batchnorm import SynchronizedBatchNorm... | 449 | 33.615385 | 96 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/make_fake_datasets/models/layers/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
#... | 17,132 | 36.245652 | 101 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/make_fake_datasets/models/layers/__init__.py | from .layers import *
| 23 | 7 | 21 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/SSKD/teacher_data_loader.py | import numpy as np
import torch
import torchvision
import torchvision.transforms as transforms
import PIL
from PIL import Image
import h5py
import os
class IMGs_dataset(torch.utils.data.Dataset):
def __init__(self, images, labels=None, transform=None):
super(IMGs_dataset, self).__init__()
self.i... | 4,779 | 36.34375 | 255 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/SSKD/teacher.py | print("\n ===================================================================================================")
import os
import os.path as osp
import argparse
import time
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
from torch.utils.data import Dat... | 7,727 | 33.5 | 200 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/SSKD/student.py | print("\n ===================================================================================================")
import os
import os.path as osp
import argparse
import time
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
from torch.optim.lr_scheduler im... | 20,500 | 40.002 | 217 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/SSKD/wrapper.py | import torch
import torch.nn as nn
import torch.nn.functional as F
class wrapper(nn.Module):
def __init__(self, module):
super(wrapper, self).__init__()
self.backbone = module
feat_dim = list(module.children())[-1].in_features
self.proj_head = nn.Sequential(
... | 718 | 24.678571 | 66 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/SSKD/utils.py | import os
import logging
import numpy as np
import torch
from torch.nn import init
class AverageMeter(object):
"""Computes and stores the average and current value"""
def __init__(self):
self.reset()
def reset(self):
self.count = 0
self.sum = 0.0
self.val = 0.0
sel... | 1,014 | 20.145833 | 69 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/SSKD/student_dataset.py | from __future__ import print_function
from PIL import Image
import os
import os.path
import numpy as np
import sys
import pickle
import torch
import torchvision
import torchvision.transforms as transforms
import torch.utils.data as data
from itertools import permutations
import h5py
class IMGs_dataset(torch.utils.... | 4,236 | 32.362205 | 120 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/SSKD/models/resnet.py | from __future__ import absolute_import
'''Resnet for cifar dataset.
Ported form
https://github.com/facebook/fb.resnet.torch
and
https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py
(c) YANG, Wei
'''
import torch.nn as nn
import torch.nn.functional as F
import math
__all__ = ['resnet']
def con... | 8,219 | 29.557621 | 122 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/SSKD/models/mobilenetv2.py | """
MobileNetV2 implementation used in
<Knowledge Distillation via Route Constrained Optimization>
"""
import torch
import torch.nn as nn
import math
import torch.nn.functional as F
__all__ = ['mobilenetv2_T_w', 'mobile_half']
BN = None
def conv_bn(inp, oup, stride):
return nn.Sequential(
nn.Conv2d(inp... | 5,886 | 27.57767 | 115 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.