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/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/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/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/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/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/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 |
cGAN-KD | cGAN-KD-main/CIFAR-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=32
NC=3
N_CLASS = 100
cfg = {"MLP3": [512,256,128],
... | 2,392 | 30.906667 | 101 | py |
cGAN-KD | cGAN-KD-main/CIFAR-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/CIFAR-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.
'''
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/make_fake_datasets/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/make_fake_datasets/models/DR_MLP.py | '''
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=32
NC=3
cfg = {"MLP3": [2048,1024,512],
"MLP5": [2048,1024,512,... | 1,752 | 26.825397 | 83 | py |
cGAN-KD | cGAN-KD-main/CIFAR-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,519 | 31.280702 | 116 | py |
cGAN-KD | cGAN-KD-main/CIFAR-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/CIFAR-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/CIFAR-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/CIFAR-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/CIFAR-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/CIFAR-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,889 | 36.906977 | 255 | py |
cGAN-KD | cGAN-KD-main/CIFAR-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,868 | 33.513158 | 194 | py |
cGAN-KD | cGAN-KD-main/CIFAR-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... | 19,976 | 40.104938 | 217 | py |
cGAN-KD | cGAN-KD-main/CIFAR-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(
nn.Linear... | 702 | 24.107143 | 58 | py |
cGAN-KD | cGAN-KD-main/CIFAR-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/CIFAR-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,131 | 32.593496 | 120 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/SSKD/cifar.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 torch.utils.data as data
from itertools import permutations
class VisionDataset(data.Dataset):
_repr_indent = 4
def __init__(self, root, transforms=None, trans... | 7,139 | 31.752294 | 86 | py |
cGAN-KD | cGAN-KD-main/CIFAR-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,021 | 29.044944 | 116 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/SSKD/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,777 | 27.323529 | 115 | py |
cGAN-KD | cGAN-KD-main/CIFAR-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... | 6,971 | 28.417722 | 98 | py |
cGAN-KD | cGAN-KD-main/CIFAR-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/CIFAR-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... | 6,933 | 33.844221 | 108 | py |
cGAN-KD | cGAN-KD-main/CIFAR-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,732 | 33.05036 | 126 | py |
cGAN-KD | cGAN-KD-main/CIFAR-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/CIFAR-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,074 | 32.530806 | 107 | py |
cGAN-KD | cGAN-KD-main/CIFAR-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,519 | 31.280702 | 116 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/ReviewKD/train.py | import pdb
import time
import argparse
import numpy as np
from tqdm import tqdm
import os
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
import torch.backends.cudnn as cudnn
from torch.optim.lr_scheduler import MultiStepLR
from torch.optim.lr_scheduler import Cos... | 12,496 | 38.175549 | 140 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/ReviewKD/util/kd.py | import torch.nn.functional as F
from torch import nn
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_softmax(y_s/self.T, dim=1)
p_t = ... | 450 | 27.1875 | 79 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/ReviewKD/util/misc.py | import torch
def format_time(seconds):
days = int(seconds / 3600/24)
seconds = seconds - days*3600*24
hours = int(seconds / 3600)
seconds = seconds - hours*3600
minutes = int(seconds / 60)
seconds = seconds - minutes*60
secondsf = int(seconds)
seconds = seconds - secondsf
millis = i... | 2,250 | 24.579545 | 95 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/ReviewKD/model/reviewkd.py | import math
import pdb
import torch.nn.functional as F
from torch import nn
import torch
#from .mobilenetv2 import mobile_half
from .shufflenetv1 import ShuffleV1
from .shufflenetv2 import ShuffleV2
from .resnet_cifar import build_resnet_backbone, build_resnetx4_backbone
from .vgg import vgg_dict
from .wide_resnet_cif... | 6,351 | 34.093923 | 111 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/ReviewKD/model/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,098 | 32.485849 | 107 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/ReviewKD/model/wide_resnet_cifar.py | import pdb
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... | 5,554 | 31.109827 | 116 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/ReviewKD/model/resnetv2_cifar.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,939 | 33.7 | 106 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/ReviewKD/model/resnet.py | '''ResNet18/34/50/101/152 in Pytorch.'''
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
def conv3x3(in_planes, out_planes, stride=1):
return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride, padding=1, bias=False)
class BasicBlock(nn.Module):... | 4,140 | 33.22314 | 102 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/ReviewKD/model/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/ReviewKD/model/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,102 | 27.757085 | 98 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/ReviewKD/model/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,756 | 32.978571 | 126 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/ReviewKD/model/wide_resnet.py | # From https://github.com/xternalz/WideResNet-pytorch
import math
import torch
import torch.nn as nn
import torch.nn.functional as F
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... | 3,801 | 41.719101 | 116 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/ReviewKD/model/resnet_cifar.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,312 | 29.339416 | 116 | py |
cGAN-KD | cGAN-KD-main/CIFAR-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,951 | 42.466667 | 162 | py |
cGAN-KD | cGAN-KD-main/CIFAR-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.cifar100 import get_cifar100_dataloaders
... | 7,738 | 41.756906 | 213 | py |
cGAN-KD | cGAN-KD-main/CIFAR-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/CIFAR-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/CIFAR-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 * ... | 5,755 | 32.271676 | 106 | py |
cGAN-KD | cGAN-KD-main/CIFAR-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,748 | 29.151751 | 116 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/RepDistiller/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/RepDistiller/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/RepDistiller/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/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=10):
super(LinearClassifier, self).__init__()
self.n... | 819 | 21.777778 | 51 | py |
cGAN-KD | cGAN-KD-main/CIFAR-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... | 6,915 | 33.753769 | 106 | py |
cGAN-KD | cGAN-KD-main/CIFAR-100/RepDistiller/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/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/CIFAR-100/RepDistiller/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/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,519 | 31.280702 | 116 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.