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
AdaInt
AdaInt-main/tests/test_models/test_backbones/test_encoder_decoders/test_encoder_decoder.py
# Copyright (c) OpenMMLab. All rights reserved. import numpy as np import torch from mmedit.models.backbones import SimpleEncoderDecoder def assert_dict_keys_equal(dictionary, target_keys): """Check if the keys of the dictionary is equal to the target key set.""" assert isinstance(dictionary, dict) asser...
3,362
35.956044
79
py
AdaInt
AdaInt-main/tests/test_models/test_backbones/test_encoder_decoders/test_encoders.py
# Copyright (c) OpenMMLab. All rights reserved. from collections.abc import Iterable import numpy as np import pytest import torch from mmcv.utils.parrots_wrapper import _BatchNorm from mmedit.models.backbones import (VGG16, DepthwiseIndexBlock, FBAResnetDilated, HolisticIndexBloc...
24,631
38.22293
79
py
AdaInt
AdaInt-main/tests/test_models/test_backbones/test_encoder_decoders/test_pconv_encdec.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from mmcv.utils.parrots_wrapper import _BatchNorm from mmedit.models.backbones import PConvEncoder, PConvEncoderDecoder def test_pconv_encdec(): pconv_enc_cfg = dict(type='PConvEncoder') pconv_dec_cfg = dict(type='PConvDecoder') ...
1,280
31.025
72
py
AdaInt
AdaInt-main/tests/test_models/test_backbones/test_encoder_decoders/test_deepfill_encdec.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from mmedit.models.backbones import DeepFillEncoderDecoder, GLEncoderDecoder from mmedit.models.components import DeepFillRefiner def test_deepfill_encdec(): encdec = DeepFillEncoderDecoder() assert isinstance(encdec.stage1, GLEncoderDecoder) a...
961
37.48
76
py
AdaInt
AdaInt-main/tests/test_models/test_extractors/test_feedback_hour_glass.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from mmedit.models import build_component from mmedit.models.extractors import Hourglass from mmedit.models.extractors.feedback_hour_glass import ( ResBlock, reduce_to_five_heatmaps) def test_res_block(): res_block = ResBlock(16, 32)...
2,154
30.231884
68
py
AdaInt
AdaInt-main/tests/test_models/test_extractors/test_lte.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from mmedit.models import build_component def test_lte(): model_cfg = dict( type='LTE', requires_grad=False, pixel_range=1., pretrained=None, load_pretrained_vgg=False) lte = build_component(mo...
863
24.411765
47
py
AdaInt
AdaInt-main/tests/test_models/test_synthesizers/test_cyclegan.py
# Copyright (c) OpenMMLab. All rights reserved. import copy from unittest.mock import patch import mmcv import pytest import torch from mmcv.parallel import DataContainer as DC from mmcv.runner import obj_from_dict from mmedit.models import build_model from mmedit.models.backbones import ResnetGenerator from mmedit.m...
23,294
40.747312
78
py
AdaInt
AdaInt-main/tests/test_models/test_restorers/test_basicvsr_model.py
# Copyright (c) OpenMMLab. All rights reserved. import tempfile import mmcv import pytest import torch from mmcv.runner import obj_from_dict from mmedit.models import build_model from mmedit.models.backbones.sr_backbones import BasicVSRNet from mmedit.models.losses import MSELoss def test_basicvsr_model(): mod...
5,163
32.973684
79
py
AdaInt
AdaInt-main/tests/test_models/test_restorers/test_tdan.py
# Copyright (c) OpenMMLab. All rights reserved. import tempfile import mmcv import pytest import torch from mmcv.runner import obj_from_dict from mmedit.models import build_model from mmedit.models.backbones import TDANNet from mmedit.models.losses import MSELoss def test_tdan_model(): model_cfg = dict( ...
5,090
34.110345
77
py
AdaInt
AdaInt-main/tests/test_models/test_restorers/test_real_esrgan.py
# Copyright (c) OpenMMLab. All rights reserved. from unittest.mock import patch import pytest import torch from mmcv.runner import obj_from_dict from mmedit.models import build_model from mmedit.models.backbones import MSRResNet from mmedit.models.components import ModifiedVGG from mmedit.models.losses import GANLoss...
10,264
38.480769
79
py
AdaInt
AdaInt-main/tests/test_models/test_restorers/test_glean.py
# Copyright (c) OpenMMLab. All rights reserved. import mmcv import pytest import torch from mmedit.models import build_model def test_glean(): model_cfg = dict( type='GLEAN', generator=dict( type='GLEANStyleGANv2', in_size=16, out_size=64, style_ch...
2,269
30.971831
78
py
AdaInt
AdaInt-main/tests/test_models/test_restorers/test_liif.py
# Copyright (c) OpenMMLab. All rights reserved. import numpy as np import torch import torch.nn as nn from mmcv.runner import obj_from_dict from mmcv.utils.config import Config from mmedit.models import build_model from mmedit.models.registry import COMPONENTS @COMPONENTS.register_module() class BP(nn.Module): "...
4,114
33.579832
77
py
AdaInt
AdaInt-main/tests/test_models/test_restorers/test_dic_model.py
# Copyright (c) OpenMMLab. All rights reserved. import numpy as np import pytest import torch from mmcv.runner import obj_from_dict from mmcv.utils.config import Config from mmedit.models.builder import build_model def test_dic_model(): pretrained = 'https://download.openmmlab.com/mmediting/' + \ 'restor...
4,844
39.375
77
py
AdaInt
AdaInt-main/tests/test_models/test_restorers/test_ttsr.py
# Copyright (c) OpenMMLab. All rights reserved. import numpy as np import torch from mmcv.runner import obj_from_dict from mmcv.utils.config import Config from mmedit.models import build_backbone, build_model from mmedit.models.backbones.sr_backbones.ttsr_net import (CSFI2, CSFI3, SFE, ...
7,308
33.63981
77
py
AdaInt
AdaInt-main/tests/test_models/test_restorers/test_esrgan.py
# Copyright (c) OpenMMLab. All rights reserved. from unittest.mock import patch import torch from mmcv.runner import obj_from_dict from mmedit.models import build_model from mmedit.models.backbones import MSRResNet from mmedit.models.components import ModifiedVGG from mmedit.models.losses import GANLoss, L1Loss def...
7,807
39.666667
79
py
AdaInt
AdaInt-main/tests/test_models/test_restorers/test_edvr_model.py
# Copyright (c) OpenMMLab. All rights reserved. import tempfile import mmcv import pytest import torch from mmcv.runner import obj_from_dict from mmedit.models import build_model from mmedit.models.backbones import EDVRNet from mmedit.models.losses import L1Loss def test_edvr_model(): model_cfg = dict( ...
6,625
35.406593
77
py
AdaInt
AdaInt-main/tests/test_models/test_restorers/test_srgan.py
# Copyright (c) OpenMMLab. All rights reserved. from unittest.mock import patch import pytest import torch from mmcv.runner import obj_from_dict from mmedit.models import build_model from mmedit.models.backbones import MSRResNet from mmedit.models.components import ModifiedVGG from mmedit.models.losses import GANLoss...
9,665
39.107884
79
py
AdaInt
AdaInt-main/tests/test_models/test_restorers/test_basic_restorer.py
# Copyright (c) OpenMMLab. All rights reserved. import tempfile import mmcv import pytest import torch from mmcv.runner import obj_from_dict from mmedit.models import build_model from mmedit.models.backbones import MSRResNet from mmedit.models.losses import L1Loss def test_basic_restorer(): model_cfg = dict( ...
6,208
35.309942
77
py
AdaInt
AdaInt-main/tests/test_models/test_mattors/test_mattors.py
# Copyright (c) OpenMMLab. All rights reserved. import os.path as osp from unittest.mock import patch import mmcv import numpy as np import pytest import torch from mmedit.models import BaseMattor, build_model def _get_model_cfg(fname): """ Grab configs necessary to create a model. These are deep copied to ...
14,057
37.620879
79
py
AdaInt
AdaInt-main/tests/test_models/test_losses/test_losses.py
# Copyright (c) OpenMMLab. All rights reserved. import math from unittest.mock import patch import numpy.testing as npt import pytest import torch from mmedit.models import (CharbonnierCompLoss, CharbonnierLoss, DiscShiftLoss, GANLoss, GradientLoss, GradientPenaltyLoss, ...
16,288
34.105603
79
py
AdaInt
AdaInt-main/tests/test_models/test_losses/test_feature_loss.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from mmedit.models.losses import LightCNNFeatureLoss def test_light_cnn_feature_loss(): pretrained = 'https://download.openmmlab.com/mmediting/' + \ 'restorers/dic/light_cnn_feature.pth' pred = torch.rand((3, 3, 128, 128)) ...
1,600
28.648148
78
py
AdaInt
AdaInt-main/tests/test_models/test_common/test_common_module.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch import torch.nn as nn from mmedit.models.common import (ASPP, DepthwiseSeparableConvModule, GCAModule, LinearModule, MaskConvModule, PartialConv2d, SimpleGatedConvModule) def...
10,851
31.984802
79
py
AdaInt
AdaInt-main/tests/test_models/test_common/test_img_normalize.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from mmedit.models.common import ImgNormalize def test_normalize_layer(): rgb_mean = (1, 2, 3) rgb_std = (1, 0.5, 0.25) layer = ImgNormalize(1, rgb_mean, rgb_std) x = torch.randn((2, 3, 64, 64)) y = layer(x) x = x.permute((1, 0, 2, ...
695
29.26087
69
py
AdaInt
AdaInt-main/tests/test_models/test_common/test_flow_warp.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from mmedit.models import flow_warp def tensor_shift(x, shift=(1, 1), fill_val=0): """Shift tensor for testing flow_warp. Args: x (Tensor): the input tensor. The shape is (b, c, h, w]. shift (tuple): shift pixel. ...
1,471
26.773585
76
py
AdaInt
AdaInt-main/tests/test_models/test_common/test_model_utils.py
# Copyright (c) OpenMMLab. All rights reserved. import copy import numpy as np import pytest import torch import torch.nn as nn from mmedit.models.common import (GANImageBuffer, extract_around_bbox, extract_bbox_patch, generation_init_weights, set_re...
5,756
38.979167
78
py
AdaInt
AdaInt-main/tests/test_models/test_transformer/test_search_transformer.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from mmedit.models.builder import build_component def test_search_transformer(): model_cfg = dict(type='SearchTransformer') model = build_component(model_cfg) lr_pad_level3 = torch.randn((2, 32, 32, 32)) ref_pad_level3 = torch.randn((2, 32...
806
31.28
61
py
AdaInt
AdaInt-main/tests/test_models/test_components/test_stylegan2.py
# Copyright (c) OpenMMLab. All rights reserved. from copy import deepcopy import pytest import torch import torch.nn as nn from mmedit.models.components.stylegan2.common import get_module_device from mmedit.models.components.stylegan2.generator_discriminator import ( StyleGAN2Discriminator, StyleGANv2Generator) f...
8,432
30.466418
79
py
AdaInt
AdaInt-main/tests/test_models/test_components/test_refiners/test_mlp_refiner.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from mmedit.models.builder import build_component def test_mlp_refiner(): model_cfg = dict( type='MLPRefiner', in_dim=8, out_dim=3, hidden_list=[8, 8, 8, 8]) mlp = build_component(model_cfg) # test attributes ...
971
26.771429
73
py
AdaInt
AdaInt-main/tests/test_models/test_components/test_refiners/test_matting_refiners.py
# Copyright (c) OpenMMLab. All rights reserved. import numpy as np import torch from mmedit.models import PlainRefiner def assert_dict_keys_equal(dictionary, target_keys): """Check if the keys of the dictionary is equal to the target key set.""" assert isinstance(dictionary, dict) assert set(dictionary.k...
2,239
34.555556
79
py
AdaInt
AdaInt-main/tests/test_models/test_components/test_refiners/test_deepfill_refiner.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from mmedit.models import (ContextualAttentionNeck, DeepFillDecoder, DeepFillEncoder, DeepFillRefiner, GLDilationNeck) def test_deepfill_refiner(): refiner = DeepFillRefiner() x = torch.rand((2, 5, 256, 256)) mask = ...
1,564
37.170732
76
py
AdaInt
AdaInt-main/tests/test_models/test_components/test_discriminators/test_light_cnn.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from mmedit.models.builder import build_component from mmedit.models.components.discriminators.light_cnn import MaxFeature def test_max_feature(): # cpu conv2d = MaxFeature(16, 16, filter_type='conv2d') x1 = torch.rand(3, 16, 16, ...
1,475
27.384615
72
py
AdaInt
AdaInt-main/tests/test_models/test_components/test_discriminators/test_discriminators.py
# Copyright (c) OpenMMLab. All rights reserved. import copy import numpy as np import pytest import torch from mmedit.models import build_component def test_ttsr_dict(): cfg = dict(type='TTSRDiscriminator', in_channels=3, in_size=160) net = build_component(cfg) net.init_weights(pretrained=None) # cp...
2,904
25.898148
68
py
AdaInt
AdaInt-main/tests/test_models/test_components/test_discriminators/test_deepfill_disc.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch from mmedit.models.components import (DeepFillv1Discriminators, MultiLayerDiscriminator) def test_deepfillv1_disc(): model_config = dict( global_disc_cfg=dict( type='MultiLayerDisc...
1,862
34.826923
68
py
AdaInt
AdaInt-main/tests/test_models/test_components/test_discriminators/test_multi_layer_disc.py
# Copyright (c) OpenMMLab. All rights reserved. import pytest import torch import torch.nn as nn from mmedit.models.components import MultiLayerDiscriminator def test_multi_layer_disc(): with pytest.raises(AssertionError): # fc_in_channels must be greater than 0 multi_disc = MultiLayerDiscriminat...
3,133
34.613636
71
py
AdaInt
AdaInt-main/tests/test_models/test_inpaintors/test_deepfill_inpaintor.py
# Copyright (c) OpenMMLab. All rights reserved. import copy import os import tempfile import pytest import torch from mmcv import Config from mmedit.core import build_optimizers from mmedit.models import DeepFillv1Inpaintor def test_two_stage_inpaintor(): model = dict( disc_input_with_mask=True, ...
12,857
38.441718
79
py
AdaInt
AdaInt-main/tests/test_models/test_inpaintors/test_gl_inpaintor.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from mmcv import Config from mmedit.models import build_model def test_gl_inpaintor(): cfg = Config.fromfile('tests/data/inpaintor_config/gl_test.py') gl = build_model(cfg.model, train_cfg=cfg.train_cfg, test_cfg=cfg.test_cfg) assert gl.__cla...
2,138
37.196429
79
py
AdaInt
AdaInt-main/tests/test_models/test_inpaintors/test_pconv_inpaintor.py
# Copyright (c) OpenMMLab. All rights reserved. import os import tempfile from unittest.mock import patch import pytest import torch from mmcv import Config from mmedit.models import build_model from mmedit.models.losses import PerceptualVGG @patch.object(PerceptualVGG, 'init_weights') def test_pconv_inpaintor(init...
3,937
36.865385
74
py
AdaInt
AdaInt-main/tests/test_models/test_inpaintors/test_two_stage_inpaintor.py
# Copyright (c) OpenMMLab. All rights reserved. import copy import os import tempfile import pytest import torch from mmcv import Config from mmedit.core import build_optimizers from mmedit.models import TwoStageInpaintor def test_two_stage_inpaintor(): model = dict( disc_input_with_mask=True, e...
14,419
38.184783
79
py
AdaInt
AdaInt-main/tests/test_models/test_inpaintors/test_one_stage_inpaintor.py
# Copyright (c) OpenMMLab. All rights reserved. import copy import os import tempfile from unittest.mock import patch import pytest import torch from mmcv import Config from mmedit.models import build_model from mmedit.models.backbones import GLEncoderDecoder def test_one_stage_inpaintor(): cfg = Config.fromfil...
6,045
39.306667
79
py
AdaInt
AdaInt-main/tests/test_data/test_datasets/test_repeat_dataset.py
# Copyright (c) OpenMMLab. All rights reserved. from torch.utils.data import Dataset from mmedit.datasets import RepeatDataset def test_repeat_dataset(): class ToyDataset(Dataset): def __init__(self): super().__init__() self.members = [1, 2, 3, 4, 5] def __len__(self): ...
623
23
50
py
AdaInt
AdaInt-main/tests/test_data/test_pipelines/test_formating.py
# Copyright (c) OpenMMLab. All rights reserved. import numpy as np import pytest import torch from mmedit.datasets.pipelines import (Collect, FormatTrimap, GetMaskedImage, ImageToTensor, ToTensor) from mmedit.datasets.pipelines.formating import FramesToTensor def check_keys_con...
7,142
36.793651
78
py
AdaInt
AdaInt-main/tests/test_data/test_pipelines/test_generate_assistant.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from mmedit.datasets.pipelines import (GenerateCoordinateAndCell, GenerateHeatmap) def test_generate_heatmap(): inputs = dict(landmark=[(1, 2), (3, 4)]) generate_heatmap = GenerateHeatmap('landmark', 4, 16) ...
2,102
39.442308
77
py
AdaInt
AdaInt-main/tests/test_data/test_pipelines/test_pipeline_utils.py
# Copyright (c) OpenMMLab. All rights reserved. import numpy as np import pytest import torch from mmedit.datasets.pipelines.utils import (adjust_gamma, dtype_range, make_coord) def test_adjust_gamma(): """Test Gamma Correction Adpted from # https://github.co...
3,075
36.512195
149
py
AdaInt
AdaInt-main/tests/test_data/test_pipelines/test_augmentation.py
# Copyright (c) OpenMMLab. All rights reserved. import copy import numpy as np import pytest import torch from mmedit.datasets.pipelines import (BinarizeImage, CopyValues, Flip, GenerateFrameIndices, GenerateFrameIndiceswithPadding, ...
31,370
41.50813
79
py
AdaInt
AdaInt-main/tests/test_utils/test_tensor2img.py
# Copyright (c) OpenMMLab. All rights reserved. import numpy as np import pytest import torch from torchvision.utils import make_grid from mmedit.core import tensor2img def test_tensor2img(): tensor_4d_1 = torch.FloatTensor(2, 3, 4, 4).uniform_(0, 1) tensor_4d_2 = torch.FloatTensor(1, 3, 4, 4).uniform_(0, 1)...
3,609
41.97619
77
py
AdaInt
AdaInt-main/tests/test_utils/test_pix2pix.py
# Copyright (c) OpenMMLab. All rights reserved. import copy from unittest.mock import patch import mmcv import pytest import torch from mmcv.parallel import DataContainer as DC from mmcv.runner import obj_from_dict from mmedit.models import build_model from mmedit.models.backbones import UnetGenerator from mmedit.mod...
16,144
38.864198
79
py
AdaInt
AdaInt-main/tests/test_utils/test_onnx_wraper.py
# Copyright (c) OpenMMLab. All rights reserved. import os import mmcv import numpy as np import pytest import torch from packaging import version from mmedit.models import build_model @pytest.mark.skipif(torch.__version__ == 'parrots', reason='skip parrots.') @pytest.mark.skipif( version.parse(torch.__version__...
5,041
31.320513
79
py
AdaInt
AdaInt-main/adaint/model.py
import numbers import os.path as osp import torch import torch.nn as nn import torch.nn.functional as F import torchvision import mmcv from mmcv.runner import auto_fp16 from mmedit.models.base import BaseModel from mmedit.models.registry import MODELS from mmedit.models.builder import build_loss from mmedit.core imp...
17,975
35.987654
103
py
AdaInt
AdaInt-main/adaint/demo.py
import os import argparse import mmcv import torch from mmcv.parallel import collate, scatter from mmedit.apis import init_model from mmedit.core import tensor2img from mmedit.datasets.pipelines import Compose def enhancement_inference(model, img): r"""Inference image with the model. Args: model (nn...
2,448
31.653333
79
py
AdaInt
AdaInt-main/adaint/transforms.py
import random import numpy as np from PIL import Image from torch.nn.modules.utils import _pair from torchvision.transforms import ColorJitter from mmedit.datasets.registry import PIPELINES @PIPELINES.register_module() class RandomRatioCrop(object): r"""Random crop the image. Args: keys (Sequence[st...
5,694
36.715232
111
py
AdaInt
AdaInt-main/adaint/ailut_transform/setup.py
import os import os.path as osp from setuptools import setup, find_packages from torch.utils.cpp_extension import BuildExtension, CUDAExtension def get_version(version_file): with open(version_file, 'r') as f: exec(compile(f.read(), version_file, 'exec')) return locals()['__version__'] os.chdir(osp....
1,466
30.891304
67
py
AdaInt
AdaInt-main/adaint/ailut_transform/ailut/pyinterfaces.py
from typing import Tuple import torch from torch.cuda.amp import custom_fwd, custom_bwd from ._ext import ( lut_cforward, lut_cbackward, ailut_cforward, ailut_cbackward ) class LUTTransformFunction(torch.autograd.Function): @staticmethod @custom_fwd(cast_inputs=torch.float32) def forward(ctx, ...
3,728
29.072581
89
py
AdaInt
AdaInt-main/mmedit/apis/test.py
# Copyright (c) OpenMMLab. All rights reserved. import os.path as osp import pickle import shutil import tempfile import mmcv import torch import torch.distributed as dist from mmcv.runner import get_dist_info def single_gpu_test(model, data_loader, save_image=False, ...
7,852
32.417021
79
py
AdaInt
AdaInt-main/mmedit/apis/restoration_face_inference.py
# Copyright (c) OpenMMLab. All rights reserved. import numpy as np import torch from mmcv.parallel import collate, scatter from mmedit.datasets.pipelines import Compose try: from facexlib.utils.face_restoration_helper import FaceRestoreHelper has_facexlib = True except ImportError: has_facexlib = False ...
3,069
33.494382
77
py
AdaInt
AdaInt-main/mmedit/apis/generation_inference.py
# Copyright (c) OpenMMLab. All rights reserved. import numpy as np import torch from mmcv.parallel import collate, scatter from mmedit.core import tensor2img from mmedit.datasets.pipelines import Compose def generation_inference(model, img, img_unpaired=None): """Inference image with the model. Args: ...
2,229
34.967742
74
py
AdaInt
AdaInt-main/mmedit/apis/inpainting_inference.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from mmcv.parallel import collate, scatter from mmedit.datasets.pipelines import Compose def inpainting_inference(model, masked_img, mask): """Inference image with the model. Args: model (nn.Module): The loaded model. masked_img (s...
1,546
29.94
70
py
AdaInt
AdaInt-main/mmedit/apis/restoration_inference.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from mmcv.parallel import collate, scatter from mmedit.datasets.pipelines import Compose def restoration_inference(model, img): """Inference image with the model. Args: model (nn.Module): The loaded model. img (str): File path of i...
1,434
32.372093
72
py
AdaInt
AdaInt-main/mmedit/apis/matting_inference.py
# Copyright (c) OpenMMLab. All rights reserved. import mmcv import torch from mmcv.parallel import collate, scatter from mmcv.runner import load_checkpoint from mmedit.datasets.pipelines import Compose from mmedit.models import build_model def init_model(config, checkpoint=None, device='cuda:0'): """Initialize a...
2,659
33.545455
79
py
AdaInt
AdaInt-main/mmedit/apis/train.py
# Copyright (c) OpenMMLab. All rights reserved. import os import os.path as osp import random import warnings import mmcv import numpy as np import torch from mmcv.parallel import MMDataParallel from mmcv.runner import HOOKS, IterBasedRunner from mmcv.utils import build_from_cfg from mmedit.core import DistEvalIterHo...
11,841
34.776435
79
py
AdaInt
AdaInt-main/mmedit/apis/restoration_video_inference.py
# Copyright (c) OpenMMLab. All rights reserved. import glob import torch from mmcv.parallel import collate, scatter from mmedit.datasets.pipelines import Compose def pad_sequence(data, window_size): padding = window_size // 2 data = torch.cat([ data[:, 1 + padding:1 + 2 * padding].flip(1), data, ...
2,942
32.443182
78
py
AdaInt
AdaInt-main/mmedit/core/distributed_wrapper.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from mmcv.parallel import MODULE_WRAPPERS, MMDistributedDataParallel from mmcv.parallel.scatter_gather import scatter_kwargs from torch.cuda._utils import _get_device_index @MODULE_WRAPPERS.register_module() class DistributedDataParall...
5,720
39.864286
79
py
AdaInt
AdaInt-main/mmedit/core/misc.py
# Copyright (c) OpenMMLab. All rights reserved. import math import numpy as np import torch from torchvision.utils import make_grid def tensor2img(tensor, out_type=np.uint8, min_max=(0, 1)): """Convert torch Tensors into image numpy arrays. After clamping to (min, max), image values will be normalized to [0...
2,898
37.653333
79
py
AdaInt
AdaInt-main/mmedit/core/evaluation/eval_hooks.py
# Copyright (c) OpenMMLab. All rights reserved. import os.path as osp from mmcv.runner import Hook from torch.utils.data import DataLoader class EvalIterHook(Hook): """Non-Distributed evaluation hook for iteration-based runner. This hook will regularly perform evaluation in a given interval when perform...
3,766
33.87963
75
py
AdaInt
AdaInt-main/mmedit/core/export/wrappers.py
# Copyright (c) OpenMMLab. All rights reserved. import os.path as osp import warnings import numpy as np import onnxruntime as ort import torch from torch import nn from mmedit.models import BaseMattor, BasicRestorer, build_model def inference_with_session(sess, io_binding, output_names, input_tensor): device_t...
4,767
34.318519
79
py
AdaInt
AdaInt-main/mmedit/core/hooks/visualization.py
# Copyright (c) OpenMMLab. All rights reserved. import os.path as osp import mmcv import torch from mmcv.runner import HOOKS, Hook from mmcv.runner.dist_utils import master_only from torchvision.utils import save_image @HOOKS.register_module() class VisualizationHook(Hook): """Visualization hook. In this ho...
3,050
34.894118
79
py
AdaInt
AdaInt-main/mmedit/core/hooks/ema.py
# Copyright (c) OpenMMLab. All rights reserved. import warnings from copy import deepcopy from functools import partial import mmcv import torch from mmcv.parallel import is_module_wrapper from mmcv.runner import HOOKS, Hook @HOOKS.register_module() class ExponentialMovingAverageHook(Hook): """Exponential Moving...
4,719
40.403509
79
py
AdaInt
AdaInt-main/mmedit/core/optimizer/builder.py
# Copyright (c) OpenMMLab. All rights reserved. from mmcv.runner import build_optimizer def build_optimizers(model, cfgs): """Build multiple optimizers from configs. If `cfgs` contains several dicts for optimizers, then a dict for each constructed optimizers will be returned. If `cfgs` only contains ...
1,679
27.474576
78
py
AdaInt
AdaInt-main/mmedit/models/base.py
# Copyright (c) OpenMMLab. All rights reserved. from abc import ABCMeta, abstractmethod from collections import OrderedDict import torch import torch.nn as nn class BaseModel(nn.Module, metaclass=ABCMeta): """Base model. All models should subclass it. All subclass should overwrite: ``init_weigh...
2,948
26.820755
79
py
AdaInt
AdaInt-main/mmedit/models/builder.py
# Copyright (c) OpenMMLab. All rights reserved. import torch.nn as nn from mmcv import build_from_cfg from .registry import BACKBONES, COMPONENTS, LOSSES, MODELS def build(cfg, registry, default_args=None): """Build module function. Args: cfg (dict): Configuration for building modules. regis...
1,482
23.311475
75
py
AdaInt
AdaInt-main/mmedit/models/restorers/basicvsr.py
# Copyright (c) OpenMMLab. All rights reserved. import numbers import os.path as osp import mmcv import numpy as np import torch from mmedit.core import tensor2img from ..registry import MODELS from .basic_restorer import BasicRestorer @MODELS.register_module() class BasicVSR(BasicRestorer): """BasicVSR model f...
7,576
35.781553
79
py
AdaInt
AdaInt-main/mmedit/models/restorers/liif.py
# Copyright (c) OpenMMLab. All rights reserved. import math import numbers import os.path as osp import mmcv import torch from mmedit.core import tensor2img from ..registry import MODELS from .basic_restorer import BasicRestorer @MODELS.register_module() class LIIF(BasicRestorer): """LIIF model for single image...
6,371
31.845361
79
py
AdaInt
AdaInt-main/mmedit/models/restorers/dic.py
# Copyright (c) OpenMMLab. All rights reserved. import numbers import os.path as osp import mmcv import torch from mmedit.core import tensor2img from mmedit.models.common import ImgNormalize from ..builder import build_backbone, build_component, build_loss from ..common import set_requires_grad from ..registry import...
9,366
34.34717
79
py
AdaInt
AdaInt-main/mmedit/models/restorers/ttsr.py
# Copyright (c) OpenMMLab. All rights reserved. import numbers import os.path as osp import mmcv import torch from mmedit.core import tensor2img from ..builder import build_backbone, build_component, build_loss from ..common import set_requires_grad from ..registry import MODELS from .basic_restorer import BasicResto...
11,581
36.003195
79
py
AdaInt
AdaInt-main/mmedit/models/restorers/real_esrgan.py
import numbers import os.path as osp from copy import deepcopy import mmcv import torch from mmcv.parallel import is_module_wrapper from mmedit.core import tensor2img from ..common import set_requires_grad from ..registry import MODELS from .srgan import SRGAN @MODELS.register_module() class RealESRGAN(SRGAN): ...
8,849
36.820513
79
py
AdaInt
AdaInt-main/mmedit/models/restorers/esrgan.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from ..common import set_requires_grad from ..registry import MODELS from .srgan import SRGAN @MODELS.register_module() class ESRGAN(SRGAN): """Enhanced SRGAN model for single image super-resolution. Ref: ESRGAN: Enhanced Super-Resolution Gene...
4,694
35.395349
79
py
AdaInt
AdaInt-main/mmedit/models/extractors/lte.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from mmcv.runner import load_checkpoint from torchvision import models from mmedit.models.common import ImgNormalize from mmedit.models.registry import COMPONENTS from mmedit.utils import get_root_logger @COMPONENTS.register_module() ...
3,781
33.697248
79
py
AdaInt
AdaInt-main/mmedit/models/extractors/feedback_hour_glass.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from mmedit.models.registry import COMPONENTS class ResBlock(nn.Module): """ResBlock for Hourglass. It has a style of: :: ---Conv-ReLU-Conv-Conv-+- |_________Conv________| or ---Conv-R...
7,183
32.7277
79
py
AdaInt
AdaInt-main/mmedit/models/common/flow_warp.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn.functional as F def flow_warp(x, flow, interpolation='bilinear', padding_mode='zeros', align_corners=True): """Warp an image or a feature map with optical flow. Args: x...
1,781
36.125
78
py
AdaInt
AdaInt-main/mmedit/models/common/aspp.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from mmcv.cnn import ConvModule from torch import nn from torch.nn import functional as F from .separable_conv_module import DepthwiseSeparableConvModule class ASPPPooling(nn.Sequential): def __init__(self, in_channels, out_channels, conv_cfg, norm_cf...
3,861
29.650794
79
py
AdaInt
AdaInt-main/mmedit/models/common/sr_backbone_utils.py
# Copyright (c) OpenMMLab. All rights reserved. import torch.nn as nn from mmcv.cnn import constant_init, kaiming_init from mmcv.utils.parrots_wrapper import _BatchNorm def default_init_weights(module, scale=1): """Initialize network weights. Args: modules (nn.Module): Modules to be initialized. ...
2,919
28.795918
78
py
AdaInt
AdaInt-main/mmedit/models/common/model_utils.py
# Copyright (c) OpenMMLab. All rights reserved. import numpy as np import torch def set_requires_grad(nets, requires_grad=False): """Set requires_grad for all the networks. Args: nets (nn.Module | list[nn.Module]): A list of networks or a single network. requires_grad (bool): Whet...
4,502
31.868613
79
py
AdaInt
AdaInt-main/mmedit/models/common/separable_conv_module.py
# Copyright (c) OpenMMLab. All rights reserved. import torch.nn as nn from mmcv.cnn import ConvModule class DepthwiseSeparableConvModule(nn.Module): """Depthwise separable convolution module. See https://arxiv.org/pdf/1704.04861.pdf for details. This module can replace a ConvModule with the conv block r...
3,907
38.877551
79
py
AdaInt
AdaInt-main/mmedit/models/common/linear_module.py
# Copyright (c) OpenMMLab. All rights reserved. import torch.nn as nn from mmcv.cnn import build_activation_layer, kaiming_init class LinearModule(nn.Module): """A linear block that contains linear/norm/activation layers. For low level vision, we add spectral norm and padding layer. Args: in_fea...
3,211
34.688889
78
py
AdaInt
AdaInt-main/mmedit/models/common/contextual_attention.py
# Copyright (c) OpenMMLab. All rights reserved. from functools import partial import torch import torch.nn as nn import torch.nn.functional as F class ContextualAttentionModule(nn.Module): """Contexture attention module. The details of this module can be found in: Generative Image Inpainting with Contex...
15,214
39.039474
79
py
AdaInt
AdaInt-main/mmedit/models/common/gated_conv_module.py
# Copyright (c) OpenMMLab. All rights reserved. import copy import torch import torch.nn as nn from mmcv.cnn import ConvModule, build_activation_layer class SimpleGatedConvModule(nn.Module): """Simple Gated Convolutional Module. This module is a simple gated convolutional module. The detailed formula is...
2,423
32.205479
79
py
AdaInt
AdaInt-main/mmedit/models/common/conv.py
# Copyright (c) OpenMMLab. All rights reserved. from mmcv.cnn import CONV_LAYERS from torch import nn CONV_LAYERS.register_module('Deconv', module=nn.ConvTranspose2d) # TODO: octave conv
188
26
64
py
AdaInt
AdaInt-main/mmedit/models/common/gca_module.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn from mmcv.cnn import ConvModule, constant_init, xavier_init from torch.nn import functional as F class GCAModule(nn.Module): """Guided Contextual Attention Module. From https://arxiv.org/pdf/2001.04069.pdf. Based on https:...
14,808
40.250696
79
py
AdaInt
AdaInt-main/mmedit/models/common/generation_model_utils.py
# Copyright (c) OpenMMLab. All rights reserved. import numpy as np import torch import torch.nn as nn from mmcv.cnn import ConvModule, kaiming_init, normal_init, xavier_init from torch.nn import init def generation_init_weights(module, init_type='normal', init_gain=0.02): """Default initialization of network weig...
10,699
34.430464
78
py
AdaInt
AdaInt-main/mmedit/models/common/upsample.py
# Copyright (c) OpenMMLab. All rights reserved. import torch.nn as nn import torch.nn.functional as F from .sr_backbone_utils import default_init_weights class PixelShufflePack(nn.Module): """ Pixel Shuffle upsample layer. Args: in_channels (int): Number of input channels. out_channels (int)...
1,517
28.192308
76
py
AdaInt
AdaInt-main/mmedit/models/common/img_normalize.py
# Copyright (c) OpenMMLab. All rights reserved. import torch import torch.nn as nn class ImgNormalize(nn.Conv2d): """Normalize images with the given mean and std value. Based on Conv2d layer, can work in GPU. Args: pixel_range (float): Pixel range of feature. img_mean (Tuple[float]): Ima...
1,063
31.242424
68
py
AdaInt
AdaInt-main/mmedit/models/common/mask_conv_module.py
# Copyright (c) OpenMMLab. All rights reserved. from mmcv.cnn import ConvModule class MaskConvModule(ConvModule): """Mask convolution module. This is a simple wrapper for mask convolution like: 'partial conv'. Convolutions in this module always need a mask as extra input. Args: in_channels (...
3,649
40.011236
78
py
AdaInt
AdaInt-main/mmedit/models/common/partial_conv.py
# Copyright (c) OpenMMLab. All rights reserved. import numpy as np import torch import torch.nn as nn import torch.nn.functional as F from mmcv.cnn import CONV_LAYERS @CONV_LAYERS.register_module(name='PConv') class PartialConv2d(nn.Conv2d): """Implementation for partial convolution. Image Inpainting for Irr...
3,609
34.048544
79
py
AdaInt
AdaInt-main/mmedit/models/inpaintors/two_stage.py
# Copyright (c) OpenMMLab. All rights reserved. import os.path as osp from pathlib import Path import mmcv import torch from torchvision.utils import save_image from mmedit.core import tensor2img from ..common.model_utils import set_requires_grad from ..registry import MODELS from .one_stage import OneStageInpaintor ...
14,418
39.052778
79
py
AdaInt
AdaInt-main/mmedit/models/inpaintors/one_stage.py
# Copyright (c) OpenMMLab. All rights reserved. import os.path as osp from pathlib import Path import mmcv import torch from mmcv.runner import auto_fp16 from torchvision.utils import save_image from mmedit.core import L1Evaluation, psnr, ssim, tensor2img from ..base import BaseModel from ..builder import build_backb...
16,856
36.795964
79
py
AdaInt
AdaInt-main/mmedit/models/inpaintors/pconv_inpaintor.py
# Copyright (c) OpenMMLab. All rights reserved. import os.path as osp from pathlib import Path import mmcv import torch from mmedit.core import tensor2img from ..registry import MODELS from .one_stage import OneStageInpaintor @MODELS.register_module() class PConvInpaintor(OneStageInpaintor): def forward_test(s...
5,306
35.349315
79
py
AdaInt
AdaInt-main/mmedit/models/inpaintors/gl_inpaintor.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from ..common import extract_around_bbox, extract_bbox_patch, set_requires_grad from ..registry import MODELS from .one_stage import OneStageInpaintor @MODELS.register_module() class GLInpaintor(OneStageInpaintor): """Inpaintor for global&local method....
9,507
37.650407
79
py
AdaInt
AdaInt-main/mmedit/models/inpaintors/deepfillv1.py
# Copyright (c) OpenMMLab. All rights reserved. import torch from torch.nn.parallel import DataParallel, DistributedDataParallel from ..common import extract_around_bbox, extract_bbox_patch, set_requires_grad from ..registry import MODELS from .two_stage import TwoStageInpaintor @MODELS.register_module() class DeepF...
12,647
39.8
79
py
AdaInt
AdaInt-main/mmedit/models/components/stylegan2/generator_discriminator.py
# Copyright (c) OpenMMLab. All rights reserved. import random import mmcv import numpy as np import torch import torch.nn as nn from mmcv.runner.checkpoint import _load_checkpoint_with_prefix from mmedit.models.registry import COMPONENTS from .common import get_mean_latent, get_module_device, style_mixing from .modul...
21,897
39.402214
167
py
AdaInt
AdaInt-main/mmedit/models/components/stylegan2/modules.py
# Copyright (c) OpenMMLab. All rights reserved. import math from copy import deepcopy from functools import partial import mmcv import torch import torch.nn as nn import torch.nn.functional as F from mmcv.cnn import ConvModule from mmcv.cnn.bricks.activation import build_activation_layer from mmcv.cnn.utils import nor...
32,421
33.236536
89
py
AdaInt
AdaInt-main/mmedit/models/components/stylegan2/common.py
# Copyright (c) OpenMMLab. All rights reserved. import torch def get_module_device(module): """Get the device of a module. Args: module (nn.Module): A module contains the parameters. Returns: torch.device: The device of the module. """ try: next(module.parameters()) e...
2,847
28.061224
78
py