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/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/__init__.py | from .sync_batchnorm import *
from .layers import *
from .BigGAN import BigGAN_Generator
from .DR_MLP import DR_MLP
from .cDR_MLP import cDR_MLP
from .InceptionV3 import Inception3, inception_v3
from .ResNet_extract import ResNet34_extract
from .resnet import resnet8, resnet14, resnet20, resnet32, resnet44, resnet56, r... | 721 | 39.111111 | 111 | 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/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/make_fake_datasets/models/sync_batchnorm/__init__.py | # -*- coding: utf-8 -*-
# File : __init__.py
# Author : Jiayuan Mao
# Email : maojiayuan@gmail.com
# Date : 27/01/2018
#
# This file is part of Synchronized-BatchNorm-PyTorch.
# https://github.com/vacancy/Synchronized-BatchNorm-PyTorch
# Distributed under MIT License.
from .batchnorm import SynchronizedBatchNorm... | 449 | 33.615385 | 96 | py |
cGAN-KD | cGAN-KD-main/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/make_fake_datasets/models/layers/__init__.py | from .layers import *
| 23 | 7 | 21 | 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/__init__.py | from .resnet import resnet8, resnet14, resnet20, resnet32, resnet44, resnet56, resnet110, resnet8x4, resnet32x4, resnet14x05, resnet20x05, resnet20x0375
from .resnetv2 import ResNet18, 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 ... | 1,139 | 29.810811 | 152 | 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/util/__init__.py | 0 | 0 | 0 | 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/ReviewKD/model/__init__.py | 0 | 0 | 0 | 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/__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,314 | 30.309524 | 111 | 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 |
cGAN-KD | cGAN-KD-main/CIFAR-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/CIFAR-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/CIFAR-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/CIFAR-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/CIFAR-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/CIFAR-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/CIFAR-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/CIFAR-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/CIFAR-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/CIFAR-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/CIFAR-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/CIFAR-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/CIFAR-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/CIFAR-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/CIFAR-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/CIFAR-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,306 | 33.343173 | 85 | py |
cGAN-KD | cGAN-KD-main/CIFAR-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/CIFAR-100/RepDistiller/helper/__init__.py | 0 | 0 | 0 | py | |
cGAN-KD | cGAN-KD-main/CIFAR-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/CIFAR-100/RepDistiller/crd/__init__.py | 0 | 0 | 0 | py | |
cGAN-KD | cGAN-KD-main/CIFAR-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 |
CodeMixedTreebank | CodeMixedTreebank-master/UDParser/driver/TrainTest.py | import sys
sys.path.extend(["../../","../","./"])
import time
import torch.optim.lr_scheduler
import torch.nn as nn
import random
import argparse
from driver.Config import *
from driver.Model import *
from driver.Parser import *
from data.Dataloader import *
import pickle
def train(data, parser, vocab, config, others)... | 7,271 | 40.318182 | 129 | py |
CodeMixedTreebank | CodeMixedTreebank-master/UDParser/driver/Config.py | from configparser import ConfigParser
import sys, os
sys.path.append('..')
#import models
class Configurable(object):
def __init__(self, config_file, extra_args):
config = ConfigParser()
config.read(config_file)
if extra_args:
extra_args = dict([ (k[2:], v) for k, v in zip(extra_args[0::2], extra_args[1::2])... | 4,481 | 27.547771 | 87 | py |
CodeMixedTreebank | CodeMixedTreebank-master/UDParser/driver/Parser.py | import torch.nn.functional as F
from driver.MST import *
import torch.optim.lr_scheduler
from driver.Layer import *
import numpy as np
def pad_sequence(xs, length=None, padding=-1, dtype=np.float64):
lengths = [len(x) for x in xs]
if length is None:
length = max(lengths)
y = np.array([np.pad(x.asty... | 6,780 | 37.310734 | 92 | py |
CodeMixedTreebank | CodeMixedTreebank-master/UDParser/driver/MST.py | # !/usr/bin/env python
# -*- encoding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
from collections import defaultdict
# ***************************************************************
class Tarjan:
"""
Computes Tar... | 7,201 | 34.303922 | 119 | py |
CodeMixedTreebank | CodeMixedTreebank-master/UDParser/driver/Layer.py | import torch
import torch.nn as nn
import numpy as np
from torch.nn import functional, init
def get_tensor_np(t):
return t.data.cpu().numpy()
def orthonormal_initializer(output_size, input_size):
"""
adopted from Timothy Dozat https://github.com/tdozat/Parser/blob/master/lib/linalg.py
"""
print(ou... | 11,929 | 41.913669 | 107 | py |
CodeMixedTreebank | CodeMixedTreebank-master/UDParser/driver/__init__.py | 0 | 0 | 0 | py | |
CodeMixedTreebank | CodeMixedTreebank-master/UDParser/driver/Model.py | from driver.Layer import *
from data.Vocab import *
def drop_tri_input_independent(word_embeddings, tag_embeddings, context_embeddings, dropout_emb):
batch_size, seq_length, _ = word_embeddings.size()
word_masks = word_embeddings.new_full((batch_size, seq_length), 1-dropout_emb)
word_masks = torch.bernoul... | 6,687 | 43.586667 | 114 | py |
CodeMixedTreebank | CodeMixedTreebank-master/UDParser/data/Vocab.py | from collections import Counter
from data.Dependency import *
import numpy as np
class Vocab(object):
PAD, ROOT, UNK = 0, 1, 2
def __init__(self, word_counter, tag_counter, rel_counter, relroot='root', min_occur_count = 2):
self._root = relroot
self._root_form = '<' + relroot.lower() + '>'
... | 7,988 | 35.646789 | 108 | py |
CodeMixedTreebank | CodeMixedTreebank-master/UDParser/data/Dataloader.py | from data.Vocab import *
import numpy as np
import torch
def read_corpus(file_path, vocab=None):
data = []
with open(file_path, 'r', encoding='UTF-8') as infile:
for sentence in readDepTree(infile, vocab):
data.append(sentence)
return data
def sentences_numberize(sentences, vocab):
... | 2,952 | 29.132653 | 130 | py |
CodeMixedTreebank | CodeMixedTreebank-master/UDParser/data/__init__.py | 0 | 0 | 0 | py | |
CodeMixedTreebank | CodeMixedTreebank-master/UDParser/data/Dependency.py |
class Dependency:
def __init__(self, id, form, lang, tag, head, rel):
self.id = id
self.org_form = form
self.form = form.lower() + "_" + lang
self.lang = lang
self.tag = tag
self.head = head
self.rel = rel
def __str__(self):
values = [str(self.id... | 4,451 | 31.028777 | 133 | py |
CodeMixedTreebank | CodeMixedTreebank-master/PartialProject/driver/Corpus.py | import numpy as np
class Dependency:
def __init__(self, id, form, lang, tag, head, rel, tgt_id=-1):
self.id = id
self.org_form = form.lower()
self.form = form.lower() + "_" + lang
self.lang = lang
self.tag = tag
self.head = head
self.rel = rel
self.t... | 7,233 | 30.452174 | 113 | py |
CodeMixedTreebank | CodeMixedTreebank-master/PartialProject/driver/Project.py | import sys
sys.path.extend(["../","./"])
import time
import argparse
from driver.Corpus import *
from collections import Counter
import copy
def evaluate(dep_file, parallel_file, align_file, outputFile, percentage, tlang):
start = time.time()
infile_dep = open(dep_file, 'r', encoding='UTF-8')
infile_paral... | 6,295 | 33.217391 | 108 | py |
LSMOL | LSMOL-main/tools/joint_iterative_optimization/3D_step.py | 0 | 0 | 0 | py | |
LSMOL | LSMOL-main/tools/joint_iterative_optimization/2D_step.py | 0 | 0 | 0 | py | |
LSMOL | LSMOL-main/tools/ssl_methods/freesolo.py | 0 | 0 | 0 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.