repo stringlengths 7 90 | file_url stringlengths 81 315 | file_path stringlengths 4 228 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 14:38:15 2026-01-05 02:33:18 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/basicsr/metrics/psnr_ssim.py | basicsr/metrics/psnr_ssim.py | import cv2
import numpy as np
from basicsr.metrics.metric_util import reorder_image, to_y_channel
from basicsr.utils.registry import METRIC_REGISTRY
@METRIC_REGISTRY.register()
def calculate_psnr(img, img2, crop_border, input_order='HWC', test_y_channel=False, **kwargs):
"""Calculate PSNR (Peak Signal-to-Noise R... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/basicsr/models/base_model.py | basicsr/models/base_model.py | import os
import time
import torch
from collections import OrderedDict
from copy import deepcopy
from torch.nn.parallel import DataParallel, DistributedDataParallel
from basicsr.models import lr_scheduler as lr_scheduler
from basicsr.utils import get_root_logger
from basicsr.utils.dist_util import master_only
class ... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/basicsr/models/cat_model.py | basicsr/models/cat_model.py | import torch
from torch.nn import functional as F
from basicsr.utils.registry import MODEL_REGISTRY
from basicsr.models.sr_model import SRModel
@MODEL_REGISTRY.register()
class CATModel(SRModel):
def test(self):
self.use_chop = self.opt['val']['use_chop'] if 'use_chop' in self.opt['val'] else False
... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/basicsr/models/sr_model.py | basicsr/models/sr_model.py | import torch
from collections import OrderedDict
from os import path as osp
from tqdm import tqdm
from basicsr.archs import build_network
from basicsr.losses import build_loss
from basicsr.metrics import calculate_metric
from basicsr.utils import get_root_logger, imwrite, tensor2img
from basicsr.utils.registry import ... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/basicsr/models/cat_se_model.py | basicsr/models/cat_se_model.py | import torch
from torch.nn import functional as F
from basicsr.utils.registry import MODEL_REGISTRY
from basicsr.models.sr_model import SRModel
@MODEL_REGISTRY.register()
class CATSEModel(SRModel):
def test(self):
# pad to multiplication of window_size
if self.opt['val']['selfensemble_testing']:... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/basicsr/models/__init__.py | basicsr/models/__init__.py | import importlib
from copy import deepcopy
from os import path as osp
from basicsr.utils import get_root_logger, scandir
from basicsr.utils.registry import MODEL_REGISTRY
__all__ = ['build_model']
# automatically scan and import model modules for registry
# scan all the files under the 'models' folder and collect fi... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/basicsr/models/lr_scheduler.py | basicsr/models/lr_scheduler.py | import math
from collections import Counter
from torch.optim.lr_scheduler import _LRScheduler
class MultiStepRestartLR(_LRScheduler):
""" MultiStep with restarts learning rate scheme.
Args:
optimizer (torch.nn.optimizer): Torch optimizer.
milestones (list): Iterations that will decrease learn... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/basicsr/archs/vgg_arch.py | basicsr/archs/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... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/basicsr/archs/__init__.py | basicsr/archs/__init__.py | import importlib
from copy import deepcopy
from os import path as osp
from basicsr.utils import get_root_logger, scandir
from basicsr.utils.registry import ARCH_REGISTRY
__all__ = ['build_network']
# automatically scan and import arch modules for registry
# scan all the files under the 'archs' folder and collect fil... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/basicsr/archs/arch_util.py | basicsr/archs/arch_util.py | import collections.abc
import math
import torch
import torchvision
import warnings
from distutils.version import LooseVersion
from itertools import repeat
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.o... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/basicsr/archs/cat_arch.py | basicsr/archs/cat_arch.py | import torch
import torch.nn as nn
import torch.utils.checkpoint as checkpoint
from timm.models.layers import DropPath, trunc_normal_
from einops.layers.torch import Rearrange
from einops import rearrange
import math
import numpy as np
from basicsr.utils.registry import ARCH_REGISTRY
def img2windows(img, H_sp, W_s... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | true |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/basicsr/archs/cat_unet_arch.py | basicsr/archs/cat_unet_arch.py | import torch
import torch.nn as nn
from timm.models.layers import DropPath
from einops import rearrange
from basicsr.utils.registry import ARCH_REGISTRY
def img2windows(img, H_sp, W_sp):
"""
Input: Image (B, C, H, W)
Output: Window Partition (B', N, C)
"""
B, C, H, W = img.shape
img_reshape =... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | true |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/basicsr/utils/matlab_functions.py | 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 + 2) * (((ab... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/basicsr/utils/img_util.py | 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... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/basicsr/utils/registry.py | basicsr/utils/registry.py | # Modified from: https://github.com/facebookresearch/fvcore/blob/master/fvcore/common/registry.py # noqa: E501
class Registry():
"""
The registry that provides name -> object mapping, to support third-party
users' custom modules.
To create a registry (e.g. a backbone registry):
.. code-block:: ... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/basicsr/utils/logger.py | basicsr/utils/logger.py | import datetime
import logging
import time
from .dist_util import get_dist_info, master_only
initialized_logger = {}
class AvgTimer():
def __init__(self, window=200):
self.window = window # average window
self.current_time = 0
self.total_time = 0
self.count = 0
self.avg... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/basicsr/utils/misc.py | 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
def set_random_seed(seed):
"""Set random seeds."""
random.seed(seed)
np.random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed(seed)
torch.cuda.manual_se... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/basicsr/utils/file_client.py | basicsr/utils/file_client.py | # Modified from https://github.com/open-mmlab/mmcv/blob/master/mmcv/fileio/file_client.py # noqa: E501
from abc import ABCMeta, abstractmethod
class BaseStorageBackend(metaclass=ABCMeta):
"""Abstract class of storage backends.
All backends need to implement two apis: ``get()`` and ``get_text()``.
``get(... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/basicsr/utils/__init__.py | basicsr/utils/__init__.py | from .file_client import FileClient
from .img_util import crop_border, imfrombytes, img2tensor, imwrite, tensor2img
from .logger import AvgTimer, MessageLogger, get_env_info, get_root_logger, init_tb_logger, init_wandb_logger
from .misc import check_resume, get_time_str, make_exp_dirs, mkdir_and_rename, scandir, set_ra... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/basicsr/utils/dist_util.py | 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=... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/basicsr/utils/options.py | basicsr/utils/options.py | import argparse
import random
import torch
import yaml
from collections import OrderedDict
from os import path as osp
from basicsr.utils import set_random_seed
from basicsr.utils.dist_util import get_dist_info, init_dist, master_only
def ordered_yaml():
"""Support OrderedDict for yaml.
Returns:
yaml... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/basicsr/data/prefetch_dataloader.py | basicsr/data/prefetch_dataloader.py | import queue as Queue
import threading
import torch
from torch.utils.data import DataLoader
class PrefetchGenerator(threading.Thread):
"""A general prefetch generator.
Ref:
https://stackoverflow.com/questions/7323664/python-generator-pre-fetch
Args:
generator: Python generator.
num_p... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/basicsr/data/data_util.py | basicsr/data/data_util.py | import cv2
import numpy as np
import torch
from os import path as osp
from torch.nn import functional as F
from basicsr.utils import img2tensor, scandir
def generate_frame_indices(crt_idx, max_frame_num, num_frames, padding='reflection'):
"""Generate an index list for reading `num_frames` frames from a sequence
... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/basicsr/data/data_sampler.py | basicsr/data/data_sampler.py | import math
import torch
from torch.utils.data.sampler import Sampler
class EnlargedSampler(Sampler):
"""Sampler that restricts data loading to a subset of the dataset.
Modified from torch.utils.data.distributed.DistributedSampler
Support enlarging the dataset for iteration-based training, for saving
... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/basicsr/data/__init__.py | basicsr/data/__init__.py | import importlib
import numpy as np
import random
import torch
import torch.utils.data
from copy import deepcopy
from functools import partial
from os import path as osp
from basicsr.data.prefetch_dataloader import PrefetchDataLoader
from basicsr.utils import get_root_logger, scandir
from basicsr.utils.dist_util impor... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/basicsr/data/paired_image_dataset.py | basicsr/data/paired_image_dataset.py | from torch.utils import data as data
from torchvision.transforms.functional import normalize
from basicsr.data.data_util import paired_paths_from_folder, paired_paths_from_lmdb, paired_paths_from_meta_info_file
from basicsr.data.transforms import augment, paired_random_crop
from basicsr.utils import FileClient, imfrom... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/basicsr/data/transforms.py | basicsr/data/transforms.py | import cv2
import random
import torch
def mod_crop(img, scale):
"""Mod crop images, used during testing.
Args:
img (ndarray): Input image.
scale (int): Scale factor.
Returns:
ndarray: Result image.
"""
img = img.copy()
if img.ndim in (2, 3):
h, w = img.shape[0... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/test_real_denoising_dnd.py | restormer/test_real_denoising_dnd.py | # The implementation builds on Restormer code https://github.com/swz30/Restormer
import numpy as np
import os
import argparse
from tqdm import tqdm
import torch
import torch.nn as nn
import torch.nn.functional as F
from basicsr.archs.cat_unet_arch import CAT_Unet
from skimage import img_as_ubyte
import cv2
import h5p... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/setup.py | restormer/setup.py | #!/usr/bin/env python
from setuptools import find_packages, setup
import os
import subprocess
import sys
import time
import torch
from torch.utils.cpp_extension import (BuildExtension, CppExtension,
CUDAExtension)
version_file = 'basicsr/version.py'
def readme():
return '... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/test_real_denoising_sidd.py | restormer/test_real_denoising_sidd.py | # The implementation builds on Restormer code https://github.com/swz30/Restormer
import numpy as np
import os
import argparse
from tqdm import tqdm
import torch
import torch.nn as nn
from basicsr.archs.cat_unet_arch import CAT_Unet
import scipy.io as sio
import cv2
from skimage import img_as_ubyte
parser = argparse.... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/generate_patches_sidd.py | restormer/generate_patches_sidd.py | import cv2
import torch
import numpy as np
from glob import glob
from natsort import natsorted
import os
from tqdm import tqdm
from pdb import set_trace as stx
src = 'datasets/SIDD/raw'
tar = 'datasets/SIDD/train'
lr_tar = os.path.join(tar, 'input_crops')
hr_tar = os.path.join(tar, 'target_crops')
os.makedirs(lr_ta... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/train.py | restormer/basicsr/train.py | import argparse
import datetime
import logging
import math
import random
import time
import torch
from os import path as osp
from basicsr.data import create_dataloader, create_dataset
from basicsr.data.data_sampler import EnlargedSampler
from basicsr.data.prefetch_dataloader import CPUPrefetcher, CUDAPrefetcher
from b... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/version.py | restormer/basicsr/version.py | # GENERATED VERSION FILE
# TIME: Sun Sep 25 08:32:49 2022
__version__ = '1.2.0+733ceb2'
short_version = '1.2.0'
version_info = (1, 2, 0)
| python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/test.py | restormer/basicsr/test.py | import logging
import torch
from os import path as osp
from basicsr.data import create_dataloader, create_dataset
from basicsr.models import create_model
from basicsr.train import parse_options
from basicsr.utils import (get_env_info, get_root_logger, get_time_str,
make_exp_dirs)
from basics... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/metrics/metric_util.py | restormer/basicsr/metrics/metric_util.py | import numpy as np
from basicsr.utils.matlab_functions import bgr2ycbcr
def reorder_image(img, input_order='HWC'):
"""Reorder images to 'HWC' order.
If the input_order is (h, w), return (h, w, 1);
If the input_order is (c, h, w), return (h, w, c);
If the input_order is (h, w, c), return as it is.
... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/metrics/fid.py | restormer/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.models.archs.inception import InceptionV3
def load_patched_inception_v3(device='cuda',
resize_input=True,
normalize_input=False):
# we may ... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/metrics/niqe.py | restormer/basicsr/metrics/niqe.py | import cv2
import math
import numpy as np
from scipy.ndimage.filters import convolve
from scipy.special import gamma
from basicsr.metrics.metric_util import reorder_image, to_y_channel
def estimate_aggd_param(block):
"""Estimate AGGD (Asymmetric Generalized Gaussian Distribution) paramters.
Args:
bl... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/metrics/__init__.py | restormer/basicsr/metrics/__init__.py | from .niqe import calculate_niqe
from .psnr_ssim import calculate_psnr, calculate_ssim
__all__ = ['calculate_psnr', 'calculate_ssim', 'calculate_niqe']
| python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/metrics/psnr_ssim.py | restormer/basicsr/metrics/psnr_ssim.py | import cv2
import numpy as np
from basicsr.metrics.metric_util import reorder_image, to_y_channel
import skimage.metrics
import torch
def calculate_psnr(img1,
img2,
crop_border,
input_order='HWC',
test_y_channel=False):
"""Calculate PSNR... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/models/base_model.py | restormer/basicsr/models/base_model.py | import logging
import os
import torch
from collections import OrderedDict
from copy import deepcopy
from torch.nn.parallel import DataParallel, DistributedDataParallel
from basicsr.models import lr_scheduler as lr_scheduler
from basicsr.utils.dist_util import master_only
logger = logging.getLogger('basicsr')
class ... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/models/cat_model.py | restormer/basicsr/models/cat_model.py | import importlib
import torch
from collections import OrderedDict
from copy import deepcopy
from os import path as osp
from tqdm import tqdm
from basicsr.models.archs import define_network
from basicsr.models.base_model import BaseModel
from basicsr.utils import get_root_logger, imwrite, tensor2img
loss_module = impo... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/models/__init__.py | restormer/basicsr/models/__init__.py | import importlib
from os import path as osp
from basicsr.utils import get_root_logger, scandir
# automatically scan and import model modules
# scan all the files under the 'models' folder and collect files ending with
# '_model.py'
model_folder = osp.dirname(osp.abspath(__file__))
model_filenames = [
osp.splitext... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/models/lr_scheduler.py | restormer/basicsr/models/lr_scheduler.py | import math
from collections import Counter
from torch.optim.lr_scheduler import _LRScheduler
import torch
class MultiStepRestartLR(_LRScheduler):
""" MultiStep with restarts learning rate scheme.
Args:
optimizer (torch.nn.optimizer): Torch optimizer.
milestones (list): Iterations that will d... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/models/losses/loss_util.py | restormer/basicsr/models/losses/loss_util.py | import functools
from torch.nn import functional as F
def reduce_loss(loss, reduction):
"""Reduce loss as specified.
Args:
loss (Tensor): Elementwise loss tensor.
reduction (str): Options are 'none', 'mean' and 'sum'.
Returns:
Tensor: Reduced loss tensor.
"""
reduction_en... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/models/losses/losses.py | restormer/basicsr/models/losses/losses.py | import torch
from torch import nn as nn
from torch.nn import functional as F
import numpy as np
from basicsr.models.losses.loss_util import weighted_loss
_reduction_modes = ['none', 'mean', 'sum']
@weighted_loss
def l1_loss(pred, target):
return F.l1_loss(pred, target, reduction='none')
@weighted_loss
def mse... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/models/losses/__init__.py | restormer/basicsr/models/losses/__init__.py | from .losses import (L1Loss, MSELoss, PSNRLoss, CharbonnierLoss)
__all__ = [
'L1Loss', 'MSELoss', 'PSNRLoss', 'CharbonnierLoss',
]
| python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/models/archs/__init__.py | restormer/basicsr/models/archs/__init__.py | import importlib
from os import path as osp
from basicsr.utils import scandir
# automatically scan and import arch modules
# scan all the files under the 'archs' folder and collect files ending with
# '_arch.py'
arch_folder = osp.dirname(osp.abspath(__file__))
arch_filenames = [
osp.splitext(osp.basename(v))[0] f... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/models/archs/arch_util.py | restormer/basicsr/models/archs/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.utils import get_root_logger
# try:
# from basicsr.models.ops.dcn import (ModulatedDeformConvPack,
# ... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/models/archs/cat_unet_arch.py | restormer/basicsr/models/archs/cat_unet_arch.py | import torch
import torch.nn as nn
from timm.models.layers import DropPath
from einops import rearrange
def img2windows(img, H_sp, W_sp):
"""
Input: Image (B, C, H, W)
Output: Window Partition (B', N, C)
"""
B, C, H, W = img.shape
img_reshape = img.view(B, C, H // H_sp, H_sp, W // W_sp, W_sp)
... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | true |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/utils/matlab_functions.py | restormer/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 +
... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/utils/img_util.py | restormer/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... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/utils/face_util.py | restormer/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... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/utils/logger.py | restormer/basicsr/utils/logger.py | import datetime
import logging
import time
from .dist_util import get_dist_info, master_only
initialized_logger = {}
class MessageLogger():
"""Message logger for printing.
Args:
opt (dict): Config. It contains the following keys:
name (str): Exp name.
logger (dict): Contains... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/utils/download_util.py | restormer/basicsr/utils/download_util.py | import math
import requests
from tqdm import tqdm
from .misc import sizeof_fmt
def download_file_from_google_drive(file_id, save_path):
"""Download files from google drive.
Ref:
https://stackoverflow.com/questions/25010369/wget-curl-large-file-from-google-drive # noqa E501
Args:
file_id (s... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/utils/lmdb_util.py | restormer/basicsr/utils/lmdb_util.py | import cv2
import lmdb
import sys
from multiprocessing import Pool
from os import path as osp
from tqdm import tqdm
def make_lmdb_from_imgs(data_path,
lmdb_path,
img_path_list,
keys,
batch=5000,
com... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/utils/misc.py | restormer/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... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/utils/file_client.py | restormer/basicsr/utils/file_client.py | # Modified from https://github.com/open-mmlab/mmcv/blob/master/mmcv/fileio/file_client.py # noqa: E501
from abc import ABCMeta, abstractmethod
class BaseStorageBackend(metaclass=ABCMeta):
"""Abstract class of storage backends.
All backends need to implement two apis: ``get()`` and ``get_text()``.
``get(... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/utils/bundle_submissions.py | restormer/basicsr/utils/bundle_submissions.py | # Author: Tobias Plötz, TU Darmstadt (tobias.ploetz@visinf.tu-darmstadt.de)
# This file is part of the implementation as described in the CVPR 2017 paper:
# Tobias Plötz and Stefan Roth, Benchmarking Denoising Algorithms with Real Photographs.
# Please see the file LICENSE.txt for the license governing this code.
... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/utils/__init__.py | restormer/basicsr/utils/__init__.py | from .file_client import FileClient
from .img_util import crop_border, imfrombytes, img2tensor, imwrite, tensor2img, padding, padding_DP, imfrombytesDP
from .logger import (MessageLogger, get_env_info, get_root_logger,
init_tb_logger, init_wandb_logger)
from .misc import (check_resume, get_time_str... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/utils/flow_util.py | restormer/basicsr/utils/flow_util.py | # Modified from https://github.com/open-mmlab/mmcv/blob/master/mmcv/video/optflow.py # noqa: E501
import cv2
import numpy as np
import os
def flowread(flow_path, quantize=False, concat_axis=0, *args, **kwargs):
"""Read an optical flow map.
Args:
flow_path (ndarray or str): Flow path.
quantiz... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/utils/create_lmdb.py | restormer/basicsr/utils/create_lmdb.py | import argparse
from os import path as osp
from basicsr.utils import scandir
from basicsr.utils.lmdb_util import make_lmdb_from_imgs
def prepare_keys(folder_path, suffix='png'):
"""Prepare image path list and keys for DIV2K dataset.
Args:
folder_path (str): Folder path.
Returns:
list[str... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/utils/dist_util.py | restormer/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=... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/utils/options.py | restormer/basicsr/utils/options.py | import yaml
from collections import OrderedDict
from os import path as osp
def ordered_yaml():
"""Support OrderedDict for yaml.
Returns:
yaml Loader and Dumper.
"""
try:
from yaml import CDumper as Dumper
from yaml import CLoader as Loader
except ImportError:
from ... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/data/prefetch_dataloader.py | restormer/basicsr/data/prefetch_dataloader.py | import queue as Queue
import threading
import torch
from torch.utils.data import DataLoader
class PrefetchGenerator(threading.Thread):
"""A general prefetch generator.
Ref:
https://stackoverflow.com/questions/7323664/python-generator-pre-fetch
Args:
generator: Python generator.
num_p... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/data/data_util.py | restormer/basicsr/data/data_util.py | import cv2
cv2.setNumThreads(1)
import numpy as np
import torch
from os import path as osp
from torch.nn import functional as F
from basicsr.data.transforms import mod_crop
from basicsr.utils import img2tensor, scandir
def read_img_seq(path, require_mod_crop=False, scale=1):
"""Read a sequence of images from a g... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/data/vimeo90k_dataset.py | restormer/basicsr/data/vimeo90k_dataset.py | import random
import torch
from pathlib import Path
from torch.utils import data as data
from basicsr.data.transforms import augment, paired_random_crop
from basicsr.utils import FileClient, get_root_logger, imfrombytes, img2tensor
class Vimeo90KDataset(data.Dataset):
"""Vimeo90K dataset for training.
The k... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/data/video_test_dataset.py | restormer/basicsr/data/video_test_dataset.py | import glob
import torch
from os import path as osp
from torch.utils import data as data
from basicsr.data.data_util import (duf_downsample, generate_frame_indices,
read_img_seq)
from basicsr.utils import get_root_logger, scandir
class VideoTestDataset(data.Dataset):
"""Video ... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/data/data_sampler.py | restormer/basicsr/data/data_sampler.py | import math
import torch
from torch.utils.data.sampler import Sampler
class EnlargedSampler(Sampler):
"""Sampler that restricts data loading to a subset of the dataset.
Modified from torch.utils.data.distributed.DistributedSampler
Support enlarging the dataset for iteration-based training, for saving
... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/data/single_image_dataset.py | restormer/basicsr/data/single_image_dataset.py | from os import path as osp
from torch.utils import data as data
from torchvision.transforms.functional import normalize
from basicsr.data.data_util import paths_from_lmdb
from basicsr.utils import FileClient, imfrombytes, img2tensor, scandir
class SingleImageDataset(data.Dataset):
"""Read only lq images in the t... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/data/__init__.py | restormer/basicsr/data/__init__.py | import importlib
import numpy as np
import random
import torch
import torch.utils.data
from functools import partial
from os import path as osp
from basicsr.data.prefetch_dataloader import PrefetchDataLoader
from basicsr.utils import get_root_logger, scandir
from basicsr.utils.dist_util import get_dist_info
__all__ =... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/data/paired_image_dataset.py | restormer/basicsr/data/paired_image_dataset.py | from torch.utils import data as data
from torchvision.transforms.functional import normalize
from basicsr.data.data_util import (paired_paths_from_folder,
paired_DP_paths_from_folder,
paired_paths_from_lmdb,
pai... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/data/transforms.py | restormer/basicsr/data/transforms.py | import cv2
import random
import numpy as np
def mod_crop(img, scale):
"""Mod crop images, used during testing.
Args:
img (ndarray): Input image.
scale (int): Scale factor.
Returns:
ndarray: Result image.
"""
img = img.copy()
if img.ndim in (2, 3):
h, w = img.sh... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/data/ffhq_dataset.py | restormer/basicsr/data/ffhq_dataset.py | from os import path as osp
from torch.utils import data as data
from torchvision.transforms.functional import normalize
from basicsr.data.transforms import augment
from basicsr.utils import FileClient, imfrombytes, img2tensor
class FFHQDataset(data.Dataset):
"""FFHQ dataset for StyleGAN.
Args:
opt (... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
zhengchen1999/CAT | https://github.com/zhengchen1999/CAT/blob/89cbfc88a337344d6dee76278c96e033ec38d5c6/restormer/basicsr/data/reds_dataset.py | restormer/basicsr/data/reds_dataset.py | import numpy as np
import random
import torch
from pathlib import Path
from torch.utils import data as data
from basicsr.data.transforms import augment, paired_random_crop
from basicsr.utils import FileClient, get_root_logger, imfrombytes, img2tensor
from basicsr.utils.flow_util import dequantize_flow
class REDSData... | python | Apache-2.0 | 89cbfc88a337344d6dee76278c96e033ec38d5c6 | 2026-01-05T07:10:50.865533Z | false |
ourresearch/openalex-guts | https://github.com/ourresearch/openalex-guts/blob/59706e52ceb84b12427334b046c47b7a6d95c862/bulk_actions.py | bulk_actions.py | import datetime
from app import logger
from util import entity_md5
def create_bulk_actions(entity, index_name):
bulk_actions = []
my_dict = entity.to_dict()
my_dict['updated'] = my_dict.get('updated_date')
my_dict['@timestamp'] = datetime.datetime.utcnow().isoformat()
new_entity_hash = entity_md... | python | MIT | 59706e52ceb84b12427334b046c47b7a6d95c862 | 2026-01-05T07:10:54.483482Z | false |
ourresearch/openalex-guts | https://github.com/ourresearch/openalex-guts/blob/59706e52ceb84b12427334b046c47b7a6d95c862/util.py | util.py | import datetime
import time
import unicodedata
import shortuuid
import sqlalchemy
import logging
import math
import bisect
import urllib.parse
import re
import os
import collections
import requests
import hashlib
import heroku3
import json
import copy
from nameparser import HumanName
import string
from tenacity impor... | python | MIT | 59706e52ceb84b12427334b046c47b7a6d95c862 | 2026-01-05T07:10:54.483482Z | false |
ourresearch/openalex-guts | https://github.com/ourresearch/openalex-guts/blob/59706e52ceb84b12427334b046c47b7a6d95c862/upsert_mag_records.py | upsert_mag_records.py | from datetime import datetime
from sqlalchemy import text
from scripts.add_things_queue import enqueue_jobs
import redis
import shortuuid
from app import db, REDIS_QUEUE_URL
UPSERT_QUEUE = 'queue:mag_authors_upsert'
REDIS = redis.from_url(REDIS_QUEUE_URL)
BATCH_SIZE = 100
def make_recordthresher_id():
return s... | python | MIT | 59706e52ceb84b12427334b046c47b7a6d95c862 | 2026-01-05T07:10:54.483482Z | false |
ourresearch/openalex-guts | https://github.com/ourresearch/openalex-guts/blob/59706e52ceb84b12427334b046c47b7a6d95c862/const.py | const.py | PREPRINT_JOURNAL_IDS = {4306401283, 4306402567, 4306507144, 4306402450,
4306401687, 4306402587, 4210203035, 4306401693,
4306400670, 4306401696, 4306401186, 2883122597,
3005989158, 4306402473, 4306402219, 4306400047,
43064023... | python | MIT | 59706e52ceb84b12427334b046c47b7a6d95c862 | 2026-01-05T07:10:54.483482Z | false |
ourresearch/openalex-guts | https://github.com/ourresearch/openalex-guts/blob/59706e52ceb84b12427334b046c47b7a6d95c862/app.py | app.py | from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_cors import CORS
from flask_compress import Compress
from flask_debugtoolbar import DebugToolbarExtension
import datetime
import shortuuid
from sqlalchemy import exc, create_engine
from sqlalchemy import event
from sqlalchemy.pool import NullPo... | python | MIT | 59706e52ceb84b12427334b046c47b7a6d95c862 | 2026-01-05T07:10:54.483482Z | false |
ourresearch/openalex-guts | https://github.com/ourresearch/openalex-guts/blob/59706e52ceb84b12427334b046c47b7a6d95c862/scripts/update_retraction_watch.py | scripts/update_retraction_watch.py | # -*- coding: utf-8 -*-
DESCRIPTION = """update retraction watch data (https://doi.org/10.13003/c23rw1d9)"""
import sys, os, time
import io
from pathlib import Path
from datetime import datetime
from timeit import default_timer as timer
try:
from humanfriendly import format_timespan
except ImportError:
def ... | python | MIT | 59706e52ceb84b12427334b046c47b7a6d95c862 | 2026-01-05T07:10:54.483482Z | false |
ourresearch/openalex-guts | https://github.com/ourresearch/openalex-guts/blob/59706e52ceb84b12427334b046c47b7a6d95c862/scripts/works_magnet_close_outstanding_issues.py | scripts/works_magnet_close_outstanding_issues.py | import pandas as pd
import requests
import time
import os
import json
from datetime import datetime
GITHUB_PAT = os.getenv('GITHUB_PAT')
headers = {
"Accept": "application/vnd.github+json",
"Authorization": f"Bearer {GITHUB_PAT}",
"X-GitHub-Api-Version": "2022-11-28"
}
import gspread
from google.oauth2 im... | python | MIT | 59706e52ceb84b12427334b046c47b7a6d95c862 | 2026-01-05T07:10:54.483482Z | false |
ourresearch/openalex-guts | https://github.com/ourresearch/openalex-guts/blob/59706e52ceb84b12427334b046c47b7a6d95c862/scripts/modify_redshift_mv.py | scripts/modify_redshift_mv.py | #!/usr/bin/env python3
"""
Redshift Materialized View Modification Script
---------------------------------------------
This script modifies or refreshes a materialized view in Amazon Redshift Serverless. It can also
identify and recreate/refresh all dependent materialized views in the correct order.
Usage:
pyth... | python | MIT | 59706e52ceb84b12427334b046c47b7a6d95c862 | 2026-01-05T07:10:54.483482Z | false |
ourresearch/openalex-guts | https://github.com/ourresearch/openalex-guts/blob/59706e52ceb84b12427334b046c47b7a6d95c862/scripts/datadump_table_updates.py | scripts/datadump_table_updates.py | # coding: utf-8
from sqlalchemy import text
from app import db
# python -m scripts.datadump_table_updates
# date_of_old_release = "20211025"
# date_of_new_release = "20211108"
date_of_old_release = "20211206"
date_of_new_release = "20220102"
# rename outs to have the date of the previous release
if True:
# ... | python | MIT | 59706e52ceb84b12427334b046c47b7a6d95c862 | 2026-01-05T07:10:54.483482Z | false |
ourresearch/openalex-guts | https://github.com/ourresearch/openalex-guts/blob/59706e52ceb84b12427334b046c47b7a6d95c862/scripts/log_works_per_day.py | scripts/log_works_per_day.py | import datetime
import os
import requests
from app import db, logger
from sqlalchemy import text
def send_email(to_address, subject, body):
mailgun_api_key = os.getenv('MAILGUN_API_KEY')
mailgun_url = f"https://api.mailgun.net/v3/ourresearch.org/messages"
mailgun_auth = ("api", mailgun_api_key)
mailgu... | python | MIT | 59706e52ceb84b12427334b046c47b7a6d95c862 | 2026-01-05T07:10:54.483482Z | false |
ourresearch/openalex-guts | https://github.com/ourresearch/openalex-guts/blob/59706e52ceb84b12427334b046c47b7a6d95c862/scripts/handle_duplicates.py | scripts/handle_duplicates.py | import pandas as pd
import requests
def get_paper_details(paper_ids):
formatted_paper_ids = '|'.join([f'W{paper_id}' for paper_id in paper_ids])
url = f'https://api.openalex.org/works?filter=ids.openalex:{formatted_paper_ids}&select=id,ids,locations,authorships&mailto=team@ourresearch.org'
data = requests... | python | MIT | 59706e52ceb84b12427334b046c47b7a6d95c862 | 2026-01-05T07:10:54.483482Z | false |
ourresearch/openalex-guts | https://github.com/ourresearch/openalex-guts/blob/59706e52ceb84b12427334b046c47b7a6d95c862/scripts/export_affiliations.py | scripts/export_affiliations.py | import logging
import os
import subprocess
import time
"""
Run with: heroku local:run python -- -m scripts.export_affiliations
"""
logger = logging.getLogger(__name__)
postgres_db_url = os.getenv("POSTGRES_URL")
def export_postgres_to_s3(query, s3_key, chunk_size):
"""execute the query in chunks and copy the ou... | python | MIT | 59706e52ceb84b12427334b046c47b7a6d95c862 | 2026-01-05T07:10:54.483482Z | false |
ourresearch/openalex-guts | https://github.com/ourresearch/openalex-guts/blob/59706e52ceb84b12427334b046c47b7a6d95c862/scripts/ingest_entity_curation_requests.py | scripts/ingest_entity_curation_requests.py | import json
import os
import re
from datetime import datetime
import argparse
import gspread
import heroku3
import pandas as pd
import requests
from google.oauth2 import service_account
from googleapiclient.discovery import build
from psycopg2 import IntegrityError
from sqlalchemy.orm import sessionmaker
from app imp... | python | MIT | 59706e52ceb84b12427334b046c47b7a6d95c862 | 2026-01-05T07:10:54.483482Z | false |
ourresearch/openalex-guts | https://github.com/ourresearch/openalex-guts/blob/59706e52ceb84b12427334b046c47b7a6d95c862/scripts/redshift_test.py | scripts/redshift_test.py | import argparse
import os
import logging
import glob
import re
import psycopg2
# Set up logging
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
# Get Redshift connection details from environment variables
redshift_db_url = os.getenv("RED... | python | MIT | 59706e52ceb84b12427334b046c47b7a6d95c862 | 2026-01-05T07:10:54.483482Z | false |
ourresearch/openalex-guts | https://github.com/ourresearch/openalex-guts/blob/59706e52ceb84b12427334b046c47b7a6d95c862/scripts/works_magnet_auto_approver.py | scripts/works_magnet_auto_approver.py | import json
import boto3
import os
import botocore
import psycopg2
from openai import OpenAI
from pydantic import BaseModel
openai_api_key = os.getenv("OPENAI_API_KEY")
AWS_ACCESS_KEY_ID = os.getenv("AWS_SAGEMAKER_ACCOUNT_KEY")
AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SAGEMAKER_ACCOUNT_SECRET")
def connect_to_db():
... | python | MIT | 59706e52ceb84b12427334b046c47b7a6d95c862 | 2026-01-05T07:10:54.483482Z | false |
ourresearch/openalex-guts | https://github.com/ourresearch/openalex-guts/blob/59706e52ceb84b12427334b046c47b7a6d95c862/scripts/save_openapc.py | scripts/save_openapc.py | import codecs
import csv
from currency_converter import CurrencyConverter
import requests
from sqlalchemy.sql import text
from app import db
from models.work_openapc import WorkOpenAPC
"""
Ingest data from OpenAPC (https://github.com/OpenAPC/openapc-de) into the mid.work_openapc table.
run with: python -m scripts.s... | python | MIT | 59706e52ceb84b12427334b046c47b7a6d95c862 | 2026-01-05T07:10:54.483482Z | false |
ourresearch/openalex-guts | https://github.com/ourresearch/openalex-guts/blob/59706e52ceb84b12427334b046c47b7a6d95c862/scripts/journal_issn_util.py | scripts/journal_issn_util.py | import os
from argparse import ArgumentParser
import heroku3
from sqlalchemy import text
from .add_things_queue import enqueue_jobs
from app import db
from models import Source
def fast_store_source(source_id, heroku_conn=None):
if not heroku_conn:
heroku_conn = heroku3.from_key(os.environ.get("HEROKU_A... | python | MIT | 59706e52ceb84b12427334b046c47b7a6d95c862 | 2026-01-05T07:10:54.483482Z | false |
ourresearch/openalex-guts | https://github.com/ourresearch/openalex-guts/blob/59706e52ceb84b12427334b046c47b7a6d95c862/scripts/copy_s3_to_postgres.py | scripts/copy_s3_to_postgres.py | import argparse
from os import getenv
from contextlib import contextmanager
import psycopg2
import psycopg2.extras
from urllib.parse import urlparse
from time import time
from util import elapsed
# python -m scripts.copy_s3_to_postgres mid.work_extra_ids
postgres_url = urlparse(getenv("POSTGRES_URL"))
def new_postg... | python | MIT | 59706e52ceb84b12427334b046c47b7a6d95c862 | 2026-01-05T07:10:54.483482Z | false |
ourresearch/openalex-guts | https://github.com/ourresearch/openalex-guts/blob/59706e52ceb84b12427334b046c47b7a6d95c862/scripts/queue_make_parseland_rt_records.py | scripts/queue_make_parseland_rt_records.py | import argparse
import datetime
import hashlib
import json
import uuid
from multiprocessing import Pool
from time import sleep, time
import requests
import shortuuid
from sqlalchemy import text
from sqlalchemy.dialects.postgresql import insert
from app import db
from app import logger
from models import Record
from u... | python | MIT | 59706e52ceb84b12427334b046c47b7a6d95c862 | 2026-01-05T07:10:54.483482Z | false |
ourresearch/openalex-guts | https://github.com/ourresearch/openalex-guts/blob/59706e52ceb84b12427334b046c47b7a6d95c862/scripts/queue_work_update_authors.py | scripts/queue_work_update_authors.py | import argparse
import json
from time import sleep
from time import time
from sqlalchemy import orm
from sqlalchemy import text
from sqlalchemy.orm import selectinload
import models
from app import db
from app import logger
from util import elapsed
def update_authors(work):
if work.affiliation_records_sorted:
... | python | MIT | 59706e52ceb84b12427334b046c47b7a6d95c862 | 2026-01-05T07:10:54.483482Z | false |
ourresearch/openalex-guts | https://github.com/ourresearch/openalex-guts/blob/59706e52ceb84b12427334b046c47b7a6d95c862/scripts/import_ror.py | scripts/import_ror.py | # coding: utf-8
# old
#
# from sqlalchemy.dialects.postgresql import JSONB
# from sqlalchemy.sql import text
# from executor import execute
# import requests
# from time import time
# from time import sleep
# import datetime
# import shortuuid
# from urllib import quote
# import os
# import re
# import simplejson as j... | python | MIT | 59706e52ceb84b12427334b046c47b7a6d95c862 | 2026-01-05T07:10:54.483482Z | false |
ourresearch/openalex-guts | https://github.com/ourresearch/openalex-guts/blob/59706e52ceb84b12427334b046c47b7a6d95c862/scripts/concat_s3_files.py | scripts/concat_s3_files.py | import tempfile
import argparse
import concurrent.futures
import re
from collections import defaultdict
from functools import partial
from os import getenv
import io
import boto
import boto3
from s3_concat import MultipartUploadJob
from s3_concat import S3Concat
from s3_concat.utils import _threads, _chunk_by_size, MI... | python | MIT | 59706e52ceb84b12427334b046c47b7a6d95c862 | 2026-01-05T07:10:54.483482Z | false |
ourresearch/openalex-guts | https://github.com/ourresearch/openalex-guts/blob/59706e52ceb84b12427334b046c47b7a6d95c862/scripts/merge.py | scripts/merge.py | import argparse
from sqlalchemy import orm
from sqlalchemy.orm import selectinload
from os import getenv
from urllib.parse import urlparse
from time import time
import datetime
import sys
import models
from app import db
from merge.merge_institution import process_institution as merge_one_institution
from util import... | python | MIT | 59706e52ceb84b12427334b046c47b7a6d95c862 | 2026-01-05T07:10:54.483482Z | false |
ourresearch/openalex-guts | https://github.com/ourresearch/openalex-guts/blob/59706e52ceb84b12427334b046c47b7a6d95c862/scripts/queue_work_process_sdgs.py | scripts/queue_work_process_sdgs.py | import argparse
import json
from time import sleep
from time import time
import random
import requests
from sqlalchemy import orm
from sqlalchemy import text
from sqlalchemy.orm import selectinload
import models
from app import db, logger, SDG_CLASSIFIER_URL
from util import elapsed
"""
Run with: heroku local:run py... | python | MIT | 59706e52ceb84b12427334b046c47b7a6d95c862 | 2026-01-05T07:10:54.483482Z | false |
ourresearch/openalex-guts | https://github.com/ourresearch/openalex-guts/blob/59706e52ceb84b12427334b046c47b7a6d95c862/scripts/clean_elastic_deleted_docs.py | scripts/clean_elastic_deleted_docs.py | import time
from elasticsearch import Elasticsearch
from app import ELASTIC_URL
es = Elasticsearch([ELASTIC_URL])
""""
Run daily to clean up deleted documents in ElasticSearch.
Command is: heroku local:run -- python -m scripts.clean_elastic_deleted_docs
"""
response = es.cat.indices(format='json', h='index,docs.dele... | python | MIT | 59706e52ceb84b12427334b046c47b7a6d95c862 | 2026-01-05T07:10:54.483482Z | false |
ourresearch/openalex-guts | https://github.com/ourresearch/openalex-guts/blob/59706e52ceb84b12427334b046c47b7a6d95c862/scripts/queue_work_add_everything.py | scripts/queue_work_add_everything.py | import argparse
import logging
import re
from time import sleep, time, mktime, gmtime
from timeit import default_timer as timer
from humanfriendly import format_timespan
from redis import Redis
from redis.exceptions import ConnectionError
from sqlalchemy import text
from tenacity import retry, wait_fixed, stop_after_a... | python | MIT | 59706e52ceb84b12427334b046c47b7a6d95c862 | 2026-01-05T07:10:54.483482Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.