repo stringlengths 1 99 | file stringlengths 13 215 | code stringlengths 12 59.2M | file_length int64 12 59.2M | avg_line_length float64 3.82 1.48M | max_line_length int64 12 2.51M | extension_type stringclasses 1
value |
|---|---|---|---|---|---|---|
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/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/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/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/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/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/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 |
cGAN-KD | cGAN-KD-main/ImageNet-100/SSKD/models/vgg.py | '''VGG for CIFAR10. FC layers are removed.
(c) YANG, Wei
'''
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-bbd30... | 7,269 | 28.433198 | 98 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/SSKD/models/classifier.py | from __future__ import print_function
import torch.nn as nn
#########################################
# ===== Classifiers ===== #
#########################################
class LinearClassifier(nn.Module):
def __init__(self, dim_in, n_label=10):
super(LinearClassifier, self).__init__()
self.n... | 819 | 21.777778 | 51 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/SSKD/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,133 | 34.492537 | 110 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/SSKD/models/ShuffleNetv1.py | '''ShuffleNet in PyTorch.
See the paper "ShuffleNet: An Extremely Efficient Convolutional Neural Network for Mobile Devices" for more details.
'''
import torch
import torch.nn as nn
import torch.nn.functional as F
class ShuffleBlock(nn.Module):
def __init__(self, groups):
super(ShuffleBlock, self).__init_... | 4,904 | 33.787234 | 126 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/SSKD/models/util.py | from __future__ import print_function
import torch.nn as nn
import math
class Paraphraser(nn.Module):
"""Paraphrasing Complex Network: Network Compression via Factor Transfer"""
def __init__(self, t_shape, k=0.5, use_bn=False):
super(Paraphraser, self).__init__()
in_channel = t_shape[1]
... | 9,622 | 32.068729 | 107 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/SSKD/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__()
... | 7,170 | 32.825472 | 107 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/SSKD/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,786 | 32.258621 | 116 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/RepDistiller/train_student.py | """
the general training framework
"""
from __future__ import print_function
import os
import argparse
import socket
import time
import torch
import torch.optim as optim
import torch.nn as nn
import torch.backends.cudnn as cudnn
from models import model_dict
from models.util import Embed, ConvReg, LinearEmbed
from... | 16,847 | 42.2 | 162 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/RepDistiller/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,225 | 30.019231 | 143 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/RepDistiller/train_teacher.py | from __future__ import print_function
import os
import argparse
import socket
import time
# import tensorboard_logger as tb_logger
import torch
import torch.optim as optim
import torch.nn as nn
import torch.backends.cudnn as cudnn
from models import model_dict
from dataset.imagenet100 import get_imagenet100_dataloa... | 7,684 | 41.458564 | 216 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/RepDistiller/dataset/cifar100.py | from __future__ import print_function
import os
import socket
import numpy as np
from torch.utils.data import DataLoader
from torchvision import datasets, transforms
from PIL import Image
import h5py
import torch
import gc
"""
mean = {
'cifar100': (0.5071, 0.4867, 0.4408),
}
std = {
'cifar100': (0.2675, 0.25... | 12,737 | 35.394286 | 148 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/RepDistiller/dataset/imagenet100.py | from __future__ import print_function
import os
import socket
import numpy as np
from torch.utils.data import DataLoader
from torchvision import datasets, transforms
from PIL import Image
import h5py
import torch
import gc
## for vanilla CNN training and KD other than CRD
class IMGs_dataset(torch.utils.data.Dataset)... | 13,091 | 36.299145 | 155 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/RepDistiller/dataset/imagenet.py | """
get data loaders
"""
from __future__ import print_function
import os
import socket
import numpy as np
from torch.utils.data import DataLoader
from torchvision import datasets
from torchvision import transforms
def get_data_folder():
"""
return server-dependent path to store the data
"""
hostname ... | 8,053 | 32.983122 | 110 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/RepDistiller/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/RepDistiller/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/RepDistiller/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/RepDistiller/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/RepDistiller/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/RepDistiller/models/classifier.py | from __future__ import print_function
import torch.nn as nn
#########################################
# ===== Classifiers ===== #
#########################################
class LinearClassifier(nn.Module):
def __init__(self, dim_in, n_label=100):
super(LinearClassifier, self).__init__()
self.... | 821 | 21.833333 | 51 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/RepDistiller/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/RepDistiller/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/RepDistiller/models/util.py | from __future__ import print_function
import torch.nn as nn
import math
class Paraphraser(nn.Module):
"""Paraphrasing Complex Network: Network Compression via Factor Transfer"""
def __init__(self, t_shape, k=0.5, use_bn=False):
super(Paraphraser, self).__init__()
in_channel = t_shape[1]
... | 9,622 | 32.068729 | 107 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/RepDistiller/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/RepDistiller/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/RepDistiller/distiller_zoo/PKT.py | from __future__ import print_function
import torch
import torch.nn as nn
class PKT(nn.Module):
"""Probabilistic Knowledge Transfer for deep representation learning
Code from author: https://github.com/passalis/probabilistic_kt"""
def __init__(self):
super(PKT, self).__init__()
def forward(se... | 1,675 | 37.976744 | 110 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/RepDistiller/distiller_zoo/SP.py | from __future__ import print_function
import torch
import torch.nn as nn
import torch.nn.functional as F
class Similarity(nn.Module):
"""Similarity-Preserving Knowledge Distillation, ICCV2019, verified by original author"""
def __init__(self):
super(Similarity, self).__init__()
def forward(self,... | 908 | 28.322581 | 93 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/RepDistiller/distiller_zoo/AT.py | from __future__ import print_function
import torch.nn as nn
import torch.nn.functional as F
class Attention(nn.Module):
"""Paying More Attention to Attention: Improving the Performance of Convolutional Neural Networks
via Attention Transfer
code: https://github.com/szagoruyko/attention-transfer"""
de... | 930 | 30.033333 | 101 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/RepDistiller/distiller_zoo/FitNet.py | from __future__ import print_function
import torch.nn as nn
class HintLoss(nn.Module):
"""Fitnets: hints for thin deep nets, ICLR 2015"""
def __init__(self):
super(HintLoss, self).__init__()
self.crit = nn.MSELoss()
def forward(self, f_s, f_t):
loss = self.crit(f_s, f_t)
... | 332 | 21.2 | 54 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/RepDistiller/distiller_zoo/KDSVD.py | from __future__ import print_function
import torch
import torch.nn as nn
import torch.nn.functional as F
class KDSVD(nn.Module):
"""
Self-supervised Knowledge Distillation using Singular Value Decomposition
original Tensorflow code: https://github.com/sseung0703/SSKD_SVD
"""
def __init__(self, k=... | 2,275 | 28.947368 | 94 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/RepDistiller/distiller_zoo/RKD.py | from __future__ import print_function
import torch
import torch.nn as nn
import torch.nn.functional as F
class RKDLoss(nn.Module):
"""Relational Knowledge Disitllation, CVPR2019"""
def __init__(self, w_d=25, w_a=50):
super(RKDLoss, self).__init__()
self.w_d = w_d
self.w_a = w_a
d... | 1,681 | 27.508475 | 87 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/RepDistiller/distiller_zoo/VID.py | from __future__ import print_function
import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
class VIDLoss(nn.Module):
"""Variational Information Distillation for Knowledge Transfer (CVPR 2019),
code from author: https://github.com/ssahn0215/variational-information-distillation... | 1,862 | 32.872727 | 90 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/RepDistiller/distiller_zoo/CC.py | from __future__ import print_function
import torch
import torch.nn as nn
class Correlation(nn.Module):
"""Correlation Congruence for Knowledge Distillation, ICCV 2019.
The authors nicely shared the code with me. I restructured their code to be
compatible with my running framework. Credits go to the orig... | 1,384 | 31.209302 | 81 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/RepDistiller/distiller_zoo/FT.py | from __future__ import print_function
import torch.nn as nn
import torch.nn.functional as F
class FactorTransfer(nn.Module):
"""Paraphrasing Complex Network: Network Compression via Factor Transfer, NeurIPS 2018"""
def __init__(self, p1=2, p2=1):
super(FactorTransfer, self).__init__()
self.p1... | 981 | 29.6875 | 93 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/RepDistiller/distiller_zoo/KD.py | from __future__ import print_function
import torch.nn as nn
import torch.nn.functional as F
class DistillKL(nn.Module):
"""Distilling the Knowledge in a Neural Network"""
def __init__(self, T):
super(DistillKL, self).__init__()
self.T = T
def forward(self, y_s, y_t):
p_s = F.log_... | 493 | 26.444444 | 82 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/RepDistiller/distiller_zoo/AB.py | from __future__ import print_function
import torch
import torch.nn as nn
class ABLoss(nn.Module):
"""Knowledge Transfer via Distillation of Activation Boundaries Formed by Hidden Neurons
code: https://github.com/bhheo/AB_distillation
"""
def __init__(self, feat_num, margin=1.0):
super(ABLoss,... | 1,100 | 35.7 | 97 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/RepDistiller/distiller_zoo/FSP.py | from __future__ import print_function
import numpy as np
import torch.nn as nn
import torch.nn.functional as F
class FSP(nn.Module):
"""A Gift from Knowledge Distillation:
Fast Optimization, Network Minimization and Transfer Learning"""
def __init__(self, s_shapes, t_shapes):
super(FSP, self).__i... | 1,625 | 32.183673 | 76 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/RepDistiller/distiller_zoo/NST.py | from __future__ import print_function
import torch.nn as nn
import torch.nn.functional as F
class NSTLoss(nn.Module):
"""like what you like: knowledge distill via neuron selectivity transfer"""
def __init__(self):
super(NSTLoss, self).__init__()
pass
def forward(self, g_s, g_t):
... | 1,366 | 31.547619 | 98 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/RepDistiller/helper/pretrain.py | from __future__ import print_function, division
import time
import sys
import torch
import torch.optim as optim
import torch.backends.cudnn as cudnn
from .util import AverageMeter
def init(model_s, model_t, init_modules, criterion, train_loader, opt):
model_t.eval()
model_s.eval()
init_modules.train()
... | 3,305 | 34.170213 | 106 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/RepDistiller/helper/loops.py | from __future__ import print_function, division
import sys
import time
import torch
from .util import AverageMeter, accuracy
def train_vanilla(epoch, train_loader, model, criterion, optimizer, opt):
"""vanilla training"""
model.train()
batch_time = AverageMeter()
data_time = AverageMeter()
loss... | 9,341 | 33.345588 | 85 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/RepDistiller/helper/util.py | from __future__ import print_function
import torch
import numpy as np
def adjust_learning_rate_new(epoch, optimizer, LUT):
"""
new learning rate schedule according to RotNet
"""
lr = next((lr for (max_epoch, lr) in LUT if max_epoch > epoch), LUT[-1][1])
for param_group in optimizer.param_groups:
... | 1,786 | 26.921875 | 89 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/RepDistiller/crd/memory.py | import torch
from torch import nn
import math
class ContrastMemory(nn.Module):
"""
memory buffer that supplies large amount of negative samples.
"""
def __init__(self, inputSize, outputSize, K, T=0.07, momentum=0.5):
super(ContrastMemory, self).__init__()
self.nLem = outputSize
... | 5,126 | 35.884892 | 120 | py |
cGAN-KD | cGAN-KD-main/ImageNet-100/RepDistiller/crd/criterion.py | import torch
from torch import nn
from .memory import ContrastMemory
eps = 1e-7
class CRDLoss(nn.Module):
"""CRD Loss function
includes two symmetric parts:
(a) using teacher as anchor, choose positive and negatives over the student side
(b) using student as anchor, choose positive and negatives over... | 3,309 | 31.135922 | 119 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/TAKD/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
# ################################################################################
# Progress Bar
class Sim... | 3,223 | 32.583333 | 143 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.