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 |
|---|---|---|---|---|---|---|
RoadNet-RT | RoadNet-RT-main/roadnet/learningratefinder.py |
# import the necessary packages
from keras.callbacks import LambdaCallback
from keras import backend as K
import matplotlib.pyplot as plt
import numpy as np
import tempfile
class LearningRateFinder:
def __init__(self, model, stopFactor=4, beta=0.98):
# store the model, stop factor, and beta value (for co... | 6,569 | 35.298343 | 73 | py |
RoadNet-RT | RoadNet-RT-main/roadnet/clr_callback.py | import numpy as np
from keras.callbacks import *
class CyclicLR(Callback):
"""This callback implements a cyclical learning rate policy (CLR).
The method cycles the learning rate between two boundaries with
some constant frequency, as detailed in this paper (https://arxiv.org/abs/1506.01186).
The ampli... | 5,295 | 38.819549 | 124 | py |
RoadNet-RT | RoadNet-RT-main/roadnet/net.py | import keras as K
import keras.layers as L
import keras.models as M
import tensorflow as tf
def resnetLayer(x_in, filters, strides, name):
# main branch
x = L.Conv2D(filters=filters, kernel_size=3, strides=strides, padding="same", name=name+"_conv1")(x_in)
x = L.BatchNormalization(name=name+"_bn1")(x)
... | 5,141 | 47.056075 | 137 | py |
CvT-ASSD | CvT-ASSD-main/models/plot_funcs.py | import torch
from matplotlib import cm
import matplotlib.colors as colors
import time
def get_color_map(num_classes):
"""
Returns a function that maps each index in 0, 1,.. . N-1 to a distinct RGB color
"""
color_norm = colors.Normalize(vmin=0, vmax=num_classes-1)
scalar_map = cm.ScalarMappable... | 2,079 | 43.255319 | 156 | py |
CvT-ASSD | CvT-ASSD-main/models/CvT/models/utils.py | import torch as t
class AverageMeter(object):
"""Computes and stores the average and current value"""
def __init__(self):
self.count = self.sum = self.avg = self.val = 0
def reset(self):
self.count = self.sum = self.avg = self.val = 0
def update(self, val, n=1):
self.val = val... | 963 | 28.212121 | 72 | py |
CvT-ASSD | CvT-ASSD-main/models/CvT/models/transformer_layers.py | import logging
import torch as t
from torch.nn import Module, LayerNorm, GELU, Linear, Dropout, Sequential, BatchNorm2d, Conv2d, AvgPool2d, functional, \
ModuleList, init, Identity, Parameter
from collections import OrderedDict
from einops import rearrange
from einops.layers.torch import Rearrange
from timm.models.... | 9,199 | 45.938776 | 120 | py |
CvT-ASSD | CvT-ASSD-main/models/CvT/models/show_demo.py | import os
import yaml
from cvt import *
from tqdm import tqdm
import time
import torch.utils.data
from torchvision import transforms
from torchvision import datasets
from torch.nn import CrossEntropyLoss
from utils import AverageMeter, get_accuracy
MODEL_FILE_PATH = '../weights/CvT-21-224x224-IN-1k.pth' # CvT-w24-384... | 4,491 | 46.787234 | 136 | py |
CvT-ASSD | CvT-ASSD-main/models/CvT/models/show_demo_multi_gpu.py |
import os
import yaml
from cvt import *
from tqdm import tqdm
import time
import torch.utils.data
from torchvision import transforms
from torchvision import datasets
from torch.nn import CrossEntropyLoss
from utils import AverageMeter, get_accuracy
MODEL_FILE_PATH = '../weights/CvT-w24-384x384-IN-22k.pth' # CvT-13-2... | 4,726 | 47.234694 | 146 | py |
CvT-ASSD | CvT-ASSD-main/models/VGG_SSD/vgg_ssd.py | from SSD.ssd_model import SSD
from SSD.ssd_utils import L2Norm
from VGG.vgg_d import vgg_layers
import torch
def build_ssd_from_vgg(mode='train', size=300, num_classes = 21):
base_layers, extras_layers, loc_layers, conf_layers = vgg_layers(num_classes)()
model = SSD(base_layers, extras_layers, loc_layers, con... | 507 | 35.285714 | 115 | py |
CvT-ASSD | CvT-ASSD-main/models/VGG_SSD/show_demo.py | """
test for the VGG_SSD model completing
user can view the picture recognition performance .
"""
# import os
# import sys
# module_path = os.path.abspath('..')
# if module_path not in sys.path:
# sys.path.append(module_path) # 添加models环境变量 如果pycharm将models设为sources Root 则不需要.
import torch
from vgg_ssd import b... | 1,839 | 33.716981 | 111 | py |
CvT-ASSD | CvT-ASSD-main/models/VGG/vgg_d.py | from torch import nn
class vgg_layers(object): # model:vgg_d
"""
vgg300 VGG16的D模型
项目根目录下introduce/VGG16的D模型.png 了解更多.
"""
def __init__(self, num_classes):
super(vgg_layers, self).__init__()
self.num_classes = num_classes
self.vgg_base_layers = self.get_vgg_base_laye... | 5,697 | 53.788462 | 116 | py |
CvT-ASSD | CvT-ASSD-main/models/CvT_SSD/cvt_ssd.py | import ctypes
import os
from SSD.ssd_utils import *
from SSD.ssd_model import SSD
from SSD.ssd_utils import L2Norm
from CvT.models.cvt import *
from SSD.ssd_utils import PriorBox
USE224 = True
class CvT_SSD(SSD):
"""基于vgg-SSD进行特性功能重写"""
def __init__(self, base_network, num_classes, mode='train'):
... | 9,421 | 48.329843 | 123 | py |
CvT-ASSD | CvT-ASSD-main/models/SSD/ssd_model.py | import collections
import torch.nn as nn
from SSD.ssd_utils import *
class SSD(nn.Module):
"""SSD 端到端物体探测模型框架 默认feature-extract-base-network: VGG,可通过base_network指定其他骨干网络"""
def __init__(self, base_network, extra_layers, loc_layers, conf_layers, num_classes=21, mode='train', size=300,
l2Nor... | 5,464 | 46.521739 | 119 | py |
CvT-ASSD | CvT-ASSD-main/models/SSD/ssd_utils.py | import logging
from itertools import product
from math import sqrt
import os
import torch
import yaml
from torch.nn import functional as F
CONFIG_FILE = os.path.join(os.path.abspath(os.path.dirname(__file__)),'../../data_preprocess/data_configs.yaml')
try:
with open(CONFIG_FILE, 'r') as yf:
YAML_CONFIG = y... | 14,400 | 40.145714 | 124 | py |
CvT-ASSD | CvT-ASSD-main/models/CvT_ASSD/cvt_assd.py | import ctypes
import os
from SSD.ssd_utils import *
from SSD.ssd_model import SSD
from SSD.ssd_utils import L2Norm
from CvT.models.cvt import *
from SSD.ssd_utils import PriorBox
USE224 = True
class Attention_Unit(t.nn.Module):
"""自注意力机制"""
def __init__(self, hidden_dim):
super(Attention_Unit, self... | 12,040 | 47.35743 | 133 | py |
CvT-ASSD | CvT-ASSD-main/run_scripts/train_multiGpus.py | import os
import argparse
import yaml
import torch
import torch as t
import time
from torch.utils.data import DataLoader
from torch.backends import cudnn
from visdom import Visdom
import logging
import cv2
import numpy as np
from models.SSD.ssd_utils import MultiBoxLoss
from data_preprocess import COCODetection, VOCDet... | 15,280 | 52.059028 | 162 | py |
CvT-ASSD | CvT-ASSD-main/run_scripts/utils.py | import torch
def collect_fn(batch_data):
# return images ,targets 指定batch数据的整理方式
return torch.stack([inst_[0] for inst_ in batch_data], 0), list(map(lambda inst_: torch.FloatTensor(inst_[1]), batch_data))
def update_chart(visdom,window_, step_idx, loc_loss, conf_loss):
visdom.line(
X=[[step_idx]... | 1,550 | 31.3125 | 127 | py |
CvT-ASSD | CvT-ASSD-main/run_scripts/show_demo.py | """
test for the VGG_SSD model completing
user can view the picture recognition performance .
"""
import os
import yaml
# import sys
# module_path = os.path.abspath('..')
# if module_path not in sys.path:
# sys.path.append(module_path) # 添加models环境变量 如果pycharm将models设为sources Root 则不需要.
import torch
from CvT_SS... | 2,480 | 39.016129 | 114 | py |
CvT-ASSD | CvT-ASSD-main/run_scripts/train.py | import os
import argparse
import yaml
import torch
import torch as t
import time
from torch.utils.data import DataLoader
from torch.backends import cudnn
from visdom import Visdom
import logging
import cv2
import numpy as np
from models.SSD.ssd_utils import MultiBoxLoss
from data_preprocess import COCODetection, VOCDet... | 16,761 | 52.382166 | 166 | py |
CvT-ASSD | CvT-ASSD-main/data_preprocess/utils.py | import torch
import cv2
import numpy as np
import types
from numpy import random
def intersect(box_a, box_b):
max_xy = np.minimum(box_a[:, 2:], box_b[2:])
min_xy = np.maximum(box_a[:, :2], box_b[:2])
inter = np.clip((max_xy - min_xy), a_min=0, a_max=np.inf)
return inter[:, 0] * inter[:, 1]
def jacca... | 10,544 | 29.833333 | 91 | py |
CvT-ASSD | CvT-ASSD-main/data_preprocess/__init__.py | """
集成了dataproprocess的工具包,处理数据集包括COCO2014 &VOC07_12
"""
import cv2
import numpy as np
import torch as t
from .COCO.coco import COCODetection, COCO_CLASSES
from .Pascal_VOC.voc import VOCDetection, VOC_CLASSES
detection_collate = lambda batch: (
t.stack([sample[0] for sample in batch]), [t.FloatTensor(sample[1]) f... | 653 | 26.25 | 108 | py |
CvT-ASSD | CvT-ASSD-main/data_preprocess/COCO/coco.py | """预处理COCO2014数据集的工具 COCO2014数据集可在github:https://github.com/albert-jin/CvT-SSD/blob/main/README.md Readme文件 找到并下载"""
import os
import cv2
import numpy as np
import torch
from pycocotools.coco import COCO
from torch.utils.data import Dataset
from .data_configs import *
class COCODetection(Dataset):
"""
c... | 4,060 | 40.865979 | 118 | py |
CvT-ASSD | CvT-ASSD-main/data_preprocess/Pascal_VOC/voc.py | """预处理voc数据集的工具 voc数据集可在github:https://github.com/albert-jin/CvT-SSD/blob/main/README.md Readme文件 找到并下载"""
import os
import sys
import xml.etree.ElementTree as ET
import cv2
import numpy as np
import torch
import torch.utils.data as data
if sys.version_info[0] == 2:
import xml.etree.cElementTree as ET
from .data_... | 3,625 | 41.162791 | 111 | py |
knowledge-distillation-pytorch | knowledge-distillation-pytorch-master/evaluate.py | """Evaluates the model"""
import argparse
import logging
import os
import numpy as np
import torch
from torch.autograd import Variable
import utils
import model.net as net
import model.resnet as resnet
import model.data_loader as data_loader
parser = argparse.ArgumentParser()
parser.add_argument('--model_dir', defau... | 6,637 | 38.047059 | 113 | py |
knowledge-distillation-pytorch | knowledge-distillation-pytorch-master/utils.py | """
Tensorboard logger code referenced from:
https://github.com/yunjey/pytorch-tutorial/blob/master/tutorials/04-utils/
Other helper functions:
https://github.com/cs230-stanford/cs230-stanford.github.io
"""
import json
import logging
import os
import shutil
import torch
from collections import OrderedDict
import tens... | 7,215 | 30.788546 | 109 | py |
knowledge-distillation-pytorch | knowledge-distillation-pytorch-master/count_model_size.py | '''Count # of parameters in a trained model'''
import argparse
import os
import numpy as np
import torch
import utils
import model.net as net
import model.resnet as resnet
import model.wrn as wrn
import model.resnext as resnext
import utils
parser = argparse.ArgumentParser()
# parser.add_argument('--data_dir', defau... | 1,827 | 30.517241 | 97 | py |
knowledge-distillation-pytorch | knowledge-distillation-pytorch-master/distillation_analysis.py | """Analyzes, visualizes knowledge distillation"""
import argparse
import logging
import os
import numpy as np
import torch
import torch.nn.functional as F
from torch.autograd import Variable
import utils
import model.net as net
import model.resnet as resnet
import model.data_loader as data_loader
from torchnet.meter i... | 4,340 | 36.102564 | 101 | py |
knowledge-distillation-pytorch | knowledge-distillation-pytorch-master/train.py | """Main entrance for train/eval with/without KD on CIFAR-10"""
import argparse
import logging
import os
import time
import math
import random
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 import StepLR
from torch.autograd... | 18,561 | 40.900677 | 99 | py |
knowledge-distillation-pytorch | knowledge-distillation-pytorch-master/mnist/teacher_mnist.py | from __future__ import print_function
import argparse
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
from torchvision import datasets, transforms
from torch.autograd import Variable
import os
import time
start_time = time.time()
# Training settings
parser = argparse.Argu... | 5,588 | 36.26 | 93 | py |
knowledge-distillation-pytorch | knowledge-distillation-pytorch-master/mnist/distill_mnist.py | from __future__ import print_function
import argparse
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
from torchvision import datasets, transforms
from torch.autograd import Variable
import os
import time
start_time = time.time()
# Training settings
parser = argparse.Argu... | 6,517 | 36.034091 | 140 | py |
knowledge-distillation-pytorch | knowledge-distillation-pytorch-master/mnist/student_mnist.py | from __future__ import print_function
import argparse
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
from torchvision import datasets, transforms
from torch.autograd import Variable
import os
import time
start_time = time.time()
# Training settings
parser = argparse.Argu... | 6,216 | 38.100629 | 133 | py |
knowledge-distillation-pytorch | knowledge-distillation-pytorch-master/mnist/distill_mnist_unlabeled.py | from __future__ import print_function
import argparse
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
from torchvision import datasets, transforms
from torch.autograd import Variable
import os
import time
start_time = time.time()
# Training settings
parser = argparse.Argu... | 6,447 | 35.636364 | 122 | py |
knowledge-distillation-pytorch | knowledge-distillation-pytorch-master/model/preresnet.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 math
import numpy as np
# __all__ = ['preresnet']
def conv3x3(in_p... | 5,359 | 28.944134 | 119 | py |
knowledge-distillation-pytorch | knowledge-distillation-pytorch-master/model/resnet.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 numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd im... | 4,983 | 31.575163 | 119 | py |
knowledge-distillation-pytorch | knowledge-distillation-pytorch-master/model/data_loader.py | """
CIFAR-10 data normalization reference:
https://github.com/Armour/pytorch-nn-practice/blob/master/utils/meanstd.py
"""
import random
import os
import numpy as np
from PIL import Image
import torch
import torchvision
import torchvision.transforms as transforms
from torch.utils.data.sampler import SubsetRandomS... | 3,862 | 35.443396 | 91 | py |
knowledge-distillation-pytorch | knowledge-distillation-pytorch-master/model/densenet.py | import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
import math
from torch.autograd import Variable
# __all__ = ['densenet']
class Bottleneck(nn.Module):
def __init__(self, inplanes, expansion=4, growthRate=12, dropRate=0):
super(Bottleneck, self).__init__()
plan... | 5,936 | 32.167598 | 119 | py |
knowledge-distillation-pytorch | knowledge-distillation-pytorch-master/model/resnext.py | from __future__ import division
"""
Creates a ResNeXt Model as defined in:
Xie, S., Girshick, R., Dollar, P., Tu, Z., & He, K. (2016).
Aggregated residual transformations for deep neural networks.
arXiv preprint arXiv:1611.05431.
import from https://github.com/prlz77/ResNeXt.pytorch/blob/master/models/model.py
"""
i... | 6,325 | 41.743243 | 144 | py |
knowledge-distillation-pytorch | knowledge-distillation-pytorch-master/model/net.py | """
Baseline CNN, losss function and metrics
Also customizes knowledge distillation (KD) loss function here
"""
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
class Net(nn.Module):
"""
This is the standard way to define your own network in PyTorch. You typically ch... | 5,875 | 42.205882 | 119 | py |
knowledge-distillation-pytorch | knowledge-distillation-pytorch-master/model/wrn.py | import numpy as np
import math
import torch
import torch.nn as nn
import torch.nn.functional as F
# __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)
self.r... | 5,085 | 39.688 | 119 | py |
BSFA-FSFG | BSFA-FSFG-main/test.py | from __future__ import print_function
from __future__ import division
import sys
import time
import argparse
import os.path as osp
import numpy as np
import torch
import torch.backends.cudnn as cudnn
import torch.nn.functional as F
from tqdm import tqdm
from models.net import Model
from data_manager import DataMan... | 5,731 | 37.213333 | 143 | py |
BSFA-FSFG | BSFA-FSFG-main/data_manager.py | from __future__ import absolute_import
from __future__ import print_function
from torch.utils.data import DataLoader
from utils import transforms as T
import datasets
import dataset_loader
class DataManager(object):
"""
Few shot data manager
"""
def __init__(self, args, use_gpu):
super(DataM... | 3,447 | 36.478261 | 84 | py |
BSFA-FSFG | BSFA-FSFG-main/train.py | from __future__ import print_function
from __future__ import division
import os
import sys
import datetime
import time
import argparse
import os.path as osp
import numpy as np
import torch
import torch.nn as nn
import torch.backends.cudnn as cudnn
import torch.nn.functional as F
from tqdm import tqdm
from models.ne... | 10,928 | 38.741818 | 147 | py |
BSFA-FSFG | BSFA-FSFG-main/models/resnet12.py | import math
import torch
import torch.nn as nn
import torch.nn.functional as F
def conv3x3(in_planes, out_planes, stride=1):
"""3x3 convolution with padding"""
return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride,
padding=1, bias=False)
class BasicBlock(nn.Module):
e... | 4,742 | 29.403846 | 86 | py |
BSFA-FSFG | BSFA-FSFG-main/models/conv4.py | import torch.nn as nn
import torch
# Basic ConvNet with Pooling layer
def conv_block(in_channels, out_channels):
return nn.Sequential(
nn.Conv2d(in_channels, out_channels, 3, padding=1),
nn.BatchNorm2d(out_channels),
nn.ReLU(),
nn.MaxPool2d(2)
)
class ConvNet4(nn.Module):
d... | 705 | 25.148148 | 59 | py |
BSFA-FSFG | BSFA-FSFG-main/models/net.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torchvision import utils as vutils
from models.resnet12 import resnet12
from models.conv4 import ConvNet4
from .xcos import Xcos
from .BAS import crop_featuremaps, drop_featuremaps
class Model(nn.Module):
def __init__(self, num_classes=64, ... | 3,490 | 28.336134 | 93 | py |
BSFA-FSFG | BSFA-FSFG-main/models/BAS.py | import torch
from skimage import measure
import torch.nn.functional as F
import math
import torch.nn as nn
def AOLM(feature_maps):
width = feature_maps.size(-1)
height = feature_maps.size(-2)
A = torch.sum(feature_maps, dim=1, keepdim=True)
a = torch.mean(A, dim=[2, 3], keepdim=True)
M = (A > a).fl... | 2,064 | 29.367647 | 99 | py |
BSFA-FSFG | BSFA-FSFG-main/models/xcos.py | import torch
import torch.nn as nn
import torch.nn.functional as F
cos = nn.CosineSimilarity(dim=1, eps=1e-6)
def Xcos(ftrain, ftest):
B, n2, n1, C, H, W = ftrain.size()
ftrain = Long_alignment(ftrain, ftest)
ftrain = ftrain.view(-1, C, H, W).permute(0, 2, 3, 1)
ftest = ftest.view(-1, C, H, W).pe... | 1,083 | 23.636364 | 62 | py |
BSFA-FSFG | BSFA-FSFG-main/datasets/Dogs.py | from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
import torch
import os.path as osp
class StanfordDogs(object):
"""
Dataset statistics:
# 64 * 600 (train) + 16 * 600 (val) + 20 * 600 (test)
"""
dataset_dir = '/home/facegroup/zz... | 3,238 | 42.186667 | 100 | py |
BSFA-FSFG | BSFA-FSFG-main/datasets/Cars.py | from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
import torch
import os.path as osp
class StanfordCars(object):
"""
Dataset statistics:
# 130 (train) + 17 (val) + 49 (test)
"""
dataset_dir = '/home/facegroup/zzc/Datasets/Fine... | 3,224 | 40.883117 | 100 | py |
BSFA-FSFG | BSFA-FSFG-main/datasets/CUB.py | from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
import torch
import os.path as osp
class CUB_200_2011(object):
"""
Dataset statistics:
# 64 * 600 (train) + 16 * 600 (val) + 20 * 600 (test)
"""
# dataset_dir = '/home/10701006/... | 3,415 | 42.794872 | 100 | py |
BSFA-FSFG | BSFA-FSFG-main/utils/losses.py | from __future__ import absolute_import
from __future__ import division
import torch
import torch.nn as nn
class CrossEntropyLoss(nn.Module):
def __init__(self):
super(CrossEntropyLoss, self).__init__()
self.logsoftmax = nn.LogSoftmax(dim=1)
def forward(self, inputs, targets):
inputs =... | 688 | 31.809524 | 109 | py |
BSFA-FSFG | BSFA-FSFG-main/utils/torchtools.py | from __future__ import absolute_import
from __future__ import division
import torch
import torch.nn as nn
def open_all_layers(model):
"""
Open all layers in model for training.
"""
model.train()
for p in model.parameters():
p.requires_grad = True
def open_specified_layers(model, open_la... | 2,776 | 28.231579 | 128 | py |
BSFA-FSFG | BSFA-FSFG-main/utils/avgmeter.py | from __future__ import absolute_import
from __future__ import division
class AverageMeter(object):
"""Computes and stores the average and current value.
Code imported from https://github.com/pytorch/examples/blob/master/imagenet/main.py#L247-L262
"""
def __init__(self):
self.reset()... | 577 | 24.130435 | 100 | py |
BSFA-FSFG | BSFA-FSFG-main/utils/optimizers.py | from __future__ import absolute_import
import torch
def init_optimizer(optim, params, lr, weight_decay):
if optim == 'adam':
return torch.optim.Adam(params, lr=lr, weight_decay=weight_decay)
elif optim == 'amsgrad':
return torch.optim.Adam(params, lr=lr, weight_decay=weight_decay, amsgrad=Tru... | 646 | 37.058824 | 101 | py |
BSFA-FSFG | BSFA-FSFG-main/utils/__init__.py | from .avgmeter import *
from .iotools import *
from .logger import *
from .torchtools import *
| 96 | 15.166667 | 25 | py |
BSFA-FSFG | BSFA-FSFG-main/utils/iotools.py | from __future__ import absolute_import
import os
import os.path as osp
import errno
import json
import shutil
import torch
def mkdir_if_missing(directory):
if not osp.exists(directory):
try:
os.makedirs(directory)
except OSError as e:
if e.errno != errno.EEXIST:
... | 1,010 | 21.466667 | 77 | py |
BSFA-FSFG | BSFA-FSFG-main/utils/transforms.py | from __future__ import absolute_import
from __future__ import division
from torchvision.transforms import *
from PIL import Image
import random
import numpy as np
import math
import torch
class Random2DTranslation(object):
"""
With a probability, first increase image size to (1 + 1/8), and then perform rand... | 3,187 | 34.032967 | 104 | py |
BSFA-FSFG | BSFA-FSFG-main/dataset_loader/test_loader.py | from __future__ import absolute_import
from __future__ import print_function
from __future__ import division
import os
from PIL import Image
import numpy as np
import os.path as osp
# import lmdb
import io
import random
import torch
from torch.utils.data import Dataset
def read_image(img_path):
"""Keep reading ... | 4,741 | 31.479452 | 109 | py |
BSFA-FSFG | BSFA-FSFG-main/dataset_loader/train_loader.py | from __future__ import absolute_import
from __future__ import print_function
from __future__ import division
import os
from PIL import Image
import numpy as np
import os.path as osp
# import lmdb
import io
import random
import torch
from torch.utils.data import Dataset
def read_image(img_path):
"""Keep reading ... | 4,584 | 31.985612 | 109 | py |
MAE-pytorch | MAE-pytorch-main/engine_for_finetuning.py | # --------------------------------------------------------
# Based on BEiT, timm, DINO and DeiT code bases
# https://github.com/microsoft/unilm/tree/master/beit
# https://github.com/rwightman/pytorch-image-models/tree/master/timm
# https://github.com/facebookresearch/deit
# https://github.com/facebookresearch/dino
# --... | 7,411 | 39.502732 | 114 | py |
MAE-pytorch | MAE-pytorch-main/run_mae_vis.py | # -*- coding: utf-8 -*-
# @Time : 2021/11/18 22:40
# @Author : zhao pengfei
# @Email : zsonghuan@gmail.com
# @File : run_mae_vis.py
# --------------------------------------------------------
# Based on BEiT, timm, DINO and DeiT code bases
# https://github.com/microsoft/unilm/tree/master/beit
# https://github.c... | 5,296 | 37.384058 | 144 | py |
MAE-pytorch | MAE-pytorch-main/run_class_finetuning.py | # --------------------------------------------------------
# Based on BEiT, timm, DINO and DeiT code bases
# https://github.com/microsoft/unilm/tree/master/beit
# https://github.com/rwightman/pytorch-image-models/tree/master/timm
# https://github.com/facebookresearch/deit
# https://github.com/facebookresearch/dino
# --... | 24,435 | 46.540856 | 121 | py |
MAE-pytorch | MAE-pytorch-main/modeling_pretrain.py | # --------------------------------------------------------
# Based on BEiT, timm, DINO and DeiT code bases
# https://github.com/microsoft/unilm/tree/master/beit
# https://github.com/rwightman/pytorch-image-models/tree/master/timm
# https://github.com/facebookresearch/deit
# https://github.com/facebookresearch/dino
# --... | 12,885 | 35.504249 | 110 | py |
MAE-pytorch | MAE-pytorch-main/modeling_finetune.py | # --------------------------------------------------------
# Based on BEiT, timm, DINO and DeiT code bases
# https://github.com/microsoft/unilm/tree/master/beit
# https://github.com/rwightman/pytorch-image-models/tree/master/timm
# https://github.com/facebookresearch/deit
# https://github.com/facebookresearch/dino
# --... | 12,917 | 36.994118 | 112 | py |
MAE-pytorch | MAE-pytorch-main/utils.py | # --------------------------------------------------------
# --------------------------------------------------------
# Based on BEiT, timm, DINO and DeiT code bases
# https://github.com/microsoft/unilm/tree/master/beit
# https://github.com/rwightman/pytorch-image-models/tree/master/timm
# https://github.com/facebookre... | 17,887 | 33.9375 | 128 | py |
MAE-pytorch | MAE-pytorch-main/engine_for_pretraining.py | # --------------------------------------------------------
# Based on BEiT, timm, DINO and DeiT code bases
# https://github.com/microsoft/unilm/tree/master/beit
# https://github.com/rwightman/pytorch-image-models/tree/master/timm
# https://github.com/facebookresearch/deit
# https://github.com/facebookresearch/dino
# --... | 5,497 | 45.991453 | 129 | py |
MAE-pytorch | MAE-pytorch-main/dataset_folder.py | # --------------------------------------------------------
# Based on BEiT, timm, DINO and DeiT code bases
# https://github.com/microsoft/unilm/tree/master/beit
# https://github.com/rwightman/pytorch-image-models/tree/master/timm
# https://github.com/facebookresearch/deit
# https://github.com/facebookresearch/dino
# --... | 9,060 | 35.833333 | 113 | py |
MAE-pytorch | MAE-pytorch-main/masking_generator.py | # --------------------------------------------------------
# Based on BEiT, timm, DINO and DeiT code bases
# https://github.com/microsoft/unilm/tree/master/beit
# https://github.com/rwightman/pytorch-image-models/tree/master/timm
# https://github.com/facebookresearch/deit
# https://github.com/facebookresearch/dino
# --... | 1,133 | 32.352941 | 68 | py |
MAE-pytorch | MAE-pytorch-main/datasets.py | # --------------------------------------------------------
# Based on BEiT, timm, DINO and DeiT code bases
# https://github.com/microsoft/unilm/tree/master/beit
# https://github.com/rwightman/pytorch-image-models/tree/master/timm
# https://github.com/facebookresearch/deit
# https://github.com/facebookresearch/dino
# --... | 4,793 | 34.776119 | 102 | py |
MAE-pytorch | MAE-pytorch-main/run_mae_pretraining.py | # --------------------------------------------------------
# Based on BEiT, timm, DINO and DeiT code bases
# https://github.com/microsoft/unilm/tree/master/beit
# https://github.com/rwightman/pytorch-image-models/tree/master/timm
# https://github.com/facebookresearch/deit
# https://github.com/facebookresearch/dino
# --... | 11,335 | 41.616541 | 116 | py |
MAE-pytorch | MAE-pytorch-main/optim_factory.py | # --------------------------------------------------------
# Based on BEiT, timm, DINO and DeiT code bases
# https://github.com/microsoft/unilm/tree/master/beit
# https://github.com/rwightman/pytorch-image-models/tree/master/timm
# https://github.com/facebookresearch/deit
# https://github.com/facebookresearch/dino
# --... | 6,977 | 37.131148 | 117 | py |
MAE-pytorch | MAE-pytorch-main/transforms.py | # --------------------------------------------------------
# Based on BEiT, timm, DINO and DeiT code bases
# https://github.com/microsoft/unilm/tree/master/beit
# https://github.com/rwightman/pytorch-image-models/tree/master/timm
# https://github.com/facebookresearch/deit
# https://github.com/facebookresearch/dino
# --... | 6,585 | 35.588889 | 118 | py |
BigGAN-PyTorch | BigGAN-PyTorch-master/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
imp... | 4,971 | 44.2 | 178 | py |
BigGAN-PyTorch | BigGAN-PyTorch-master/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 |
BigGAN-PyTorch | BigGAN-PyTorch-master/sample.py | ''' Sample
This script loads a pretrained net and a weightsfile and sample '''
import functools
import math
import numpy as np
from tqdm import tqdm, trange
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
i... | 8,346 | 44.612022 | 157 | py |
BigGAN-PyTorch | BigGAN-PyTorch-master/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 |
BigGAN-PyTorch | BigGAN-PyTorch-master/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,366 | 44.472826 | 149 | py |
BigGAN-PyTorch | BigGAN-PyTorch-master/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
# Architectures for G
# Att... | 19,726 | 42.740576 | 98 | py |
BigGAN-PyTorch | BigGAN-PyTorch-master/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... | 48,656 | 39.751256 | 109 | py |
BigGAN-PyTorch | BigGAN-PyTorch-master/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 |
BigGAN-PyTorch | BigGAN-PyTorch-master/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... | 11,416 | 30.451791 | 139 | py |
BigGAN-PyTorch | BigGAN-PyTorch-master/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 Generat... | 12,310 | 38.712903 | 136 | py |
BigGAN-PyTorch | BigGAN-PyTorch-master/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 |
BigGAN-PyTorch | BigGAN-PyTorch-master/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,153 | 39.325991 | 124 | py |
BigGAN-PyTorch | BigGAN-PyTorch-master/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 |
BigGAN-PyTorch | BigGAN-PyTorch-master/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 |
BigGAN-PyTorch | BigGAN-PyTorch-master/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 |
BigGAN-PyTorch | BigGAN-PyTorch-master/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 |
BigGAN-PyTorch | BigGAN-PyTorch-master/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 |
BigGAN-PyTorch | BigGAN-PyTorch-master/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 |
df | df-master/model.py | from keras.models import Model
from keras.layers import Input, Dense, Flatten, Reshape, Dropout, Add,Concatenate, Lambda
from keras.layers.advanced_activations import LeakyReLU
from keras.layers.convolutional import Conv2D
from keras.initializers import RandomNormal
from keras.optimizers import Adam
from pixel_shuffle... | 4,215 | 24.245509 | 122 | py |
df | df-master/exampleTrainer.py |
from utils import get_image_paths, load_images, stack_images
from training_data import get_training_data
import random
import numpy
import cv2
from keras.models import Model
from keras.layers import Input, Dense, Flatten, Reshape, concatenate, Add, add, Dropout
from keras.layers.advanced_activations import LeakyReLU... | 14,486 | 31.776018 | 139 | py |
df | df-master/pixel_shuffler.py | # PixelShuffler layer for Keras
# by t-ae
# https://gist.github.com/t-ae/6e1016cc188104d123676ccef3264981
from keras.utils import conv_utils
from keras.engine.topology import Layer
import keras.backend as K
class PixelShuffler(Layer):
def __init__(self, size=(2, 2), data_format=None, **kwargs):
super(Pixe... | 3,382 | 37.443182 | 90 | py |
what-is-where-by-looking | what-is-where-by-looking-main/base.py | import torch
import torch.nn as nn
import torch.nn.functional as F
class SkipUpBlock(nn.Module):
def __init__(self, in_channels, out_channels, kernel_size=3, drop=0, func=None):
super(SkipUpBlock, self).__init__()
d = drop
P = int((kernel_size - 1) / 2)
self.Upsample = nn.Upsample(... | 8,711 | 41.497561 | 93 | py |
what-is-where-by-looking | what-is-where-by-looking-main/train_grounding.py | import torch.optim as optim
import torch.utils.data
import torch.nn as nn
from tqdm import tqdm
import os
import numpy as np
from model import *
from datasets.flicker import get_flicker1K_dataset, get_flicker_dataset
from datasets.visual_genome import get_VG_dataset
from datasets.coco import get_coco_dataset
from ut... | 9,378 | 48.363158 | 116 | py |
what-is-where-by-looking | what-is-where-by-looking-main/wwbl_algo1_point_metric.py | import torch.utils.data
import os
from datasets.flicker import get_flicker1K_dataset
from datasets.referit_loader import get_refit_test_dataset
from datasets.visual_genome import get_VGtest_dataset
from utils_grounding import *
import clip
from tqdm import tqdm
import pickle
def norm_z(z):
return z / z.norm(dim... | 4,123 | 39.431373 | 110 | py |
what-is-where-by-looking | what-is-where-by-looking-main/inference_grounding.py | import torch.utils.data
import os
from model import *
from datasets.flicker import get_flicker1K_dataset
from datasets.referit_loader import get_refit_test_dataset
from datasets.visual_genome import get_VGtest_dataset
from utils_grounding import *
from utils import interpret, interpret_batch, interpret_new
import CLI... | 15,713 | 47.350769 | 147 | py |
what-is-where-by-looking | what-is-where-by-looking-main/utils.py | import cv2
import matplotlib.pyplot as plt
import torch
import numpy as np
import torch.nn.functional as F
from scipy.ndimage import gaussian_filter
def rand_bbox(size, lam, center=False, attcen=None):
if len(size) == 4:
W = size[2]
H = size[3]
elif len(size) == 3:
W = size[1]
... | 16,160 | 37.478571 | 120 | py |
what-is-where-by-looking | what-is-where-by-looking-main/bbox.py | from typing import List
import torch
from torch import Tensor
class BBox(object):
def __init__(self, left: float, top: float, right: float, bottom: float):
super().__init__()
self.left = left
self.top = top
self.right = right
self.bottom = bottom
def __repr__(self) -... | 4,250 | 45.714286 | 114 | py |
what-is-where-by-looking | what-is-where-by-looking-main/utils_grounding.py | from skimage.feature import peak_local_max
import cv2
import numpy as np
import matplotlib.pyplot as plt
from scipy import ndimage as ndi
import sys
import torch
# from support.layer.nms import nms
import torchvision
from skimage import filters
from skimage.measure import regionprops
rel_peak_thr = .3
rel_rel_thr = ... | 18,658 | 36.021825 | 141 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.