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 |
|---|---|---|---|---|---|---|
MSSR | MSSR-main/degradation/codes/evaluate.py | import argparse
import sys
from os import listdir
from os.path import join, basename
from tqdm import tqdm
from PIL import Image
from skimage.measure import compare_psnr, compare_ssim
import numpy as np
import torch
import utils
sys.path.append('../PerceptualSimilarity')
sys.path.append('../')
import PerceptualSimilari... | 2,500 | 38.698413 | 109 | py |
MSSR | MSSR-main/degradation/codes/receptive_cal.py | import torch
import numpy as np
import torch.nn as nn
import functools
import math
def outFromIn(conv, layerIn):
n_in = layerIn[0]
j_in = layerIn[1]
r_in = layerIn[2]
start_in = layerIn[3]
k = conv[0]
s = conv[1]
p = conv[2]
n_out = math.floor((n_in - k + 2 * p) / s) + 1
actualP =... | 2,307 | 30.616438 | 103 | py |
MSSR | MSSR-main/degradation/codes/create_dataset_modified.py | import argparse
import os
import torch.utils.data
import yaml
import model
import utils
from PIL import Image
import torchvision.transforms.functional as TF
from tqdm import tqdm
from receptive_cal import *
import numpy as np
import hanmodel
def domain_distance_map_handler(fake_img, D_out, convnet, fs_type):
if fs... | 10,610 | 52.590909 | 121 | py |
MSSR | MSSR-main/degradation/codes/data_loader.py | from os import listdir
from os.path import join
from PIL import Image
from torch.utils.data.dataset import Dataset
import torchvision.transforms as T
import torchvision.transforms.functional as TF
import random
import utils
import numpy as np
class Train_Deresnet_Dataset(Dataset):
def __init__(self, noisy_dir, cl... | 8,209 | 41.760417 | 128 | py |
MSSR | MSSR-main/degradation/codes/loss.py | import torch
import random
from torch import nn
from torchvision.models.vgg import vgg16, vgg19
from model import FilterLow
import sys
# need to correct this code
# sys.path.insert(0, '/mnt/workspace/DASR/codes')
sys.path.insert(0, '../')
import PerceptualSimilarity.models.util as ps
from pytorch_wavelets import DWTFo... | 6,614 | 37.459302 | 119 | py |
MSSR | MSSR-main/degradation/codes/utils.py | from PIL import Image
from torchvision.transforms import Compose, ToTensor, ToPILImage, CenterCrop, Resize
import numpy as np
import torch
import math
import os
from torchvision import transforms
# set random seed for reproducibility
np.random.seed(0)
def is_image_file(filename):
return any(filename.endswith(ext... | 7,586 | 39.790323 | 112 | py |
MSSR | MSSR-main/degradation/codes/model.py | from torch import nn
import torch
import functools
import torch.nn.functional as F
from pytorch_wavelets import DWTForward
class NoiseInjection(nn.Module):
def __init__(self, channel, std):
super().__init__()
self.channel = channel
self.std = std
self.w = torch.nn.Parameter(torch.ze... | 13,296 | 38.340237 | 131 | py |
MSSR | MSSR-main/degradation/codes/edsr.py | from torch import nn
import torch
import math
import utils
from torchvision import transforms
import os
def default_conv(in_channels, out_channels, kernel_size, bias=True, stride=1):
return nn.Conv2d(
in_channels, out_channels, kernel_size,stride,
padding=(kernel_size//2), bias=bias)
class NoiseInje... | 6,698 | 32 | 130 | py |
MSSR | MSSR-main/degradation/codes/create_dataset.py | import argparse
import os
import torch.utils.data
import yaml
import model
import utils
from PIL import Image
import torchvision.transforms.functional as TF
from tqdm import tqdm
parser = argparse.ArgumentParser(description='Apply the trained model to create a dataset')
parser.add_argument('--checkpoint', default=Non... | 6,515 | 44.566434 | 118 | py |
MSSR | MSSR-main/degradation/codes/train.py | import argparse
import os
from PIL import Image
import numpy as np
import torch.optim as optim
import torch.utils.data
import torchvision.utils as tvutils
import data_loader as loader
import yaml
import loss
import model
import utils
import json
import hanmodel
from torch.utils.data import DataLoader
from tensorboardX ... | 23,567 | 52.081081 | 173 | py |
MSSR | MSSR-main/degradation/codes/hanmodel/rcan3.py | from model import common
import torch
import torch.nn as nn
from torch.autograd import Variable
import pdb
import numpy as np
import math
def make_model(args, parent=False):
return RCAN(args)
## Channel Attention (CA) Layer
class CALayer(nn.Module):
def __init__(self, channel, reduction=16):
super(CAL... | 22,423 | 34.147335 | 126 | py |
MSSR | MSSR-main/degradation/codes/hanmodel/rcan.py | from model import common
import torch
import torch.nn as nn
import numpy as np
import pdb
def make_model(args, parent=False):
return RCAN(args)
## Channel Attention (CA) Layer
class CALayer(nn.Module):
def __init__(self, channel, reduction=16):
super(CALayer, self).__init__()
# global average ... | 7,347 | 36.299492 | 116 | py |
MSSR | MSSR-main/degradation/codes/hanmodel/rdn2.py | # Residual Dense Network for Image Super-Resolution
# https://arxiv.org/abs/1802.08797
from model import common
import torch
import torch.nn as nn
def make_model(args, parent=False):
return RDN(args)
class RDB_Conv(nn.Module):
def __init__(self, inChannels, growRate, kSize=3):
super(RDB_Conv, self)... | 4,712 | 29.406452 | 90 | py |
MSSR | MSSR-main/degradation/codes/hanmodel/rcan1.py | from model import common
import torch.nn as nn
import torch
import torch.nn.init as init
import pdb
def make_model(args, parent=False):
return RCAN(args)
## Channel Attention (CA) Layer
class CALayer(nn.Module):
def __init__(self, channel, reduction=16):
super(CALayer, self).__init__()
# glob... | 17,848 | 39.110112 | 160 | py |
MSSR | MSSR-main/degradation/codes/hanmodel/ddbpn.py | # Deep Back-Projection Networks For Super-Resolution
# https://arxiv.org/abs/1803.02735
from model import common
import torch
import torch.nn as nn
def make_model(args, parent=False):
return DDBPN(args)
def projection_conv(in_channels, out_channels, scale, up=True):
kernel_size, stride, padding = {
... | 3,629 | 26.5 | 78 | py |
MSSR | MSSR-main/degradation/codes/hanmodel/rdn.py | # Residual Dense Network for Image Super-Resolution
# https://arxiv.org/abs/1802.08797
from model import common
import torch
import torch.nn as nn
def make_model(args, parent=False):
return RDN(args)
class RDB_Conv(nn.Module):
def __init__(self, inChannels, growRate, kSize=3):
super(RDB_Conv, self)... | 3,201 | 29.495238 | 90 | py |
MSSR | MSSR-main/degradation/codes/hanmodel/han.py | from hanmodel import common
import torch
import torch.nn as nn
import pdb
def make_model(args, parent=False):
return HAN(args)
## Channel Attention (CA) Layer
class CALayer(nn.Module):
def __init__(self, channel, reduction=16):
super(CALayer, self).__init__()
# global average pooling: feature ... | 10,004 | 32.686869 | 115 | py |
MSSR | MSSR-main/degradation/codes/hanmodel/matrixmodel.py | # ------------------------------------------------------------------------------
# Copyright (c) Microsoft
# Licensed under the MIT License.
# Written by Bin Xiao (Bin.Xiao@microsoft.com)
# ------------------------------------------------------------------------------
from __future__ import absolute_import
from __futu... | 75,664 | 36.908317 | 147 | py |
MSSR | MSSR-main/degradation/codes/hanmodel/han2.py | ## Down-Sample at last layer
from hanmodel import common
import torch
import torch.nn as nn
import pdb
import neptune
def make_model(args, parent=False):
return HAN(args)
## Channel Attention (CA) Layer
class CALayer(nn.Module):
def __init__(self, channel, reduction=16):
super(CALayer, self).__init__... | 10,160 | 32.87 | 173 | py |
MSSR | MSSR-main/degradation/codes/hanmodel/mdsr.py | from model import common
import torch.nn as nn
url = {
'r16f64': 'https://cv.snu.ac.kr/research/EDSR/models/mdsr_baseline-a00cab12.pt',
'r80f64': 'https://cv.snu.ac.kr/research/EDSR/models/mdsr-4a78bedf.pt'
}
def make_model(args, parent=False):
return MDSR(args)
class MDSR(nn.Module):
def __init__(s... | 1,926 | 27.338235 | 84 | py |
MSSR | MSSR-main/degradation/codes/hanmodel/rdn1.py | # Residual Dense Network for Image Super-Resolution
# https://arxiv.org/abs/1802.08797
from model import common
import torch
import torch.nn as nn
def make_model(args, parent=False):
return RDN(args)
class RDB_Conv(nn.Module):
def __init__(self, inChannels, growRate, kSize=(3,3,3)):
super(RDB_Conv,... | 4,564 | 29.231788 | 90 | py |
MSSR | MSSR-main/degradation/codes/hanmodel/common.py | import math
import torch
import torch.nn as nn
import torch.nn.functional as F
def default_conv(in_channels, out_channels, kernel_size, bias=True, stride=1):
return nn.Conv2d(
in_channels, out_channels, kernel_size, stride=stride,
padding=(kernel_size//2), bias=bias)
class MeanShift(nn.Conv2d):
... | 2,807 | 30.550562 | 81 | py |
MSSR | MSSR-main/degradation/codes/hanmodel/rcan4.py | from model import common
import torch
import torch.nn as nn
import pdb
def make_model(args, parent=False):
return RCAN(args)
## Channel Attention (CA) Layer
class CALayer(nn.Module):
def __init__(self, channel, reduction=16):
super(CALayer, self).__init__()
# global average pooling: feature --... | 8,623 | 34.344262 | 116 | py |
MSSR | MSSR-main/degradation/codes/hanmodel/__init__.py | import os
from importlib import import_module
import torch
import torch.nn as nn
import torch.nn.parallel as P
import torch.utils.model_zoo
class Model(nn.Module):
def __init__(self, args, ckp):
super(Model, self).__init__()
print('Making model...')
self.scale = args.upscale_factor
... | 6,498 | 32.673575 | 90 | py |
MSSR | MSSR-main/degradation/codes/hanmodel/ops.py | '''EoctConv'''
import torch.nn as nn
import torch.nn.functional as F
import torch
import numpy as np
import math
import pdb
BN_MOMENTUM = 0.1
class EoctConv(nn.Module):
def __init__(self, in_channels, num_channels, kernel_size=3, stride=1, padding=1, bias=True, name=None):
super(EoctConv, self).__init__()
... | 12,527 | 39.543689 | 167 | py |
MSSR | MSSR-main/degradation/codes/hanmodel/edsr.py | from hanmodel import common
import torch.nn as nn
url = {
'r16f64x2': 'https://cv.snu.ac.kr/research/EDSR/models/edsr_baseline_x2-1bc95232.pt',
'r16f64x3': 'https://cv.snu.ac.kr/research/EDSR/models/edsr_baseline_x3-abf2a44e.pt',
'r16f64x4': 'https://cv.snu.ac.kr/research/EDSR/models/edsr_baseline_x4-6b44... | 3,034 | 34.290698 | 95 | py |
MSSR | MSSR-main/degradation/codes/hanmodel/vdsr.py | from model import common
import torch.nn as nn
import torch.nn.init as init
url = {
'r20f64': ''
}
def make_model(args, parent=False):
return VDSR(args)
class VDSR(nn.Module):
def __init__(self, args, conv=common.default_conv):
super(VDSR, self).__init__()
n_resblocks = args.n_resblocks... | 1,275 | 26.148936 | 73 | py |
MSSR | MSSR-main/degradation/codes/hanmodel/dcn/deform_conv.py | import math
import logging
import torch
import torch.nn as nn
from torch.autograd import Function
from torch.autograd.function import once_differentiable
from torch.nn.modules.utils import _pair
from . import deform_conv_cuda
logger = logging.getLogger('base')
class DeformConvFunction(Function):
@staticmethod
... | 12,234 | 40.900685 | 99 | py |
MSSR | MSSR-main/degradation/codes/hanmodel/dcn/setup.py | from setuptools import setup
from torch.utils.cpp_extension import BuildExtension, CUDAExtension
def make_cuda_ext(name, sources):
return CUDAExtension(
name='{}'.format(name), sources=[p for p in sources], extra_compile_args={
'cxx': [],
'nvcc': [
'-D__CUDA_NO_HAL... | 711 | 29.956522 | 93 | py |
MSSR | MSSR-main/sr/srresnet_arch.py | from torch import nn as nn
from torch.nn import functional as F
from basicsr.utils.registry import ARCH_REGISTRY
from .arch_util import ResidualBlockNoBN, default_init_weights, make_layer
@ARCH_REGISTRY.register()
class MSRResNet(nn.Module):
"""Modified SRResNet.
A compacted version modified from SRResNet i... | 2,878 | 35.910256 | 79 | py |
MSSR | MSSR-main/sr/stylegan2_arch.py | import math
import random
import torch
from torch import nn
from torch.nn import functional as F
from basicsr.ops.fused_act import FusedLeakyReLU, fused_leaky_relu
from basicsr.ops.upfirdn2d import upfirdn2d
from basicsr.utils.registry import ARCH_REGISTRY
class NormStyleCode(nn.Module):
def forward(self, x):
... | 32,177 | 33.862405 | 102 | py |
MSSR | MSSR-main/sr/edvr_arch.py | import torch
from torch import nn as nn
from torch.nn import functional as F
from basicsr.utils.registry import ARCH_REGISTRY
from .arch_util import DCNv2Pack, ResidualBlockNoBN, make_layer
class PCDAlignment(nn.Module):
"""Alignment module using Pyramid, Cascading and Deformable convolution
(PCD). It is use... | 16,986 | 39.253555 | 79 | py |
MSSR | MSSR-main/sr/contsr_train.py | import rrdbnet_arch
import torch
from dataset import *
from utils import *
import json
import argparse
import contsr_model
from collections import namedtuple
def main():
from types import SimpleNamespace
with open('config_cont.json') as json_file:
json_data = json.load(json_file)
... | 912 | 17.632653 | 71 | py |
MSSR | MSSR-main/sr/discriminator_arch.py | from torch import nn as nn
from basicsr.utils.registry import ARCH_REGISTRY
@ARCH_REGISTRY.register()
class VGGStyleDiscriminator128(nn.Module):
"""VGG style discriminator with input size 128 x 128.
It is used to train SRGAN and ESRGAN.
Args:
num_in_ch (int): Channel number of inputs. Default: ... | 3,303 | 36.977011 | 77 | py |
MSSR | MSSR-main/sr/ridnet_arch.py | import torch
import torch.nn as nn
from basicsr.utils.registry import ARCH_REGISTRY
from .arch_util import ResidualBlockNoBN, make_layer
class MeanShift(nn.Conv2d):
""" Data normalization with mean and std.
Args:
rgb_range (int): Maximum value of RGB.
rgb_mean (list[float]): Mean for RGB cha... | 6,771 | 31.401914 | 79 | py |
MSSR | MSSR-main/sr/inception.py | # Modified from https://github.com/mseitzer/pytorch-fid/blob/master/pytorch_fid/inception.py # noqa: E501
# For FID metric
import os
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.utils.model_zoo import load_url
from torchvision import models
# Inception weights ported to Pytorch from
#... | 12,278 | 36.898148 | 140 | py |
MSSR | MSSR-main/sr/vgg_arch.py | import os
import torch
from collections import OrderedDict
from torch import nn as nn
from torchvision.models import vgg as vgg
from basicsr.utils.registry import ARCH_REGISTRY
VGG_PRETRAIN_PATH = 'experiments/pretrained_models/vgg19-dcbb9e9d.pth'
NAMES = {
'vgg11': [
'conv1_1', 'relu1_1', 'pool1', 'conv2... | 6,306 | 35.04 | 79 | py |
MSSR | MSSR-main/sr/rrdbnet_arch.py | import torch
from torch import nn as nn
from torch.nn import functional as F
import sys
sys.path.append('../')
from basicsr.utils.registry import ARCH_REGISTRY
from arch_util import default_init_weights, make_layer
class ResidualDenseBlock(nn.Module):
"""Residual Dense Block.
Used in RRDB block in ESRGAN.
... | 4,404 | 34.24 | 79 | py |
MSSR | MSSR-main/sr/utils2.py | from torchvision import transforms
from PIL import Image
import os
from torch import nn
import torch
import glob
def tensor2pil(t):
img = transforms.functional.to_pil_image(denorm(t))
return img
def denorm(t):
return t*0.5 + 0.5
def tensor_imsave(t, path, fname, denormalization=False, prt=True):
# Save... | 4,089 | 33.369748 | 136 | py |
MSSR | MSSR-main/sr/utils.py | from torchvision import transforms
from PIL import Image
import os
from torch import nn
import torch
import glob
def tensor2pil(t):
img = transforms.functional.to_pil_image(denorm(t))
return img
def denorm(t):
return t*0.5 + 0.5
def tensor_imsave(t, path, fname, denormalization=False, prt=True):
# Save... | 4,496 | 34.132813 | 137 | py |
MSSR | MSSR-main/sr/model.py | # from torch import nn
# import torch
# import functools
# import torch.nn.functional as F
# from pytorch_wavelets import DWTForward
# class NoiseInjection(nn.Module):
# def __init__(self, channel, std):
# super().__init__()
# self.channel = channel
# self.std = std
# self.w = torch... | 26,802 | 38.649408 | 133 | py |
MSSR | MSSR-main/sr/arch_util.py | import math
import torch
from torch import nn as nn
from torch.nn import functional as F
from torch.nn import init as init
from torch.nn.modules.batchnorm import _BatchNorm
# from basicsr.ops.dcn import ModulatedDeformConvPack, modulated_deform_conv
from basicsr.utils import get_root_logger
@torch.no_grad()
def defa... | 8,594 | 33.38 | 80 | py |
MSSR | MSSR-main/sr/dataset.py | import torch.utils.data as data
import random
from PIL import Image
from torchvision import transforms
import os
import os.path
from utils import *
from transforms import *
import torchvision.transforms.functional as TF
import random
def has_file_allowed_extension(filename, extensions):
"""Checks if a file is an al... | 9,166 | 33.723485 | 186 | py |
MSSR | MSSR-main/sr/edsr_arch.py | import torch
from torch import nn as nn
from basicsr.archs.arch_util import ResidualBlockNoBN, Upsample, make_layer
from basicsr.utils.registry import ARCH_REGISTRY
@ARCH_REGISTRY.register()
class EDSR(nn.Module):
"""EDSR network structure.
Paper: Enhanced Deep Residual Networks for Single Image Super-Resol... | 2,223 | 32.19403 | 77 | py |
MSSR | MSSR-main/sr/tof_arch.py | import torch
from torch import nn as nn
from torch.nn import functional as F
from basicsr.utils.registry import ARCH_REGISTRY
from .arch_util import flow_warp
class BasicModule(nn.Module):
"""Basic module of SPyNet.
Note that unlike the architecture in spynet_arch.py, the basic module
here contains batc... | 7,106 | 30.727679 | 79 | py |
MSSR | MSSR-main/sr/psnr_ssim.py | import sys
sys.path.append("../")
import cv2
import numpy as np
import argparse
from basicsr.metrics.metric_util import reorder_image, to_y_channel
from basicsr.utils.registry import METRIC_REGISTRY
import utils
import torch
import os
import torchvision.transforms.functional as TF
def calculate_psnr(img1,
... | 7,451 | 32.12 | 103 | py |
MSSR | MSSR-main/sr/lpips_eval.py | import argparse
import os
import lpips
import utils2
import torch
# import psnr_ssim
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('-d0','--dir0', type=str, default='./imgs/ex_dir0')
parser.add_argument('-d1','--dir1', type=str, default='./imgs/ex_dir1')
pa... | 1,853 | 33.333333 | 112 | py |
MSSR | MSSR-main/sr/duf_arch.py | import numpy as np
import torch
from torch import nn as nn
from torch.nn import functional as F
from basicsr.utils.registry import ARCH_REGISTRY
class DenseBlocksTemporalReduce(nn.Module):
"""A concatenation of 3 dense blocks with reduction in temporal dimension.
Note that the output temporal dimension is 6... | 13,010 | 34.842975 | 79 | py |
MSSR | MSSR-main/sr/dfdnet_arch.py | import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.nn.utils.spectral_norm as SpectralNorm
from basicsr.utils.registry import ARCH_REGISTRY
from .dfdnet_util import (AttentionBlock, Blur, MSDilationBlock, UpResBlock,
adaptive_instance_normalizati... | 7,735 | 40.148936 | 79 | py |
MSSR | MSSR-main/sr/edsr.py | from torch import nn
import torch
import math
import utils
from torchvision import transforms
import os
def default_conv(in_channels, out_channels, kernel_size, bias=True):
return nn.Conv2d(
in_channels, out_channels, kernel_size,
padding=(kernel_size//2), bias=bias)
class EDSR(nn.Module):
def _... | 6,250 | 33.535912 | 130 | py |
MSSR | MSSR-main/sr/rcan_arch.py | import torch
from torch import nn as nn
from basicsr.utils.registry import ARCH_REGISTRY
from .arch_util import Upsample, make_layer
class ChannelAttention(nn.Module):
"""Channel attention used in RCAN.
Args:
num_feat (int): Channel number of intermediate features.
squeeze_factor (int): Chan... | 4,690 | 31.576389 | 77 | py |
MSSR | MSSR-main/sr/dfdnet_util.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.nn.utils.spectral_norm as SpectralNorm
from torch.autograd import Function
class BlurFunctionBackward(Function):
@staticmethod
def forward(ctx, grad_output, kernel, kernel_flip):
ctx.save_for_backward(kernel, kernel_flip)... | 5,647 | 29.203209 | 77 | py |
MSSR | MSSR-main/sr/contsr_model.py | import rrdbnet_arch
import torch
from dataset import *
from utils import *
from torchvision import transforms
from transforms import *
from torch.utils.data import DataLoader
import time
from torch import nn
import lpips
import model
import hanmodel
import rcanmodel
import torchvision.transforms.functional as TF
import... | 14,886 | 44.387195 | 217 | py |
MSSR | MSSR-main/sr/spynet_arch.py | import math
import torch
from torch import nn as nn
from torch.nn import functional as F
from basicsr.utils.registry import ARCH_REGISTRY
from .arch_util import flow_warp
class BasicModule(nn.Module):
"""Basic Module for SpyNet.
"""
def __init__(self):
super(BasicModule, self).__init__()
... | 4,822 | 28.771605 | 77 | py |
MSSR | MSSR-main/sr/transforms.py | from torchvision import transforms
import random
from PIL import Image
class Random90Rot(object):
def __call__(self, img):
angle_list = [0,-90,-180,90]
angle = random.choice(angle_list)
return transforms.functional.rotate(img, angle)
class ResizeTensor(object):
def __init__(self, size, ... | 1,047 | 30.757576 | 67 | py |
MSSR | MSSR-main/sr/hanmodel/rcan3.py | from model import common
import torch
import torch.nn as nn
from torch.autograd import Variable
import pdb
import numpy as np
import math
def make_model(args, parent=False):
return RCAN(args)
## Channel Attention (CA) Layer
class CALayer(nn.Module):
def __init__(self, channel, reduction=16):
super(CAL... | 22,423 | 34.147335 | 126 | py |
MSSR | MSSR-main/sr/hanmodel/rcan.py | from model import common
import torch
import torch.nn as nn
import numpy as np
import pdb
def make_model(args, parent=False):
return RCAN(args)
## Channel Attention (CA) Layer
class CALayer(nn.Module):
def __init__(self, channel, reduction=16):
super(CALayer, self).__init__()
# global average ... | 7,347 | 36.299492 | 116 | py |
MSSR | MSSR-main/sr/hanmodel/rdn2.py | # Residual Dense Network for Image Super-Resolution
# https://arxiv.org/abs/1802.08797
from model import common
import torch
import torch.nn as nn
def make_model(args, parent=False):
return RDN(args)
class RDB_Conv(nn.Module):
def __init__(self, inChannels, growRate, kSize=3):
super(RDB_Conv, self)... | 4,712 | 29.406452 | 90 | py |
MSSR | MSSR-main/sr/hanmodel/rcan1.py | from model import common
import torch.nn as nn
import torch
import torch.nn.init as init
import pdb
def make_model(args, parent=False):
return RCAN(args)
## Channel Attention (CA) Layer
class CALayer(nn.Module):
def __init__(self, channel, reduction=16):
super(CALayer, self).__init__()
# glob... | 17,848 | 39.110112 | 160 | py |
MSSR | MSSR-main/sr/hanmodel/ddbpn.py | # Deep Back-Projection Networks For Super-Resolution
# https://arxiv.org/abs/1803.02735
from model import common
import torch
import torch.nn as nn
def make_model(args, parent=False):
return DDBPN(args)
def projection_conv(in_channels, out_channels, scale, up=True):
kernel_size, stride, padding = {
... | 3,629 | 26.5 | 78 | py |
MSSR | MSSR-main/sr/hanmodel/rdn.py | # Residual Dense Network for Image Super-Resolution
# https://arxiv.org/abs/1802.08797
from model import common
import torch
import torch.nn as nn
def make_model(args, parent=False):
return RDN(args)
class RDB_Conv(nn.Module):
def __init__(self, inChannels, growRate, kSize=3):
super(RDB_Conv, self)... | 3,201 | 29.495238 | 90 | py |
MSSR | MSSR-main/sr/hanmodel/han.py | from hanmodel import common
import torch
import torch.nn as nn
import pdb
def make_model(args, parent=False):
return HAN(args)
## Channel Attention (CA) Layer
class CALayer(nn.Module):
def __init__(self, channel, reduction=16):
super(CALayer, self).__init__()
# global average pooling: feature ... | 10,002 | 32.680135 | 115 | py |
MSSR | MSSR-main/sr/hanmodel/matrixmodel.py | # ------------------------------------------------------------------------------
# Copyright (c) Microsoft
# Licensed under the MIT License.
# Written by Bin Xiao (Bin.Xiao@microsoft.com)
# ------------------------------------------------------------------------------
from __future__ import absolute_import
from __futu... | 75,664 | 36.908317 | 147 | py |
MSSR | MSSR-main/sr/hanmodel/han2.py | ## Down-Sample at last layer
from hanmodel import common
import torch
import torch.nn as nn
import pdb
import neptune
def make_model(args, parent=False):
return HAN(args)
## Channel Attention (CA) Layer
class CALayer(nn.Module):
def __init__(self, channel, reduction=16):
super(CALayer, self).__init__... | 10,158 | 32.863333 | 173 | py |
MSSR | MSSR-main/sr/hanmodel/mdsr.py | from model import common
import torch.nn as nn
url = {
'r16f64': 'https://cv.snu.ac.kr/research/EDSR/models/mdsr_baseline-a00cab12.pt',
'r80f64': 'https://cv.snu.ac.kr/research/EDSR/models/mdsr-4a78bedf.pt'
}
def make_model(args, parent=False):
return MDSR(args)
class MDSR(nn.Module):
def __init__(s... | 1,926 | 27.338235 | 84 | py |
MSSR | MSSR-main/sr/hanmodel/rdn1.py | # Residual Dense Network for Image Super-Resolution
# https://arxiv.org/abs/1802.08797
from model import common
import torch
import torch.nn as nn
def make_model(args, parent=False):
return RDN(args)
class RDB_Conv(nn.Module):
def __init__(self, inChannels, growRate, kSize=(3,3,3)):
super(RDB_Conv,... | 4,564 | 29.231788 | 90 | py |
MSSR | MSSR-main/sr/hanmodel/common.py | import math
import torch
import torch.nn as nn
import torch.nn.functional as F
def default_conv(in_channels, out_channels, kernel_size, bias=True, stride=1):
return nn.Conv2d(
in_channels, out_channels, kernel_size, stride=stride,
padding=(kernel_size//2), bias=bias)
class MeanShift(nn.Conv2d):
... | 2,807 | 30.550562 | 81 | py |
MSSR | MSSR-main/sr/hanmodel/rcan4.py | from model import common
import torch
import torch.nn as nn
import pdb
def make_model(args, parent=False):
return RCAN(args)
## Channel Attention (CA) Layer
class CALayer(nn.Module):
def __init__(self, channel, reduction=16):
super(CALayer, self).__init__()
# global average pooling: feature --... | 8,623 | 34.344262 | 116 | py |
MSSR | MSSR-main/sr/hanmodel/__init__.py | import os
from importlib import import_module
import torch
import torch.nn as nn
import torch.nn.parallel as P
import torch.utils.model_zoo
class Model(nn.Module):
def __init__(self, args, ckp):
super(Model, self).__init__()
print('Making model...')
self.scale = args.scale_factor
... | 6,491 | 32.637306 | 90 | py |
MSSR | MSSR-main/sr/hanmodel/ops.py | '''EoctConv'''
import torch.nn as nn
import torch.nn.functional as F
import torch
import numpy as np
import math
import pdb
BN_MOMENTUM = 0.1
class EoctConv(nn.Module):
def __init__(self, in_channels, num_channels, kernel_size=3, stride=1, padding=1, bias=True, name=None):
super(EoctConv, self).__init__()
... | 12,527 | 39.543689 | 167 | py |
MSSR | MSSR-main/sr/hanmodel/edsr.py | from model import common
import torch.nn as nn
url = {
'r16f64x2': 'https://cv.snu.ac.kr/research/EDSR/models/edsr_baseline_x2-1bc95232.pt',
'r16f64x3': 'https://cv.snu.ac.kr/research/EDSR/models/edsr_baseline_x3-abf2a44e.pt',
'r16f64x4': 'https://cv.snu.ac.kr/research/EDSR/models/edsr_baseline_x4-6b446fa... | 3,031 | 34.255814 | 95 | py |
MSSR | MSSR-main/sr/hanmodel/vdsr.py | from model import common
import torch.nn as nn
import torch.nn.init as init
url = {
'r20f64': ''
}
def make_model(args, parent=False):
return VDSR(args)
class VDSR(nn.Module):
def __init__(self, args, conv=common.default_conv):
super(VDSR, self).__init__()
n_resblocks = args.n_resblocks... | 1,275 | 26.148936 | 73 | py |
MSSR | MSSR-main/sr/hanmodel/dcn/deform_conv.py | import math
import logging
import torch
import torch.nn as nn
from torch.autograd import Function
from torch.autograd.function import once_differentiable
from torch.nn.modules.utils import _pair
from . import deform_conv_cuda
logger = logging.getLogger('base')
class DeformConvFunction(Function):
@staticmethod
... | 12,234 | 40.900685 | 99 | py |
MSSR | MSSR-main/sr/hanmodel/dcn/setup.py | from setuptools import setup
from torch.utils.cpp_extension import BuildExtension, CUDAExtension
def make_cuda_ext(name, sources):
return CUDAExtension(
name='{}'.format(name), sources=[p for p in sources], extra_compile_args={
'cxx': [],
'nvcc': [
'-D__CUDA_NO_HAL... | 711 | 29.956522 | 93 | py |
MSSR | MSSR-main/sr/rcanmodel/rcan.py | from rcanmodel import common
import torch.nn as nn
def make_model(args, parent=False):
return RCAN(args)
## Channel Attention (CA) Layer
class CALayer(nn.Module):
def __init__(self, channel, reduction=16):
super(CALayer, self).__init__()
# global average pooling: feature --> point
sel... | 4,951 | 33.873239 | 108 | py |
MSSR | MSSR-main/sr/rcanmodel/common.py | import math
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
def default_conv(in_channels, out_channels, kernel_size, bias=True):
return nn.Conv2d(
in_channels, out_channels, kernel_size,
padding=(kernel_size//2), bias=bias)
class MeanShift(n... | 2,512 | 32.065789 | 76 | py |
MSSR | MSSR-main/sr/rcanmodel/__init__.py | import os
from importlib import import_module
import torch
import torch.nn as nn
from torch.autograd import Variable
class Model(nn.Module):
def __init__(self, args):
super(Model, self).__init__()
print('Making model...')
self.scale = args.scale_factor
self.idx_scale = 0
... | 6,323 | 31.9375 | 90 | py |
MSSR | MSSR-main/basicsr/metrics/fid.py | import numpy as np
import torch
import torch.nn as nn
from scipy import linalg
from tqdm import tqdm
from basicsr.archs.inception import InceptionV3
def load_patched_inception_v3(device='cuda', resize_input=True, normalize_input=False):
# we may not resize the input, but in [rosinality/stylegan2-pytorch] it
... | 3,258 | 33.670213 | 98 | py |
MSSR | MSSR-main/basicsr/utils/face_util.py | import cv2
import numpy as np
import os
import torch
from skimage import transform as trans
from basicsr.utils import imwrite
try:
import dlib
except ImportError:
print('Please install dlib before testing face restoration.'
'Reference: https://github.com/davisking/dlib')
class FaceRestorationHelpe... | 9,588 | 42.986239 | 79 | py |
MSSR | MSSR-main/basicsr/utils/misc.py | import numpy as np
import os
import random
import time
import torch
from os import path as osp
from .dist_util import master_only
from .logger import get_root_logger
def set_random_seed(seed):
"""Set random seeds."""
random.seed(seed)
np.random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual... | 4,480 | 31.007143 | 79 | py |
MSSR | MSSR-main/basicsr/utils/logger.py | import datetime
import logging
import time
from .dist_util import get_dist_info, master_only
class MessageLogger():
"""Message logger for printing.
Args:
opt (dict): Config. It contains the following keys:
name (str): Exp name.
logger (dict): Contains 'print_freq' (str) for l... | 6,114 | 33.353933 | 79 | py |
MSSR | MSSR-main/basicsr/utils/img_util.py | import cv2
import math
import numpy as np
import os
import torch
from torchvision.utils import make_grid
def img2tensor(imgs, bgr2rgb=True, float32=True):
"""Numpy array to tensor.
Args:
imgs (list[ndarray] | ndarray): Input images.
bgr2rgb (bool): Whether to change bgr to rgb.
float3... | 5,555 | 32.46988 | 79 | py |
MSSR | MSSR-main/basicsr/utils/matlab_functions.py | import math
import numpy as np
import torch
def cubic(x):
"""cubic function used for calculate_weights_indices."""
absx = torch.abs(x)
absx2 = absx**2
absx3 = absx**3
return (1.5 * absx3 - 2.5 * absx2 + 1) * (
(absx <= 1).type_as(absx)) + (-0.5 * absx3 + 2.5 * absx2 - 4 * absx +
... | 13,747 | 36.977901 | 79 | py |
MSSR | MSSR-main/basicsr/utils/dist_util.py | # Modified from https://github.com/open-mmlab/mmcv/blob/master/mmcv/runner/dist_utils.py # noqa: E501
import functools
import os
import subprocess
import torch
import torch.distributed as dist
import torch.multiprocessing as mp
def init_dist(launcher, backend='nccl', **kwargs):
if mp.get_start_method(allow_none=... | 2,617 | 30.166667 | 102 | py |
bats | bats-main/datasets/get_mnist.py | from download_file import download
if __name__ == "__main__":
print("Downloading MNIST...")
url = 'https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz'
filename = 'mnist.npz'
download(url, filename)
print("Done.") | 254 | 24.5 | 81 | py |
bats | bats-main/experiments/mnist/Dataset.py | from pathlib import Path
from typing import Tuple
from elasticdeform import deform_random_grid
import warnings
import matplotlib.pyplot as plt
from scipy.ndimage import gaussian_filter, map_coordinates
warnings.filterwarnings("ignore")
from tensorflow import keras
import numpy as np
TIME_WINDOW = 100e-3
MAX_VALUE = ... | 4,882 | 41.46087 | 120 | py |
DeepBugs | DeepBugs-master/python/EmbeddingModelValidator.py | '''
Created on Jul 17, 2017
@author: Michael Pradel
'''
import sys
from os import getcwd
from os.path import join
import json
from keras.models import load_model
import numpy as np
from keras import backend as K
import random
from numpy import float32
nb_tokens_in_context = 20
kept_main_tokens = 10000
kept_context_t... | 2,667 | 31.938272 | 153 | py |
DeepBugs | DeepBugs-master/python/BugFind.py | '''
Created on Jun 23, 2017
@author: Michael Pradel, Sabine Zach
'''
import sys
import json
from os.path import join
from os import getcwd
from collections import namedtuple
from tensorflow.python.keras.models import load_model
import time
import numpy as np
import Util
import LearningDataSwappedArgs
import LearningD... | 5,781 | 32.421965 | 174 | py |
DeepBugs | DeepBugs-master/python/BugLearn.py | '''
Created on Jun 23, 2017
@author: Michael Pradel, Sabine Zach
'''
import sys
import json
from os.path import join
from os import getcwd
from collections import namedtuple
import math
from tensorflow.python.keras.models import Sequential
from tensorflow.python.keras.layers.core import Dense, Dropout
import time
i... | 5,274 | 33.253247 | 174 | py |
DeepBugs | DeepBugs-master/python/EmbeddingLearner.py | '''
Created on Jul 3, 2017
@author: Michael Pradel
'''
import json
import math
from os import getcwd
from os.path import join
import sys
import time
from keras.layers.core import Dense
from keras.models import Model
from keras.models import Sequential
import numpy as np
import random
nb_tokens_in_context = 20
kept... | 5,557 | 36.053333 | 161 | py |
DeepBugs | DeepBugs-master/python/ASTEmbeddingLearner.py | '''
Created on Jul 20, 2017
@author: Michael Pradel
'''
import json
import math
from os import getcwd
from os.path import join
import sys
import time
from keras.layers.core import Dense
from keras.models import Model
from keras.models import Sequential
from keras import backend as K
import numpy as np
import random... | 6,757 | 40.460123 | 165 | py |
DeepBugs | DeepBugs-master/python/ASTEmbeddingLearnerPerLocation.py | '''
Created on Jul 20, 2017
@author: Michael Pradel
'''
import json
import math
from os import getcwd
from os.path import join
import sys
import time
from keras.layers.core import Dense
from keras.models import Model
from keras.models import Sequential
import numpy as np
import random
from collections import namedt... | 10,164 | 43.977876 | 165 | py |
DeepBugs | DeepBugs-master/python/BugLearnAndValidate.py | '''
Created on Jun 23, 2017
@author: Michael Pradel, Sabine Zach
'''
import sys
import json
from os.path import join
from os import getcwd
from collections import Counter, namedtuple
import math
import argparse
from tensorflow.python.keras.models import Sequential
from tensorflow.python.keras.layers.core import Dens... | 9,564 | 38.688797 | 226 | py |
DeepBugs | DeepBugs-master/python/AccuracyMetricTest.py | '''
Created on Jul 17, 2017
@author: Michael Pradel
'''
from keras import backend as K
import numpy as np
nb_tokens_in_context = 2
kept_context_tokens = 5
weight_of_ones = kept_context_tokens
def weighted_loss(y_true, y_pred):
weights = (y_true * (weight_of_ones - 1) + 1)
y_pred = K.variable(y_pred) ## req... | 1,272 | 30.825 | 121 | py |
CoMP | CoMP-main/run.py | import argparse
import logging
import os
from pathlib import Path
import pytorch_lightning as pl
import s3fs
import torch
import yaml
from comp.data.loaders import prepare_training_data
from comp import metric_handlers
from comp.nn.utils import Encoder, GaussianDecoder, calc_input_dims
from comp.nn.config import Mode... | 9,960 | 32.203333 | 132 | py |
CoMP | CoMP-main/comp/metric_handlers.py | import logging
import os
from pathlib import Path
from typing import Callable, List, Optional, Tuple, Union
import numpy as np
import pandas as pd
import pytorch_lightning as pl
import torch
from umap import UMAP
LOG = logging.getLogger(__name__)
LOG.setLevel(logging.INFO)
UMAP_SEED = 42
def get_umap_params(dataset... | 4,105 | 31.078125 | 96 | py |
CoMP | CoMP-main/comp/nn/loss.py | from typing import Callable
import torch
import torch.nn as nn
class RBF(nn.Module):
def __init__(self, length_scale: float):
super().__init__()
self._length_scale = length_scale
def forward(self, x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
dists = torch.cdist(x / self._length... | 2,522 | 33.094595 | 100 | py |
CoMP | CoMP-main/comp/nn/utils.py | import torch
import torch.distributions as dist
import torch.nn as nn
def calc_input_dims(tensor_dataset, model_config):
gene_expression_dim = tensor_dataset.tensors[0].shape[1]
if model_config.model in ["cvae", "comp", "trvae"]:
assert len(tensor_dataset.tensors) in [2, 3]
label_dims = tensor... | 4,143 | 32.967213 | 97 | py |
CoMP | CoMP-main/comp/pl/trvae.py | import logging
import pytorch_lightning as pl
import torch
import torch.distributions as tdist
from comp.nn.loss import GroupwiseMMD, MultiScaleRBF
LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.INFO)
# From TrVAE
RBF_SCALES = [
[
i ** (-1)
for i in [
1e-6,
... | 3,747 | 26.762963 | 111 | py |
CoMP | CoMP-main/comp/pl/vae.py | import logging
import pytorch_lightning as pl
import torch
import torch.distributions as tdist
LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.INFO)
class VAE(pl.LightningModule):
"""VAE class with flexible encoder and decoder"""
def __init__(
self, encoder, decoder, z_dim, learning_rat... | 2,608 | 32.025316 | 102 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.