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 |
|---|---|---|---|---|---|---|
s2am | s2am-master/scripts/utils/pytorch_ssim/__init__.py | import torch
import torch.nn.functional as F
from torch.autograd import Variable
import numpy as np
from math import exp
def gaussian(window_size, sigma):
gauss = torch.Tensor([exp(-(x - window_size//2)**2/float(2*sigma**2)) for x in range(window_size)])
return gauss/gauss.sum()
def create_window(window_size,... | 2,635 | 34.621622 | 104 | py |
CodeBERT | CodeBERT-master/CodeExecutor/pretrain/model.py | import torch
import torch.nn as nn
import torch
from torch.autograd import Variable
import copy
import torch.nn.functional as F
from torch.nn import CrossEntropyLoss, MSELoss
import random
class Model(nn.Module):
def __init__(self, encoder,config,tokenizer,args):
super(Model, self).__init__()
... | 2,158 | 39.735849 | 135 | py |
CodeBERT | CodeBERT-master/CodeExecutor/pretrain/dataset.py | import random
import torch
from torch.utils.data import Dataset
import os
import pickle
import logging
import json
from tqdm import tqdm
def _truncate_seq_pair(tokens_a, tokens_b, max_length):
"""Truncates a sequence pair in place to the maximum length."""
while True:
total_length = len(tokens_a) + le... | 6,292 | 42.10274 | 193 | py |
CodeBERT | CodeBERT-master/CodeExecutor/pretrain/run.py | # coding=utf-8
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a cop... | 20,300 | 46.432243 | 218 | py |
CodeBERT | CodeBERT-master/CodeExecutor/downstream/run.py | # coding=utf-8
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a cop... | 12,985 | 36.531792 | 138 | py |
CodeBERT | CodeBERT-master/CodeExecutor/downstream/model_unixcoder.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import torch.nn as nn
import torch
class Model(nn.Module):
def __init__(self, encoder):
super(Model, self).__init__()
self.encoder = encoder
def forward(self, code_inputs=None, nl_inputs=None, cls=False):
... | 888 | 41.333333 | 101 | py |
CodeBERT | CodeBERT-master/CodeExecutor/inference/model.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import torch
import torch.nn as nn
import torch
from torch.autograd import Variable
import copy
class Seq2Seq(nn.Module):
"""
Build Seqence-to-Sequence.
Parameters:
* `encoder`- encoder of seq2seq model. e.g... | 8,350 | 38.023364 | 123 | py |
CodeBERT | CodeBERT-master/CodeExecutor/inference/dataset.py | import random
import torch
from torch.utils.data import Dataset
import os
import pickle
import logging
import json
from tqdm import tqdm
def _truncate_seq_pair(tokens_a, tokens_b, max_length):
"""Truncates a sequence pair in place to the maximum length."""
while True:
total_length = len(tokens_a) + le... | 6,641 | 42.697368 | 193 | py |
CodeBERT | CodeBERT-master/CodeExecutor/inference/run.py | # coding=utf-8
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a cop... | 13,398 | 45.044674 | 128 | py |
CodeBERT | CodeBERT-master/GraphCodeBERT/codesearch/model.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import torch.nn as nn
import torch
class Model(nn.Module):
def __init__(self, encoder):
super(Model, self).__init__()
self.encoder = encoder
def forward(self, code_inputs=None, attn_mask=None,position_idx=None... | 1,168 | 43.961538 | 118 | py |
CodeBERT | CodeBERT-master/GraphCodeBERT/codesearch/run.py | # coding=utf-8
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a cop... | 21,132 | 40.275391 | 141 | py |
CodeBERT | CodeBERT-master/GraphCodeBERT/clonedetection/model.py | import torch
import torch.nn as nn
import torch
from torch.autograd import Variable
import copy
import torch.nn.functional as F
from torch.nn import CrossEntropyLoss, MSELoss
class RobertaClassificationHead(nn.Module):
"""Head for sentence-level classification tasks."""
def __init__(self, config):
sup... | 2,668 | 38.835821 | 167 | py |
CodeBERT | CodeBERT-master/GraphCodeBERT/clonedetection/run.py | # coding=utf-8
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a cop... | 26,923 | 42.009585 | 135 | py |
CodeBERT | CodeBERT-master/GraphCodeBERT/refinement/model.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import torch
import torch.nn as nn
import torch
from torch.autograd import Variable
import copy
class Seq2Seq(nn.Module):
"""
Build Seqence-to-Sequence.
Parameters:
* `encoder`- encoder of seq2seq model. e.g... | 9,668 | 41.03913 | 129 | py |
CodeBERT | CodeBERT-master/GraphCodeBERT/refinement/run.py | # coding=utf-8
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a cop... | 29,129 | 46.675941 | 191 | py |
CodeBERT | CodeBERT-master/GraphCodeBERT/translation/model.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import torch
import torch.nn as nn
import torch
from torch.autograd import Variable
import copy
class Seq2Seq(nn.Module):
"""
Build Seqence-to-Sequence.
Parameters:
* `encoder`- encoder of seq2seq model. e.g... | 9,668 | 41.03913 | 129 | py |
CodeBERT | CodeBERT-master/GraphCodeBERT/translation/run.py | # coding=utf-8
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a cop... | 29,854 | 46.313788 | 191 | py |
CodeBERT | CodeBERT-master/CodeReviewer/code/run_finetune_ref.py | import os
import torch
import logging
import argparse
import random
import json
from tqdm import tqdm
import multiprocessing
import time
from itertools import cycle
from torch.utils.data import DataLoader, RandomSampler, SequentialSampler
from torch.utils.data import ConcatDataset
from torch.utils.data.distributed impo... | 11,242 | 39.297491 | 130 | py |
CodeBERT | CodeBERT-master/CodeReviewer/code/run_infer_msg.py | import os, json
import torch
import logging
import argparse
import random
import numpy as np
from tqdm import tqdm
import multiprocessing
import time
from itertools import cycle
from torch.utils.data import DataLoader, SequentialSampler, RandomSampler
from torch.utils.data.distributed import DistributedSampler
from tra... | 5,132 | 39.738095 | 129 | py |
CodeBERT | CodeBERT-master/CodeReviewer/code/run_test_msg.py | import os, json
import torch
import logging
import argparse
import random
import numpy as np
from tqdm import tqdm
import multiprocessing
import time
from itertools import cycle
from torch.utils.data import DataLoader, SequentialSampler, RandomSampler
from torch.utils.data.distributed import DistributedSampler
from tra... | 4,792 | 39.965812 | 129 | py |
CodeBERT | CodeBERT-master/CodeReviewer/code/utils.py | import re, json
import os, random
import torch, logging
from copy import deepcopy as cp
from torch.utils.data import Dataset
from tokenizers import ByteLevelBPETokenizer
from transformers import T5Tokenizer, RobertaTokenizer
import nltk
logging.basicConfig(
format="%(asctime)s - %(levelname)s - %(name)s - %(mess... | 33,175 | 39.311057 | 122 | py |
CodeBERT | CodeBERT-master/CodeReviewer/code/run_finetune_cls.py | import os
import torch
import logging
import argparse
import random
import numpy as np
from tqdm import tqdm
import multiprocessing
import time
from itertools import cycle
from torch.utils.data import DataLoader, RandomSampler, SequentialSampler
from torch.utils.data import ConcatDataset
from torch.utils.data.distribut... | 10,933 | 39.198529 | 140 | py |
CodeBERT | CodeBERT-master/CodeReviewer/code/run_test_ref.py | import os, json
import torch
import logging
import argparse
import random
import numpy as np
from tqdm import tqdm
import multiprocessing
import time
from itertools import cycle
from torch.utils.data import DataLoader, SequentialSampler, RandomSampler
from torch.utils.data.distributed import DistributedSampler
from tra... | 5,062 | 39.18254 | 129 | py |
CodeBERT | CodeBERT-master/CodeReviewer/code/models.py | import os
import torch.nn as nn
import torch
import torch.nn.functional as F
from torch.nn import CrossEntropyLoss, BCEWithLogitsLoss
import numpy as np
from utils import MyTokenizer
from transformers import (
RobertaConfig,
RobertaModel,
RobertaTokenizer,
BartConfig,
BartForConditionalGeneration,
... | 8,221 | 38.339713 | 151 | py |
CodeBERT | CodeBERT-master/CodeReviewer/code/run_test_cls.py | import os
import torch
import logging
import argparse
import random
import numpy as np
from tqdm import tqdm
import multiprocessing
import time
from itertools import cycle
from torch.utils.data import DataLoader, SequentialSampler, RandomSampler
from torch.utils.data.distributed import DistributedSampler
from transform... | 4,248 | 37.981651 | 129 | py |
CodeBERT | CodeBERT-master/CodeReviewer/code/test_model.py | import argparse
import torch
from configs import add_args
from models import ReviewerModel, build_or_load_gen_model
MAX_SOURCE_LENGTH=512
def pad_assert(tokenizer, source_ids):
source_ids = source_ids[:MAX_SOURCE_LENGTH - 2]
source_ids = [tokenizer.bos_id] + source_ids + [tokenizer.eos_id]
pad_len = MAX_S... | 2,421 | 39.366667 | 281 | py |
CodeBERT | CodeBERT-master/CodeReviewer/code/run_finetune_msg.py | import os
import torch
import logging
import argparse
import random
import json
from tqdm import tqdm
import multiprocessing
import time
from itertools import cycle
from torch.utils.data import DataLoader, RandomSampler, SequentialSampler
from torch.utils.data import ConcatDataset
from torch.utils.data.distributed impo... | 11,631 | 40.841727 | 140 | py |
CodeBERT | CodeBERT-master/CodeReviewer/code/configs.py | import random
import torch
import logging
import multiprocessing
import numpy as np
logger = logging.getLogger(__name__)
def add_args(parser):
parser.add_argument(
"--task",
type=str,
required=False,
choices=[
"review",
],
)
parser.add_argument(
... | 7,379 | 29.75 | 106 | py |
CodeBERT | CodeBERT-master/LongCoder/model.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import torch
import torch.nn as nn
import torch
from torch.autograd import Variable
import copy
class Seq2Seq(nn.Module):
"""
Build Seqence-to-Sequence.
Parameters:
* `encoder`- encoder of seq2seq model. e.g... | 9,111 | 40.045045 | 211 | py |
CodeBERT | CodeBERT-master/LongCoder/run.py | # coding=utf-8
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a cop... | 17,159 | 39.471698 | 177 | py |
CodeBERT | CodeBERT-master/LongCoder/longcoder.py | # coding=utf-8
# Copyright 2020 The Allen Institute for AI team and The HuggingFace Inc. team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2... | 81,922 | 48.321493 | 214 | py |
CodeBERT | CodeBERT-master/UniXcoder/unixcoder.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import torch
import torch.nn as nn
from transformers import RobertaTokenizer, RobertaModel, RobertaConfig
class UniXcoder(nn.Module):
def __init__(self, model_name):
"""
Build UniXcoder.
Parameters:
... | 10,352 | 39.6 | 120 | py |
CodeBERT | CodeBERT-master/UniXcoder/downstream-tasks/code-completion/model.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import torch
import torch.nn as nn
import torch
from torch.autograd import Variable
import copy
class Seq2Seq(nn.Module):
"""
Build Seqence-to-Sequence.
Parameters:
* `encoder`- encoder of seq2seq model. e.g... | 8,935 | 39.071749 | 117 | py |
CodeBERT | CodeBERT-master/UniXcoder/downstream-tasks/code-completion/run.py | # coding=utf-8
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a cop... | 22,612 | 44.961382 | 140 | py |
CodeBERT | CodeBERT-master/UniXcoder/downstream-tasks/code-generation/model.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import torch
import torch.nn as nn
import torch
from torch.autograd import Variable
import copy
class Seq2Seq(nn.Module):
"""
Build Seqence-to-Sequence.
Parameters:
* `encoder`- encoder of seq2seq model. e.g... | 8,350 | 38.023364 | 123 | py |
CodeBERT | CodeBERT-master/UniXcoder/downstream-tasks/code-generation/run.py | # coding=utf-8
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a cop... | 19,957 | 46.519048 | 142 | py |
CodeBERT | CodeBERT-master/UniXcoder/downstream-tasks/code-search/model.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import torch.nn as nn
import torch
class Model(nn.Module):
def __init__(self, encoder):
super(Model, self).__init__()
self.encoder = encoder
def forward(self, code_inputs=None, nl_inputs=None):
if cod... | 869 | 40.428571 | 100 | py |
CodeBERT | CodeBERT-master/UniXcoder/downstream-tasks/code-search/run.py | # coding=utf-8
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a cop... | 16,275 | 41.165803 | 148 | py |
CodeBERT | CodeBERT-master/UniXcoder/downstream-tasks/zero-shot-search/model.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import torch.nn as nn
import torch
class Model(nn.Module):
def __init__(self, encoder):
super(Model, self).__init__()
self.encoder = encoder
def forward(self, code_inputs=None, nl_inputs=None, cls=False):
... | 889 | 39.454545 | 101 | py |
CodeBERT | CodeBERT-master/UniXcoder/downstream-tasks/zero-shot-search/run.py | # coding=utf-8
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a cop... | 11,207 | 36.23588 | 135 | py |
CodeBERT | CodeBERT-master/UniXcoder/downstream-tasks/code-summarization/model.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import torch
import torch.nn as nn
import torch
from torch.autograd import Variable
import copy
class Seq2Seq(nn.Module):
"""
Build Seqence-to-Sequence.
Parameters:
* `encoder`- encoder of seq2seq model. e.g... | 8,350 | 38.023364 | 123 | py |
CodeBERT | CodeBERT-master/UniXcoder/downstream-tasks/code-summarization/run.py | # coding=utf-8
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a cop... | 20,589 | 46.995338 | 142 | py |
CodeBERT | CodeBERT-master/UniXcoder/downstream-tasks/clone-detection/BCB/model.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import torch
import torch.nn as nn
import torch
from torch.autograd import Variable
import copy
import torch.nn.functional as F
from torch.nn import CrossEntropyLoss, MSELoss
class RobertaClassificationHead(nn.Module):
"""Head for sentence-l... | 1,775 | 29.62069 | 93 | py |
CodeBERT | CodeBERT-master/UniXcoder/downstream-tasks/clone-detection/BCB/run.py | # coding=utf-8
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a cop... | 15,992 | 40.866492 | 118 | py |
CodeBERT | CodeBERT-master/UniXcoder/downstream-tasks/clone-detection/POJ-104/model.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import torch
import torch.nn as nn
import torch
from torch.autograd import Variable
import copy
import torch.nn.functional as F
from torch.nn import CrossEntropyLoss, MSELoss
class Model(nn.Module):
def __init__(self, encoder,config,... | 1,566 | 32.340426 | 93 | py |
CodeBERT | CodeBERT-master/UniXcoder/downstream-tasks/clone-detection/POJ-104/run.py | # coding=utf-8
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a cop... | 14,995 | 40.655556 | 116 | py |
CodeBERT | CodeBERT-master/CodeBERT/codesearch/run_classifier.py | # coding=utf-8
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a cop... | 30,834 | 50.649916 | 151 | py |
CodeBERT | CodeBERT-master/CodeBERT/code2nl/model.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import torch
import torch.nn as nn
import torch
from torch.autograd import Variable
import copy
class Seq2Seq(nn.Module):
"""
Build Seqence-to-Sequence.
Parameters:
* `encoder`- encoder of seq2seq model. e.g... | 9,011 | 39.963636 | 129 | py |
CodeBERT | CodeBERT-master/CodeBERT/code2nl/run.py | # coding=utf-8
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a cop... | 26,349 | 49 | 175 | py |
DFGC-2022-1st-place | DFGC-2022-1st-place-main/predict_swin.py | """
Author: HanChen
Date: 21.06.2022
"""
# -*- coding: utf-8 -*-
import torch
import torch.nn as nn
import torch.optim as optim
from torch.autograd import Variable
import random
import argparse
import json
import numpy as np
import pandas as pd
import torchvision.models as models
from transforms import build_transfor... | 4,178 | 35.025862 | 113 | py |
DFGC-2022-1st-place | DFGC-2022-1st-place-main/data_utils.py | """
Some codes borrowed from https://github.com/jphdotam/DFDC/blob/master/cnn3d/training/datasets_video.py
Extract images from videos in Celeb-DF v2
Author: HanChen
Date: 13.10.2020
"""
import cv2
import math
import json
import random
import glob
import numpy as np
from tqdm import tqdm
from PIL import Image
from col... | 6,437 | 33.427807 | 110 | py |
DFGC-2022-1st-place | DFGC-2022-1st-place-main/train_swin.py | """
Author: HanChen
Date: 21.06.2022
"""
# -*- coding: utf-8 -*-
import torch
import torch.optim as optim
from torch.autograd import Variable
import argparse
import json
import random
import numpy as np
import pandas as pd
from tqdm import tqdm
import time
from logger import create_logger
from network.models import g... | 7,783 | 40.404255 | 117 | py |
DFGC-2022-1st-place | DFGC-2022-1st-place-main/train_convnext.py | """
Author: HanChen
Date: 21.06.2022
"""
# -*- coding: utf-8 -*-
import torch
import torch.optim as optim
from torch.autograd import Variable
import argparse
import json
import random
import numpy as np
import pandas as pd
from tqdm import tqdm
import torch.nn as nn
import time
from logger import create_logger
from n... | 7,798 | 40.047368 | 117 | py |
DFGC-2022-1st-place | DFGC-2022-1st-place-main/transforms.py | from torchvision import transforms
import albumentations as A
from albumentations.pytorch import ToTensorV2
def build_transforms(height, width, max_pixel_value=255.0, norm_mean=[0.485, 0.456, 0.406],
norm_std=[0.229, 0.224, 0.225], **kwargs):
"""Builds train and test transform functions.
... | 1,437 | 30.26087 | 97 | py |
DFGC-2022-1st-place | DFGC-2022-1st-place-main/predict_convnext.py | """
Author: HanChen
Date: 21.06.2022
"""
# -*- coding: utf-8 -*-
import torch
import torch.nn as nn
import torch.optim as optim
from torch.autograd import Variable
import random
import argparse
import json
import numpy as np
import pandas as pd
import torchvision.models as models
from transforms import build_transfor... | 4,221 | 35.08547 | 126 | py |
DFGC-2022-1st-place | DFGC-2022-1st-place-main/extract_video_mtcnn.py | """
Author: HanChen
Date: 21.06.2022
"""
import torch
from tqdm import tqdm
from facenet_pytorch import MTCNN
from PIL import Image
import numpy as np
from collections import OrderedDict
import cv2
import argparse
import os
def extract_video(input_dir, model, scale=1.3):
reader = cv2.VideoCapture(input_dir)
... | 4,983 | 35.918519 | 127 | py |
DFGC-2022-1st-place | DFGC-2022-1st-place-main/network/models.py | import torch
import torch.nn as nn
from torch.nn import init
import torchvision
from efficientnet_pytorch import EfficientNet
import timm
from pytorch_pretrained_vit import ViT
# fc layer weight init
def weights_init_kaiming(m):
classname = m.__class__.__name__
# print(classname)
if classname.find('Conv')... | 9,502 | 40.679825 | 128 | py |
WordArt | WordArt-main/tools/test.py | #!/usr/bin/env python
# Copyright (c) OpenMMLab. All rights reserved.
import argparse
import os
import warnings
import mmcv
import torch
from mmcv import Config, DictAction
from mmcv.cnn import fuse_conv_bn
from mmcv.parallel import MMDataParallel, MMDistributedDataParallel
from mmcv.runner import (get_dist_info, init... | 9,085 | 37.5 | 79 | py |
WordArt | WordArt-main/tools/kie_test_imgs.py | #!/usr/bin/env python
# Copyright (c) OpenMMLab. All rights reserved.
import argparse
import ast
import os
import os.path as osp
import mmcv
import numpy as np
import torch
from mmcv import Config
from mmcv.image import tensor2imgs
from mmcv.parallel import MMDataParallel
from mmcv.runner import load_checkpoint
from ... | 5,414 | 32.425926 | 78 | py |
WordArt | WordArt-main/tools/publish_model.py | #!/usr/bin/env python
# Copyright (c) OpenMMLab. All rights reserved.
import argparse
import subprocess
import torch
def parse_args():
parser = argparse.ArgumentParser(
description='Process a checkpoint to be published')
parser.add_argument('in_file', help='input checkpoint filename')
parser.add_... | 1,209 | 29.25 | 77 | py |
WordArt | WordArt-main/tools/train.py | #!/usr/bin/env python
# Copyright (c) OpenMMLab. All rights reserved.
import argparse
import copy
import os
import os.path as osp
import time
import warnings
import mmcv
import torch
import torch.distributed as dist
from mmcv import Config, DictAction
from mmcv.runner import get_dist_info, init_dist, set_random_seed
f... | 8,725 | 36.774892 | 79 | py |
WordArt | WordArt-main/tools/deployment/onnx2tensorrt.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import os
import os.path as osp
import warnings
from typing import Iterable
import cv2
import mmcv
import numpy as np
import torch
from mmcv.parallel import collate
from mmcv.tensorrt import is_tensorrt_plugin_loaded, onnx2trt, save_trt_engine
from mmdet.... | 10,163 | 33.454237 | 79 | py |
WordArt | WordArt-main/tools/deployment/mmocr_handler.py | # Copyright (c) OpenMMLab. All rights reserved.
import base64
import os
import mmcv
import torch
from ts.torch_handler.base_handler import BaseHandler
from mmocr.apis import init_detector, model_inference
from mmocr.datasets.pipelines import * # NOQA
class MMOCRHandler(BaseHandler):
threshold = 0.5
def in... | 1,640 | 30.557692 | 79 | py |
WordArt | WordArt-main/tools/deployment/pytorch2onnx.py | # Copyright (c) OpenMMLab. All rights reserved.
import warnings
from argparse import ArgumentParser
from functools import partial
import cv2
import numpy as np
import torch
from mmcv.onnx import register_extra_symbolics
from mmcv.parallel import collate
from mmdet.datasets import replace_ImageToTensor
from mmdet.datas... | 13,045 | 34.355014 | 79 | py |
WordArt | WordArt-main/tools/deployment/mmocr2torchserve.py | # Copyright (c) OpenMMLab. All rights reserved.
from argparse import ArgumentParser, Namespace
from pathlib import Path
from tempfile import TemporaryDirectory
import mmcv
try:
from model_archiver.model_packaging import package_model
from model_archiver.model_packaging_utils import ModelExportUtils
except Imp... | 3,669 | 32.063063 | 76 | py |
WordArt | WordArt-main/tests/test_models/test_ocr_neck.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmocr.models.textrecog.necks import FPNOCR
def test_fpn_ocr():
in_s1 = torch.rand(1, 128, 32, 256)
in_s2 = torch.rand(1, 256, 16, 128)
in_s3 = torch.rand(1, 512, 8, 64)
in_s4 = torch.rand(1, 512, 4, 32)
fpn_ocr = FPNOCR(in_channel... | 525 | 26.684211 | 72 | py |
WordArt | WordArt-main/tests/test_models/test_ocr_fuser.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmocr.models.textrecog.fusers import ABIFuser
def test_base_alignment():
model = ABIFuser(d_model=512, num_chars=90, max_seq_len=40)
l_feat = torch.randn(1, 40, 512)
v_feat = torch.randn(1, 40, 512)
result = model(l_feat, v_feat)
a... | 376 | 28 | 63 | py |
WordArt | WordArt-main/tests/test_models/test_ocr_preprocessor.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmocr.models.textrecog.preprocessor import (BasePreprocessor,
TPSPreprocessor)
def test_tps_preprocessor():
with pytest.raises(AssertionError):
TPSPreprocessor(num_fiducial=-1)... | 1,212 | 29.325 | 66 | py |
WordArt | WordArt-main/tests/test_models/test_ocr_decoder.py | # Copyright (c) OpenMMLab. All rights reserved.
import math
import pytest
import torch
from mmocr.models.textrecog.decoders import (ABILanguageDecoder,
ABIVisionDecoder, BaseDecoder,
MasterDecoder, NRTRDecoder,
... | 5,384 | 34.427632 | 79 | py |
WordArt | WordArt-main/tests/test_models/test_recog_config.py | # Copyright (c) OpenMMLab. All rights reserved.
import copy
from os.path import dirname, exists, join
import numpy as np
import pytest
import torch
def _demo_mm_inputs(num_kernels=0, input_shape=(1, 3, 300, 300),
num_items=None): # yapf: disable
"""Create a superset of inputs needed to run t... | 4,883 | 29.911392 | 78 | py |
WordArt | WordArt-main/tests/test_models/test_loss.py | # Copyright (c) OpenMMLab. All rights reserved.
import numpy as np
import torch
from mmdet.core import BitmapMasks
import mmocr.models.textdet.losses as losses
def test_panloss():
panloss = losses.PANLoss()
# test bitmasks2tensor
mask = [[1, 0, 1], [1, 1, 1], [0, 0, 1]]
target = [[1, 0, 1, 0, 0], [1... | 5,976 | 36.35625 | 78 | py |
WordArt | WordArt-main/tests/test_models/test_ocr_backbone.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmocr.models.textrecog.backbones import (ResNet, ResNet31OCR, ResNetABI,
ShallowCNN, VeryDeepVgg)
def test_resnet31_ocr_backbone():
"""Test resnet backbone."""
with pytest.raises(Asse... | 4,837 | 29.427673 | 78 | py |
WordArt | WordArt-main/tests/test_models/test_ocr_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmocr.models.textrecog import SegHead
def test_seg_head():
with pytest.raises(AssertionError):
SegHead(num_classes='100')
with pytest.raises(AssertionError):
SegHead(num_classes=-1)
seg_head = SegHead(num_cla... | 466 | 24.944444 | 56 | py |
WordArt | WordArt-main/tests/test_models/test_modules.py | # Copyright (c) OpenMMLab. All rights reserved.
import numpy as np
import torch
from mmocr.models.textdet.modules import GCN, LocalGraphs, ProposalLocalGraphs
from mmocr.models.textdet.modules.utils import (feature_embedding,
normalize_adjacent_matrix)
def test_local_g... | 5,158 | 37.5 | 79 | py |
WordArt | WordArt-main/tests/test_models/test_ner_model.py | # Copyright (c) OpenMMLab. All rights reserved.
import copy
import os.path as osp
import tempfile
import pytest
import torch
from mmocr.models import build_detector
def _create_dummy_vocab_file(vocab_file):
with open(vocab_file, 'w') as fw:
for char in list(map(chr, range(ord('a'), ord('z') + 1))):
... | 2,207 | 26.949367 | 78 | py |
WordArt | WordArt-main/tests/test_models/test_textdet_neck.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmocr.models.textdet.necks import FPNC, FPN_UNet
def test_fpnc():
in_channels = [64, 128, 256, 512]
size = [112, 56, 28, 14]
asf_cfgs = [
None,
dict(attention_type='ScaleChannelSpatial'),
]
for flag i... | 1,649 | 27.448276 | 74 | py |
WordArt | WordArt-main/tests/test_models/test_recognizer.py | # Copyright (c) OpenMMLab. All rights reserved.
import os.path as osp
import tempfile
from functools import partial
import numpy as np
import pytest
import torch
from mmdet.core import BitmapMasks
from mmocr.models.textrecog.recognizer import (EncodeDecodeRecognizer,
Seg... | 5,845 | 29.290155 | 79 | py |
WordArt | WordArt-main/tests/test_models/test_ocr_encoder.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmocr.models.textrecog.encoders import (ABIVisionModel, BaseEncoder,
NRTREncoder, SAREncoder,
SatrnEncoder, TransformerEncoder)
def test_sar_encode... | 2,378 | 28.012195 | 79 | py |
WordArt | WordArt-main/tests/test_models/test_kie_config.py | # Copyright (c) OpenMMLab. All rights reserved.
import copy
from os.path import dirname, exists, join
import numpy as np
import pytest
import torch
def _demo_mm_inputs(num_kernels=0, input_shape=(1, 3, 300, 300),
num_items=None): # yapf: disable
"""Create a superset of inputs needed to run t... | 3,896 | 28.522727 | 78 | py |
WordArt | WordArt-main/tests/test_models/test_ocr_loss.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmocr.models.common.losses import DiceLoss
from mmocr.models.textrecog.losses import (ABILoss, CELoss, CTCLoss, SARLoss,
TFLoss)
def test_ctc_loss():
with pytest.raises(AssertionError):
... | 4,198 | 30.335821 | 77 | py |
WordArt | WordArt-main/tests/test_models/test_detector.py | # Copyright (c) OpenMMLab. All rights reserved.
"""pytest tests/test_detector.py."""
import copy
import tempfile
from functools import partial
from os.path import dirname, exists, join
import numpy as np
import pytest
import torch
from mmocr.utils import revert_sync_batchnorm
def _demo_mm_inputs(num_kernels=0, inpu... | 16,927 | 31.679537 | 78 | py |
WordArt | WordArt-main/tests/test_models/test_textdet_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import numpy as np
import torch
from mmocr.models.textdet.dense_heads import DRRGHead
def test_drrg_head():
in_channels = 10
drrg_head = DRRGHead(in_channels)
assert drrg_head.in_channels == in_channels
assert drrg_head.k_at_hops == (8, 4)
assert dr... | 3,291 | 38.662651 | 77 | py |
WordArt | WordArt-main/tests/test_models/test_ocr_layer.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from mmocr.models.common import (PositionalEncoding, TFDecoderLayer,
TFEncoderLayer)
from mmocr.models.textrecog.layers import BasicBlock, Bottleneck
from mmocr.models.textrecog.layers.conv_layer import conv3x3
def test_con... | 1,940 | 29.328125 | 76 | py |
WordArt | WordArt-main/tests/test_models/test_label_convertor/test_ctc_label_convertor.py | # Copyright (c) OpenMMLab. All rights reserved.
import os.path as osp
import tempfile
import numpy as np
import pytest
import torch
from mmocr.models.textrecog.convertors import CTCConvertor
def _create_dummy_dict_file(dict_file):
chars = list('helowrd')
with open(dict_file, 'w') as fw:
for char in ... | 2,591 | 34.027027 | 79 | py |
WordArt | WordArt-main/tests/test_models/test_label_convertor/test_attn_label_convertor.py | # Copyright (c) OpenMMLab. All rights reserved.
import os.path as osp
import tempfile
import numpy as np
import pytest
import torch
from mmocr.models.textrecog.convertors import ABIConvertor, AttnConvertor
def _create_dummy_dict_file(dict_file):
characters = list('helowrd')
with open(dict_file, 'w') as fw:
... | 3,990 | 36.650943 | 75 | py |
WordArt | WordArt-main/tests/test_apis/test_single_gpu_test.py | # Copyright (c) OpenMMLab. All rights reserved.
import copy
import json
import os
import os.path as osp
import tempfile
import mmcv
import numpy as np
import pytest
import torch
from mmcv import Config
from mmcv.parallel import MMDataParallel
from mmocr.apis.test import single_gpu_test
from mmocr.datasets import buil... | 7,228 | 34.092233 | 75 | py |
WordArt | WordArt-main/tests/test_apis/test_image_misc.py | # Copyright (c) OpenMMLab. All rights reserved.
import numpy as np
import pytest
import torch
from numpy.testing import assert_array_equal
from mmocr.apis.utils import tensor2grayimgs
@pytest.mark.skipif(not torch.cuda.is_available(), reason='requires cuda')
def test_tensor2grayimgs():
# test tensor obj
wit... | 1,253 | 28.162791 | 74 | py |
WordArt | WordArt-main/tests/test_dataset/test_openset_kie_dataset.py | # Copyright (c) OpenMMLab. All rights reserved.
import json
import math
import os.path as osp
import tempfile
import torch
from mmocr.datasets.openset_kie_dataset import OpensetKIEDataset
from mmocr.utils import list_to_file
def _create_dummy_ann_file(ann_file):
ann_info1 = {
'file_name':
'1.png... | 2,966 | 28.969697 | 77 | py |
WordArt | WordArt-main/tests/test_dataset/test_ner_dataset.py | # Copyright (c) OpenMMLab. All rights reserved.
import json
import os.path as osp
import tempfile
import torch
from mmocr.datasets.ner_dataset import NerDataset
from mmocr.models.ner.convertors.ner_convertor import NerConvertor
from mmocr.utils import list_to_file
def _create_dummy_ann_file(ann_file):
data = {
... | 3,449 | 29 | 79 | py |
WordArt | WordArt-main/tests/test_dataset/test_kie_dataset.py | # Copyright (c) OpenMMLab. All rights reserved.
import json
import math
import os.path as osp
import tempfile
import pytest
import torch
from mmocr.datasets.kie_dataset import KIEDataset
def _create_dummy_ann_file(ann_file):
ann_info1 = {
'file_name':
'sample1.png',
'height':
200... | 3,492 | 26.077519 | 68 | py |
WordArt | WordArt-main/tests/test_dataset/test_ocr_transforms.py | # Copyright (c) OpenMMLab. All rights reserved.
import math
import unittest.mock as mock
import numpy as np
import torch
import torchvision.transforms.functional as TF
from PIL import Image
import mmocr.datasets.pipelines.ocr_transforms as transforms
def test_resize_ocr():
input_img = np.ones((64, 256, 3), dtyp... | 3,819 | 25.901408 | 76 | py |
WordArt | WordArt-main/tests/test_dataset/test_transform_wrappers.py | # Copyright (c) OpenMMLab. All rights reserved.
import copy
import unittest.mock as mock
import numpy as np
import pytest
from mmocr.datasets.pipelines import (OneOfWrapper, RandomWrapper,
TorchVisionWrapper)
from mmocr.datasets.pipelines.transforms import ColorJitter
def test_... | 2,275 | 32.970149 | 78 | py |
WordArt | WordArt-main/tests/test_dataset/test_transforms.py | # Copyright (c) OpenMMLab. All rights reserved.
import copy
import unittest.mock as mock
import numpy as np
import pytest
import torchvision.transforms as TF
from mmdet.core import BitmapMasks, PolygonMasks
from PIL import Image
import mmocr.datasets.pipelines.transforms as transforms
@mock.patch('%s.transforms.np.... | 12,544 | 32.542781 | 79 | py |
WordArt | WordArt-main/tests/test_utils/test_ocr.py | # Copyright (c) OpenMMLab. All rights reserved.
import io
import json
import os
import platform
import random
import sys
import tempfile
from pathlib import Path
from unittest import mock
import mmcv
import numpy as np
import pytest
import torch
from mmocr.apis import init_detector
from mmocr.datasets.kie_dataset imp... | 16,591 | 38.410926 | 79 | py |
WordArt | WordArt-main/tests/test_utils/test_wrapper.py | # Copyright (c) OpenMMLab. All rights reserved.
import numpy as np
import pytest
import torch
from mmocr.models.textdet.postprocess import (DBPostprocessor,
FCEPostprocessor,
TextSnakePostprocessor)
from mmocr.models.textdet.po... | 3,806 | 32.690265 | 77 | py |
WordArt | WordArt-main/tests/test_utils/test_model.py | # Copyright (c) OpenMMLab. All rights reserved.
import pytest
import torch
from mmcv.cnn.bricks import ConvModule
from mmocr.utils import revert_sync_batchnorm
def test_revert_sync_batchnorm():
conv_syncbn = ConvModule(3, 8, 2, norm_cfg=dict(type='SyncBN')).to('cpu')
conv_syncbn.train()
x = torch.randn(1... | 740 | 31.217391 | 77 | py |
WordArt | WordArt-main/tests/test_core/test_deploy_utils.py | # Copyright (c) OpenMMLab. All rights reserved.
import tempfile
from functools import partial
import mmcv
import numpy as np
import pytest
import torch
from packaging import version
from mmocr.core.deployment import (ONNXRuntimeDetector, ONNXRuntimeRecognizer,
TensorRTDetector, Tens... | 7,594 | 32.606195 | 78 | py |
WordArt | WordArt-main/demo/webcam_demo.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import cv2
import torch
from mmocr.apis import init_detector, model_inference
from mmocr.datasets import build_dataset # noqa: F401
from mmocr.models import build_detector # noqa: F401
def parse_args():
parser = argparse.ArgumentParser(descriptio... | 1,417 | 27.36 | 79 | py |
WordArt | WordArt-main/configs/_base_/det_models/dbnet_r18_fpnc.py | model = dict(
type='DBNet',
backbone=dict(
type='mmdet.ResNet',
depth=18,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=-1,
norm_cfg=dict(type='BN', requires_grad=True),
init_cfg=dict(type='Pretrained', checkpoint='torchvision://resnet18'),
... | 709 | 31.272727 | 78 | py |
WordArt | WordArt-main/configs/_base_/det_models/textsnake_r50_fpn_unet.py | model = dict(
type='TextSnake',
backbone=dict(
type='mmdet.ResNet',
depth=50,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=-1,
norm_cfg=dict(type='BN', requires_grad=True),
init_cfg=dict(type='Pretrained', checkpoint='torchvision://resnet50'),
... | 709 | 29.869565 | 78 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.