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 |
|---|---|---|---|---|---|---|
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/__init__.py | from .resnet import resnet8, resnet14, resnet20, resnet32, resnet44, resnet56, resnet110, resnet8x4, resnet32x4, resnet14x05, resnet20x05, resnet20x0375
from .resnetv2 import ResNet18, ResNet50, ResNet34
from .wrn import wrn_16_1, wrn_16_2, wrn_40_1, wrn_40_2
from .vgg import vgg19_bn, vgg16_bn, vgg13_bn, vgg11_bn, vgg... | 1,175 | 29.947368 | 152 | 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/__init__.py | from .resnet import resnet8, resnet14, resnet20, resnet32, resnet44, resnet56, resnet110, resnet8x4, resnet32x4
from .resnetv2 import ResNet18, ResNet34, ResNet50
from .wrn import wrn_16_1, wrn_16_2, wrn_40_1, wrn_40_2
from .vgg import vgg19_bn, vgg16_bn, vgg13_bn, vgg11_bn, vgg8_bn
from .mobilenetv2 import mobile_half... | 1,374 | 30.976744 | 111 | 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/__init__.py | from .AB import ABLoss
from .AT import Attention
from .CC import Correlation
from .FitNet import HintLoss
from .FSP import FSP
from .FT import FactorTransfer
from .KD import DistillKL
from .KDSVD import KDSVD
from .NST import NSTLoss
from .PKT import PKT
from .RKD import RKDLoss
from .SP import Similarity
from .VID imp... | 332 | 22.785714 | 30 | 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/helper/__init__.py | 0 | 0 | 0 | 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/__init__.py | 0 | 0 | 0 | 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/opts.py | import argparse
'''
Options for Teacher Assistant Knowledge Distillation: TAKD
Mirzadeh, Seyed Iman, et al. "Improved knowledge distillation via teacher assistant." Proceedings of the AAAI Conference on Artificial Intelligence. Vol. 34. No. 04. 2020.
'''
def takd_opts():
parser = argparse.ArgumentParser()
... | 3,041 | 47.285714 | 171 | 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 |
cGAN-KD | cGAN-KD-main/CIFAR-100/TAKD/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
''' function for cnn training '''
def train_cnn(net, net_name, trainloader, testloader, epochs, resume_epoch=0, save_freq=[100, 150], lr_base=0.1, lr_decay_factor... | 4,372 | 37.026087 | 257 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/TAKD/takd.py | '''
Teacher Assistant Knowledge Distillation: TAKD
'''
print("\n ===================================================================================================")
import argparse
import os
import timeit
import torch
import torchvision
import torchvision.transforms as transforms
import numpy as np
import torch.n... | 11,728 | 39.725694 | 429 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/TAKD/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,755 | 32.271676 | 106 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/TAKD/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,748 | 29.151751 | 116 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/TAKD/models/mobilenetv2.py | """
MobileNetV2 implementation used in
<Knowledge Distillation via Route Constrained Optimization>
"""
import torch
import torch.nn as nn
import math
__all__ = ['mobilenetv2_T_w', 'mobile_half']
BN = None
def conv_bn(inp, oup, stride):
return nn.Sequential(
nn.Conv2d(inp, oup, 3, stride, 1, bias=False)... | 5,705 | 27.108374 | 115 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/TAKD/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... | 6,971 | 28.417722 | 98 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/TAKD/models/densenet.py | '''DenseNet in PyTorch.'''
import math
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
NC=3
resize = (32,32)
class Bottleneck(nn.Module):
def __init__(self, in_planes, growth_rate):
super(Bottleneck, self).__init__()
self.bn1 = nn.BatchNor... | 3,895 | 32.878261 | 96 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/TAKD/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/CIFAR-100/TAKD/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... | 6,915 | 33.753769 | 106 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/TAKD/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,732 | 33.05036 | 126 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/TAKD/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/CIFAR-100/TAKD/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,074 | 32.530806 | 107 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/TAKD/models/__init__.py | from .resnet import resnet8, resnet14, resnet20, resnet32, resnet44, resnet56, resnet110, resnet8x4, resnet32x4
from .resnetv2 import ResNet50
from .wrn import wrn_16_1, wrn_16_2, wrn_40_1, wrn_40_2
from .vgg import vgg19_bn, vgg16_bn, vgg13_bn, vgg11_bn, vgg8_bn
from .mobilenetv2 import mobile_half
from .ShuffleNetv1 ... | 1,242 | 30.075 | 111 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/TAKD/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,519 | 31.280702 | 116 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/BigGAN/make_hdf5.py | """ Convert dataset to HDF5
This script preprocesses a dataset and saves it (images and labels) to
an HDF5 file for improved I/O. """
import os
import sys
from argparse import ArgumentParser
from tqdm import tqdm, trange
import h5py as h5
import numpy as np
import torch
import torchvision.datasets as dset
impo... | 6,407 | 47.545455 | 182 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/BigGAN/losses.py | import torch
import torch.nn.functional as F
# DCGAN loss
def loss_dcgan_dis(dis_fake, dis_real):
L1 = torch.mean(F.softplus(-dis_real))
L2 = torch.mean(F.softplus(dis_fake))
return L1, L2
def loss_dcgan_gen(dis_fake):
loss = torch.mean(F.softplus(-dis_fake))
return loss
# Hinge Loss
def loss_hinge_dis(d... | 821 | 23.909091 | 78 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/BigGAN/sample.py | ''' Sample
This script loads a pretrained net and a weightsfile and sample '''
wd = "/home/xin/OneDrive/Working_directory/GAN_DA_Subsampling/CIFAR10/BigGAN"
import os
os.chdir(wd)
import functools
import math
import numpy as np
from tqdm import tqdm, trange
import torch
import torch.nn as nn
from torch.nn import... | 8,362 | 43.248677 | 157 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/BigGAN/BigGANdeep.py | import numpy as np
import math
import functools
import torch
import torch.nn as nn
from torch.nn import init
import torch.optim as optim
import torch.nn.functional as F
from torch.nn import Parameter as P
import layers
from sync_batchnorm import SynchronizedBatchNorm2d as SyncBatchNorm2d
# BigGAN-deep: uses a differ... | 22,982 | 41.958879 | 126 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/BigGAN/inception_tf13.py | ''' Tensorflow inception score code
Derived from https://github.com/openai/improved-gan
Code derived from tensorflow/tensorflow/models/image/imagenet/classify_image.py
THIS CODE REQUIRES TENSORFLOW 1.3 or EARLIER to run in PARALLEL BATCH MODE
To use this code, run sample.py on your model with --sample_npz, and then
... | 5,363 | 37.869565 | 191 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/BigGAN/train_fns.py | ''' train_fns.py
Functions for the main loop of training different conditional image models
'''
import torch
import torch.nn as nn
import torchvision
import os
import utils
import losses
# Dummy training function for debugging
def dummy_training_function():
def train(x, y):
return {}
return train
def GAN_t... | 8,275 | 43.735135 | 149 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/BigGAN/BigGAN.py | import numpy as np
import math
import functools
import torch
import torch.nn as nn
from torch.nn import init
import torch.optim as optim
import torch.nn.functional as F
from torch.nn import Parameter as P
import layers
from sync_batchnorm import SynchronizedBatchNorm2d as SyncBatchNorm2d
from DiffAugment_pytorch imp... | 20,324 | 42.709677 | 98 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/BigGAN/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/CIFAR-100/BigGAN/utils.py | #!/usr/bin/env python
# -*- coding: utf-8 -*-
''' Utilities file
This file contains utility functions for bookkeeping, logging, and data loading.
Methods which directly affect training should either go in layers, the model,
or train_fns.py.
'''
from __future__ import print_function
import sys
import os
import numpy a... | 51,556 | 40.411245 | 143 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/BigGAN/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,130 | 36.32244 | 101 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/BigGAN/datasets.py | ''' Datasets
This file contains definitions for our CIFAR, ImageFolder, and HDF5 datasets
'''
import os
import os.path
import sys
from PIL import Image
import numpy as np
from tqdm import tqdm, trange
import torchvision.datasets as dset
import torchvision.transforms as transforms
from torchvision.datasets.utils im... | 13,114 | 29.571096 | 139 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/BigGAN/inception_utils.py | ''' Inception utilities
This file contains methods for calculating IS and FID, using either
the original numpy code or an accelerated fully-pytorch version that
uses a fast newton-schulz approximation for the matrix sqrt. There are also
methods for acquiring a desired number of samples from the Generato... | 12,341 | 38.305732 | 136 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/BigGAN/animal_hash.py | c = ['Aardvark', 'Abyssinian', 'Affenpinscher', 'Akbash', 'Akita', 'Albatross',
'Alligator', 'Alpaca', 'Angelfish', 'Ant', 'Anteater', 'Antelope', 'Ape',
'Armadillo', 'Ass', 'Avocet', 'Axolotl', 'Baboon', 'Badger', 'Balinese',
'Bandicoot', 'Barb', 'Barnacle', 'Barracuda', 'Bat', 'Beagle', 'Bear',
'B... | 32,285 | 72.544419 | 82 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/BigGAN/calculate_inception_moments.py | ''' Calculate Inception Moments
This script iterates over the dataset and calculates the moments of the
activations of the Inception net (needed for FID), and also returns
the Inception Score of the training data.
Note that if you don't shuffle the data, the IS of true data will be under-
estimated as it is lab... | 3,551 | 38.032967 | 105 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/BigGAN/train.py | """ BigGAN: The Authorized Unofficial PyTorch release
Code by A. Brock and A. Andonian
This code is an unofficial reimplementation of
"Large-Scale GAN Training for High Fidelity Natural Image Synthesis,"
by A. Brock, J. Donahue, and K. Simonyan (arXiv 1809.11096).
Let's go.
"""
import os
import fu... | 9,472 | 39.656652 | 124 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/BigGAN/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/CIFAR-100/BigGAN/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/CIFAR-100/BigGAN/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/CIFAR-100/BigGAN/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/CIFAR-100/BigGAN/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/CIFAR-100/BigGAN/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/CIFAR-100/BigGAN/TFHub/biggan_v1.py | # BigGAN V1:
# This is now deprecated code used for porting the TFHub modules to pytorch,
# included here for reference only.
import numpy as np
import torch
from scipy.stats import truncnorm
from torch import nn
from torch.nn import Parameter
from torch.nn import functional as F
def l2normalize(v, eps=1e-4):
retur... | 12,173 | 30.29563 | 114 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/BigGAN/TFHub/converter.py | """Utilities for converting TFHub BigGAN generator weights to PyTorch.
Recommended usage:
To convert all BigGAN variants and generate test samples, use:
```bash
CUDA_VISIBLE_DEVICES=0 python converter.py --generate_samples
```
See `parse_args` for additional options.
"""
import argparse
import os
import sys
impor... | 17,428 | 42.355721 | 143 | py |
cGAN-KD | cGAN-KD-main/CIFAR-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... | 35,820 | 49.02933 | 548 | py |
cGAN-KD | cGAN-KD-main/CIFAR-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/CIFAR-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,773 | 57.219512 | 131 | py |
cGAN-KD | cGAN-KD-main/CIFAR-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/CIFAR-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/CIFAR-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/CIFAR-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 * ... | 5,755 | 32.271676 | 106 | py |
cGAN-KD | cGAN-KD-main/CIFAR-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/CIFAR-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,748 | 29.151751 | 116 | py |
cGAN-KD | cGAN-KD-main/CIFAR-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
__all__ = ['mobilenetv2_T_w', 'mobile_half']
BN = None
def conv_bn(inp, oup, stride):
return nn.Sequential(
nn.Conv2d(inp, oup, 3, stride, 1, bias=False)... | 5,705 | 27.108374 | 115 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/make_fake_datasets/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... | 6,971 | 28.417722 | 98 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/make_fake_datasets/models/densenet.py | '''DenseNet in PyTorch.'''
import math
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
NC=3
resize = (32,32)
class Bottleneck(nn.Module):
def __init__(self, in_planes, growth_rate):
super(Bottleneck, self).__init__()
self.bn1 = nn.BatchNor... | 3,837 | 32.373913 | 96 | py |
cGAN-KD | cGAN-KD-main/CIFAR-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,650 | 33.668712 | 107 | py |
cGAN-KD | cGAN-KD-main/CIFAR-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... | 6,915 | 33.753769 | 106 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.