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 |
|---|---|---|---|---|---|---|
UNITER | UNITER-master/inf_vqa.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
run inference of VQA for submission
"""
import argparse
import json
import os
from os.path import exists
from time import time
import torch
from torch.utils.data import DataLoader
from apex import amp
from horovod import torch as hvd
import num... | 6,692 | 35.774725 | 79 | py |
UNITER | UNITER-master/inf_nlvr2.py | """run inference of NLVR2 (single GPU only)"""
import argparse
import json
import os
from os.path import exists
from time import time
import torch
from torch.utils.data import DataLoader
from apex import amp
from horovod import torch as hvd
from data import (DetectFeatLmdb, TxtTokLmdb,
PrefetchLoade... | 5,465 | 37.765957 | 77 | py |
UNITER | UNITER-master/pretrain_vcr.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
UNITER pre-training
"""
import argparse
from collections import defaultdict
import json
import os
from os.path import exists, join
from time import time
import torch
from torch.utils.data import DataLoader
from torch.nn import functional as F
fr... | 22,741 | 39.538324 | 79 | py |
UNITER | UNITER-master/inf_re.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
run inference of VQA for submission
"""
import argparse
import json
import os
from os.path import exists
from time import time
import torch
from torch.utils.data import DataLoader
from apex import amp
from horovod import torch as hvd
from cytoo... | 7,395 | 35.98 | 99 | py |
UNITER | UNITER-master/inf_itm.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
run inference for Image Text Retrieval
"""
import argparse
import json
import os
from os.path import exists
import pickle
from time import time
import torch
from torch.utils.data import DataLoader
from apex import amp
from horovod import torch ... | 6,413 | 38.109756 | 79 | py |
UNITER | UNITER-master/train_vqa.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
UNITER finetuning for VQA
"""
import argparse
import json
import os
from os.path import abspath, dirname, exists, join
from time import time
import torch
from torch.nn import functional as F
from torch.nn.utils import clip_grad_norm_
from torch.... | 16,988 | 41.261194 | 79 | py |
UNITER | UNITER-master/train_ve.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
UNITER finetuning for SNLI-VE
"""
import argparse
import json
import os
from os.path import exists, join
import pickle
from time import time
import torch
from torch.nn import functional as F
from torch.nn.utils import clip_grad_norm_
from torch.... | 16,875 | 41.724051 | 79 | py |
UNITER | UNITER-master/train_re.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
UNITER finetuning for RE
"""
import argparse
import json
import os
from os.path import exists, join
from time import time
import torch
from torch.nn.utils import clip_grad_norm_
from torch.utils.data import DataLoader
from torch.optim import Ada... | 18,420 | 39.220524 | 79 | py |
UNITER | UNITER-master/train_itm_hard_negatives.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
UNITER finetuning for Image-Text Retrieval with hard negatives
"""
import argparse
import os
from os.path import exists, join
from time import time
import torch
from torch.nn.utils import clip_grad_norm_
from torch.utils.data import DataLoader, ... | 19,146 | 42.417234 | 79 | py |
UNITER | UNITER-master/optim/misc.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
Misc lr helper
"""
from torch.optim import Adam, Adamax
from .adamw import AdamW
def build_optimizer(model, opts):
param_optimizer = list(model.named_parameters())
no_decay = ['bias', 'LayerNorm.bias', 'LayerNorm.weight']
optimizer... | 1,037 | 27.833333 | 65 | py |
UNITER | UNITER-master/optim/adamw.py | """
AdamW optimizer (weight decay fix)
copied from hugginface (https://github.com/huggingface/transformers).
"""
import math
import torch
from torch.optim import Optimizer
class AdamW(Optimizer):
""" Implements Adam algorithm with weight decay fix.
Parameters:
lr (float): learning rate. Default 1e-3.... | 4,450 | 41.798077 | 79 | py |
UNITER | UNITER-master/scripts/convert_ckpt.py | import sys
from collections import OrderedDict
import torch
bert_ckpt, output_ckpt = sys.argv[1:]
bert = torch.load(bert_ckpt)
uniter = OrderedDict()
for k, v in bert.items():
uniter[k.replace('bert', 'uniter')] = v
torch.save(uniter, output_ckpt)
| 256 | 17.357143 | 43 | py |
UNITER | UNITER-master/utils/misc.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
Misc utilities
"""
import json
import random
import sys
import torch
import numpy as np
from utils.logger import LOGGER
class NoOp(object):
""" useful for distributed training No-Ops """
def __getattr__(self, name):
return sel... | 1,507 | 20.239437 | 70 | py |
UNITER | UNITER-master/utils/save.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
saving utilities
"""
import json
import os
from os.path import abspath, dirname, exists, join
import subprocess
import torch
from utils.logger import LOGGER
def save_training_meta(args):
if args.rank > 0:
return
if not exists... | 2,734 | 35.959459 | 73 | py |
UNITER | UNITER-master/utils/itm_eval.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
Image Text Retrieval evaluation helper
"""
from time import time
import torch
from horovod import torch as hvd
from tqdm import tqdm
from .logger import LOGGER
from .misc import NoOp
from .distributed import all_gather_list
@torch.no_grad()
d... | 3,661 | 30.843478 | 72 | py |
UNITER | UNITER-master/utils/distributed.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
distributed API using Horovod
Modified from OpenNMT's native pytorch distributed utils
(https://github.com/OpenNMT/OpenNMT-py)
"""
import math
import pickle
import torch
from horovod import torch as hvd
def all_reduce_and_rescale_tensors(tenso... | 6,296 | 28.985714 | 77 | py |
UNITER | UNITER-master/data/vcr.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
VCR dataset
"""
import copy
import json
import torch
from torch.nn.utils.rnn import pad_sequence
from toolz.sandbox import unzip
from cytoolz import concat
from .data import (DetectFeatTxtTokDataset, TxtTokLmdb, DetectFeatLmdb,
... | 11,643 | 37.556291 | 82 | py |
UNITER | UNITER-master/data/mlm.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
MLM datasets
"""
import random
import torch
from torch.nn.utils.rnn import pad_sequence
from toolz.sandbox import unzip
from .data import (DetectFeatTxtTokDataset, TxtTokLmdb,
pad_tensors, get_gather_index)
def random_word(... | 4,551 | 32.226277 | 79 | py |
UNITER | UNITER-master/data/sampler.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
sampler for length bucketing (batch by tokens)
"""
import math
import random
import horovod.torch as hvd
import torch
from torch.utils.data import Sampler
from cytoolz import partition_all
class TokenBucketSampler(Sampler):
def __init__(se... | 4,199 | 33.42623 | 79 | py |
UNITER | UNITER-master/data/mrm.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
MRM Datasets
"""
import random
import torch
from torch.nn.utils.rnn import pad_sequence
from toolz.sandbox import unzip
from .data import DetectFeatTxtTokDataset, pad_tensors, get_gather_index
def _get_img_mask(mask_prob, num_bb):
img_mask... | 7,228 | 34.965174 | 79 | py |
UNITER | UNITER-master/data/vqa.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
VQA dataset
"""
import torch
from torch.nn.utils.rnn import pad_sequence
from toolz.sandbox import unzip
from .data import DetectFeatTxtTokDataset, pad_tensors, get_gather_index
def _get_vqa_target(example, num_answers):
target = torch.zer... | 4,105 | 31.330709 | 76 | py |
UNITER | UNITER-master/data/data.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
Dataset interfaces
"""
from collections import defaultdict
from contextlib import contextmanager
import io
import json
from os.path import exists
import numpy as np
import torch
from torch.utils.data import Dataset, ConcatDataset
import horovod.... | 10,028 | 31.041534 | 78 | py |
UNITER | UNITER-master/data/pretrain_vcr.py | from .vcr import VcrDetectFeatTxtTokDataset
from .mlm import random_word
import torch
from toolz.sandbox import unzip
from torch.nn.utils.rnn import pad_sequence
from .data import pad_tensors, get_gather_index
from .mrm import (
_get_img_tgt_mask, _get_img_mask, _mask_img_feat,
_get_feat_target, _get_targets)
... | 9,933 | 35.255474 | 77 | py |
UNITER | UNITER-master/data/nlvr2.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
NLVR2 dataset
"""
import copy
import torch
from torch.nn.utils.rnn import pad_sequence
from toolz.sandbox import unzip
from cytoolz import concat
from .data import (DetectFeatTxtTokDataset, TxtTokLmdb, DetectFeatLmdb,
get_ids... | 7,186 | 31.817352 | 76 | py |
UNITER | UNITER-master/data/loader.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
A prefetch loader to speedup data loading
Modified from Nvidia Deep Learning Examples
(https://github.com/NVIDIA/DeepLearningExamples/tree/master/PyTorch).
"""
import random
import torch
from torch.utils.data import DataLoader
from utils.distri... | 4,747 | 32.202797 | 79 | py |
UNITER | UNITER-master/data/re.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
Referring Expression dataset
"""
import random
import numpy as np
import json
import torch
from torch.nn.utils.rnn import pad_sequence
from toolz.sandbox import unzip
from .data import (DetectFeatTxtTokDataset, TxtTokLmdb, DetectFeatLmdb,
... | 10,442 | 35.260417 | 79 | py |
UNITER | UNITER-master/data/itm.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
Itm dataset
"""
from collections import defaultdict
import copy
import random
import torch
from torch.nn.utils.rnn import pad_sequence
from toolz.sandbox import unzip
from cytoolz import concat
import numpy as np
from .data import (DetectFeatTx... | 16,959 | 35.162047 | 79 | py |
UNITER | UNITER-master/model/vcr.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
Uniter for VCR model
"""
from collections import defaultdict
from torch import nn
from torch.nn import functional as F
from apex.normalization.fused_layer_norm import FusedLayerNorm as LayerNorm
# from .layer import GELU
from .model import (
... | 3,024 | 37.782051 | 80 | py |
UNITER | UNITER-master/model/pretrain.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
UNITER for pretraining
"""
from collections import defaultdict
import torch
from torch import nn
from torch.nn import functional as F
from apex.normalization.fused_layer_norm import FusedLayerNorm as LayerNorm
from .layer import GELU, BertOnlyM... | 10,155 | 43.156522 | 78 | py |
UNITER | UNITER-master/model/layer.py | """
BERT layers from the huggingface implementation
(https://github.com/huggingface/transformers)
"""
# 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... | 9,378 | 39.081197 | 104 | py |
UNITER | UNITER-master/model/model.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
Pytorch modules
some classes are modified from HuggingFace
(https://github.com/huggingface/transformers)
"""
import copy
import json
import logging
from io import open
import torch
from torch import nn
from apex.normalization.fused_layer_norm im... | 15,887 | 42.173913 | 79 | py |
UNITER | UNITER-master/model/vqa.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
Uniter for VQA model
"""
from collections import defaultdict
from torch import nn
from torch.nn import functional as F
from apex.normalization.fused_layer_norm import FusedLayerNorm as LayerNorm
from .layer import GELU
from .model import Uniter... | 1,860 | 34.113208 | 75 | py |
UNITER | UNITER-master/model/pretrain_vcr.py | from .pretrain import UniterForPretraining
from torch import nn
from .layer import BertOnlyMLMHead
from collections import defaultdict
from torch.nn import functional as F
import torch
class UniterForPretrainingForVCR(UniterForPretraining):
""" 2nd Stage Pretrain UNITER for VCR
"""
def init_type_embedding... | 7,123 | 46.493333 | 80 | py |
UNITER | UNITER-master/model/nlvr2.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
Uniter for NLVR2 model
"""
from collections import defaultdict
import torch
from torch import nn
from torch.nn import functional as F
from .model import UniterPreTrainedModel, UniterModel
from .attention import MultiheadAttention
class Uniter... | 8,505 | 40.492683 | 76 | py |
UNITER | UNITER-master/model/ot.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
Wasserstein Distance (Optimal Transport)
"""
import torch
from torch.nn import functional as F
def cost_matrix_cosine(x, y, eps=1e-5):
""" Compute cosine distnace across every pairs of x, y (batched)
[B, L_x, D] [B, L_y, D] -> [B, Lx, L... | 2,866 | 32.337209 | 74 | py |
UNITER | UNITER-master/model/attention.py | """
copy multi-head attention code from pytorch
(https://github.com/pytorch/pytorch),
"""
import warnings
import torch
from torch.nn import Module, Parameter, Linear
from torch.nn.init import xavier_normal_, xavier_uniform_, constant_
from torch.nn.functional import linear, softmax, dropout
def multi_head_attention_... | 19,463 | 47.297767 | 130 | py |
UNITER | UNITER-master/model/re.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
Uniter for RE model
"""
from collections import defaultdict
import torch
from torch import nn
import random
import numpy as np
from apex.normalization.fused_layer_norm import FusedLayerNorm as LayerNorm
from .layer import GELU
from .model impor... | 5,705 | 36.051948 | 89 | py |
UNITER | UNITER-master/model/itm.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
UNITER for ITM model
"""
from collections import defaultdict
import torch
from torch import nn
from .model import UniterPreTrainedModel, UniterModel
class UniterForImageTextRetrieval(UniterPreTrainedModel):
""" Finetune UNITER for image te... | 5,619 | 39.142857 | 79 | py |
DenoiseCompression | DenoiseCompression-main/CompressAI/setup.py | # Copyright (c) 2021-2022, InterDigital Communications, Inc
# All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted (subject to the limitations in the disclaimer
# below) provided that the following conditions are met:
# * Redistributions of source cod... | 5,093 | 31.653846 | 96 | py |
DenoiseCompression | DenoiseCompression-main/CompressAI/codes/test.py | import os, glob
import math
import logging
import time
import argparse
from collections import OrderedDict
import json
import torch
import torch.nn.functional as F
import numpy as np
from criterions.criterion import Criterion
import options.options as option
import utils.util as util
import compressai
torch.backends... | 6,949 | 38.714286 | 139 | py |
DenoiseCompression | DenoiseCompression-main/CompressAI/codes/train.py | import os
import math
import argparse
import random
import logging
import torch
import torch.distributed as dist
from torch.utils.data.sampler import Sampler
import options.options as option
from utils import util
from utils.util import (
configure_optimizers, load_optimizer,
configure_schedulers, load_schedu... | 17,639 | 41 | 137 | py |
DenoiseCompression | DenoiseCompression-main/CompressAI/codes/criterions/criterion.py | import math
import torch
import torch.nn as nn
from torch.autograd import Variable
from torchvision import models
import torch.nn.functional as F
class Criterion(nn.Module):
def __init__(self, opt):
super(Criterion, self).__init__()
self.opt = opt
# criterions
self.criterion_metri... | 3,832 | 33.223214 | 113 | py |
DenoiseCompression | DenoiseCompression-main/CompressAI/codes/utils/util.py | import os
import sys
import time
import math
from datetime import datetime
import random
import logging
from collections import OrderedDict
import numpy as np
import cv2
import torch
import torch.nn as nn
import torch.utils.data
from torchvision import transforms
from torchvision.utils import make_grid
from shutil impo... | 13,098 | 34.498645 | 143 | py |
DenoiseCompression | DenoiseCompression-main/CompressAI/compressai/models/MultiscaleDecomp.py | import torch
import torch.nn as nn
from torch.nn import functional as F
from .waseda import Cheng2020Anchor
from compressai.layers import (
AttentionBlock,
ResidualBlock,
ResidualBlockUpsample,
ResidualBlockWithStride,
conv3x3,
subpel_conv3x3,
conv1x1
)
import warnings
class MultiscaleDecom... | 3,860 | 28.930233 | 84 | py |
DenoiseCompression | DenoiseCompression-main/CompressAI/compressai/models/priors.py | # Copyright (c) 2021-2022, InterDigital Communications, Inc
# All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted (subject to the limitations in the disclaimer
# below) provided that the following conditions are met:
# * Redistributions of source cod... | 23,319 | 34.226586 | 88 | py |
DenoiseCompression | DenoiseCompression-main/CompressAI/compressai/models/utils.py | # Copyright (c) 2021-2022, InterDigital Communications, Inc
# All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted (subject to the limitations in the disclaimer
# below) provided that the following conditions are met:
# * Redistributions of source cod... | 4,989 | 33.178082 | 88 | py |
DenoiseCompression | DenoiseCompression-main/CompressAI/compressai/models/waseda.py | # Copyright (c) 2021-2022, InterDigital Communications, Inc
# All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted (subject to the limitations in the disclaimer
# below) provided that the following conditions are met:
# * Redistributions of source cod... | 5,591 | 35.077419 | 79 | py |
DenoiseCompression | DenoiseCompression-main/CompressAI/compressai/zoo/image.py | # Copyright (c) 2021-2022, InterDigital Communications, Inc
# All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted (subject to the limitations in the disclaimer
# below) provided that the following conditions are met:
# * Redistributions of source cod... | 19,465 | 39.469854 | 115 | py |
DenoiseCompression | DenoiseCompression-main/CompressAI/compressai/zoo/pretrained.py | # Copyright (c) 2021-2022, InterDigital Communications, Inc
# All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted (subject to the limitations in the disclaimer
# below) provided that the following conditions are met:
# * Redistributions of source cod... | 2,750 | 41.323077 | 78 | py |
DenoiseCompression | DenoiseCompression-main/CompressAI/compressai/datasets/SiddDataset.py | import random
import os, glob
import json
import torch
from torch.utils.data import Dataset
from PIL import Image
from torchvision import transforms
class SiddDataset(Dataset):
def __init__(self, dataset_opt):
self.root = dataset_opt['root']
self.transform = transforms.ToTensor()
self.patch... | 3,608 | 38.659341 | 159 | py |
DenoiseCompression | DenoiseCompression-main/CompressAI/compressai/datasets/SyntheticDataset.py | import random
import numpy as np
import torch
from torch.utils.data import Dataset
from PIL import Image
from pathlib import Path
from .utils import sRGBGamma, UndosRGBGamma
from torchvision import transforms
class SyntheticDataset(Dataset):
def __init__(self, dataset_opt):
splitdir = Path(dataset_opt['roo... | 2,867 | 34.85 | 91 | py |
DenoiseCompression | DenoiseCompression-main/CompressAI/compressai/datasets/SyntheticTestDataset.py | import random
import numpy as np
import torch
from torch.utils.data import Dataset
from PIL import Image
from pathlib import Path
from .utils import sRGBGamma, UndosRGBGamma
from torchvision import transforms
class SyntheticTestDataset(Dataset):
def __init__(self, dataset_opt):
root = Path(dataset_opt['roo... | 1,969 | 31.295082 | 82 | py |
DenoiseCompression | DenoiseCompression-main/CompressAI/compressai/datasets/utils.py | import random
import numpy as np
import torch
def sRGBGamma(tensor):
threshold = 0.0031308
a = 0.055
mult = 12.92
gamma = 2.4
res = torch.zeros_like(tensor)
mask = tensor > threshold
res[mask] = (1 + a) * torch.pow(tensor[mask] + 0.001, 1.0 / gamma) - a
res[~mask] = tensor[~mask] * mult... | 717 | 22.933333 | 74 | py |
DenoiseCompression | DenoiseCompression-main/CompressAI/compressai/layers/gdn.py | # Copyright (c) 2021-2022, InterDigital Communications, Inc
# All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted (subject to the limitations in the disclaimer
# below) provided that the following conditions are met:
# * Redistributions of source cod... | 4,085 | 32.491803 | 80 | py |
DenoiseCompression | DenoiseCompression-main/CompressAI/compressai/layers/layers.py | # Copyright (c) 2021-2022, InterDigital Communications, Inc
# All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted (subject to the limitations in the disclaimer
# below) provided that the following conditions are met:
# * Redistributions of source cod... | 8,243 | 32.376518 | 87 | py |
DenoiseCompression | DenoiseCompression-main/CompressAI/compressai/utils/bench/__main__.py | # Copyright (c) 2021-2022, InterDigital Communications, Inc
# All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted (subject to the limitations in the disclaimer
# below) provided that the following conditions are met:
# * Redistributions of source cod... | 5,369 | 28.184783 | 85 | py |
DenoiseCompression | DenoiseCompression-main/CompressAI/compressai/utils/bench/codecs.py | # Copyright (c) 2021-2022, InterDigital Communications, Inc
# All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted (subject to the limitations in the disclaimer
# below) provided that the following conditions are met:
# * Redistributions of source cod... | 24,347 | 26.053333 | 88 | py |
DenoiseCompression | DenoiseCompression-main/CompressAI/compressai/transforms/functional.py | from typing import Tuple, Union
import torch
import torch.nn.functional as F
from torch import Tensor
YCBCR_WEIGHTS = {
# Spec: (K_r, K_g, K_b) with K_g = 1 - K_r - K_b
"ITU-R_BT.709": (0.2126, 0.7152, 0.0722)
}
def _check_input_tensor(tensor: Tensor) -> None:
if (
not isinstance(tensor, Tensor... | 3,953 | 28.073529 | 88 | py |
DenoiseCompression | DenoiseCompression-main/CompressAI/compressai/transforms/transforms.py | from . import functional as F_transforms
__all__ = [
"RGB2YCbCr",
"YCbCr2RGB",
"YUV444To420",
"YUV420To444",
]
class RGB2YCbCr:
"""Convert a RGB tensor to YCbCr.
The tensor is expected to be in the [0, 1] floating point range, with a
shape of (3xHxW) or (Nx3xHxW).
"""
def __call_... | 3,308 | 26.806723 | 83 | py |
DenoiseCompression | DenoiseCompression-main/CompressAI/compressai/entropy_models/entropy_models.py | # Copyright (c) 2021-2022, InterDigital Communications, Inc
# All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted (subject to the limitations in the disclaimer
# below) provided that the following conditions are met:
# * Redistributions of source cod... | 24,657 | 34.840116 | 99 | py |
DenoiseCompression | DenoiseCompression-main/CompressAI/compressai/ops/parametrizers.py | # Copyright (c) 2021-2022, InterDigital Communications, Inc
# All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted (subject to the limitations in the disclaimer
# below) provided that the following conditions are met:
# * Redistributions of source cod... | 2,642 | 39.661538 | 78 | py |
DenoiseCompression | DenoiseCompression-main/CompressAI/compressai/ops/bound_ops.py | # Copyright (c) 2021-2022, InterDigital Communications, Inc
# All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted (subject to the limitations in the disclaimer
# below) provided that the following conditions are met:
# * Redistributions of source cod... | 3,102 | 37.308642 | 78 | py |
DenoiseCompression | DenoiseCompression-main/CompressAI/compressai/ops/ops.py | # Copyright (c) 2021-2022, InterDigital Communications, Inc
# All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted (subject to the limitations in the disclaimer
# below) provided that the following conditions are met:
# * Redistributions of source cod... | 2,223 | 43.48 | 78 | py |
CaBERT-SLU | CaBERT-SLU-main/baseline_midsf.py | """For model training and inference
Data input should be a single sentence.
"""
import random
import torch
import torch.nn as nn
from torch.autograd import Variable
from torch.optim import Adam, RMSprop
from transformers import BertTokenizer, BertModel, BertConfig
from keras.preprocessing.sequence import pad_sequences... | 16,880 | 36.182819 | 138 | py |
CaBERT-SLU | CaBERT-SLU-main/all_data_context.py | import torch as t
from torch.utils.data import Dataset, DataLoader
import pickle
from config import opt
from sklearn.model_selection import train_test_split
import numpy as np
from keras.preprocessing.sequence import pad_sequences
class Turns:
def __init__(self, token_ids, slot_ids):
token_ids, mask = self... | 4,711 | 34.164179 | 113 | py |
CaBERT-SLU | CaBERT-SLU-main/all_data_slot.py | import torch as t
from torch.utils.data import Dataset, DataLoader
import pickle
from config import opt
from sklearn.model_selection import train_test_split
from keras.preprocessing.sequence import pad_sequences
import numpy as np
class CoreDataset(Dataset):
def __init__(self, data, num_labels, num_slot_labels, o... | 1,819 | 29.847458 | 100 | py |
CaBERT-SLU | CaBERT-SLU-main/utils.py | import random
import torch
import torch.nn as nn
from torch.autograd import Variable
from torch.optim import Adam, RMSprop
from transformers import BertTokenizer, BertModel, BertConfig, AdamW
from keras.preprocessing.sequence import pad_sequences
from sklearn.model_selection import train_test_split
import pickle
impor... | 6,421 | 34.877095 | 115 | py |
CaBERT-SLU | CaBERT-SLU-main/bert_context.py | """For model training and inference (multi dialogue act & slot detection)
"""
import random
import torch
import torch.nn as nn
from torch.autograd import Variable
from torch.optim import Adam, RMSprop
from transformers import BertTokenizer, BertModel, BertConfig, AdamW
from keras.preprocessing.sequence import pad_sequ... | 15,293 | 36.211679 | 192 | py |
CaBERT-SLU | CaBERT-SLU-main/baseline_stackprop/utils_bert.py | import random
import torch
import torch.nn as nn
from torch.autograd import Variable
from torch.optim import Adam, RMSprop
from keras.preprocessing.sequence import pad_sequences
from sklearn.model_selection import train_test_split
import pickle
import copy
import numpy as np
import collections
from tqdm import tqdm
fr... | 5,829 | 34.120482 | 115 | py |
CaBERT-SLU | CaBERT-SLU-main/baseline_stackprop/train.py | """
@Author : Lee, Qin
@StartTime : 2018/08/13
@Filename : train.py
@Software : Pycharm
@Framework : Pytorch
@LastModify : 2019/05/07
"""
from utils.module import ModelManager
from utils.loader import DatasetManager ######
from utils.process import Processo... | 3,585 | 36.747368 | 103 | py |
CaBERT-SLU | CaBERT-SLU-main/baseline_stackprop/utils/module.py | """
@Author : Lee, Qin
@StartTime : 2018/08/13
@Filename : module.py
@Software : Pycharm
@Framework : Pytorch
@LastModify : 2019/05/07
"""
import math
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.utils.rnn import pack_pa... | 17,569 | 38.483146 | 111 | py |
CaBERT-SLU | CaBERT-SLU-main/baseline_stackprop/utils/process.py | """
@Author : Lee, Qin
@StartTime : 2018/08/13
@Filename : process.py
@Software : Pycharm
@Framework : Pytorch
@LastModify : 2019/05/07
"""
import torch
import torch.nn as nn
import torch.optim as optim
from torch.autograd import Variable
import pickle
imp... | 18,042 | 39.364653 | 123 | py |
CaBERT-SLU | CaBERT-SLU-main/baseline_stackprop/utils/loader.py | """
@Author : Lee, Qin
@StartTime : 2018/08/13
@Filename : loader.py
@Software : Pycharm
@Framework : Pytorch
@LastModify : 2019/05/07
"""
import os
import numpy as np
from copy import deepcopy
from collections import Counter
from collections import Ordered... | 13,758 | 32.31477 | 112 | py |
CaBERT-SLU | CaBERT-SLU-main/data/dialogue_data.py | import torch as t
from torch.autograd import Variable
import numpy as np
import pandas as pd
import re
import pickle
import h5py
import json
import os
import csv
import spacy
from nltk.tokenize import word_tokenize
from transformers import BertTokenizer, BertModel, BertForMaskedLM
import time
class Data:
def __... | 22,069 | 38.837545 | 145 | py |
CaBERT-SLU | CaBERT-SLU-main/model/transformer_new.py | """Transformer module with masks"""
import torch
import torch.nn as nn
import numpy as np
class ScaledDotProductAttention(nn.Module):
"""Scaled dot-product attention mechanism.
"""
def __init__(self, attention_dropout=0.0):
super(ScaledDotProductAttention, self).__init__()
self.dropout = n... | 3,804 | 32.672566 | 76 | py |
CaBERT-SLU | CaBERT-SLU-main/model/baseline_multi.py | import torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F
import numpy as np
from transformers import BertTokenizer, BertModel
class MULTI(nn.Module):
def __init__(self, opt, num_labels=2, num_slot_labels=10):
super(MULTI, self).__init__()
self.device = tor... | 4,648 | 39.426087 | 107 | py |
CaBERT-SLU | CaBERT-SLU-main/model/CHAN.py | import os.path
import math
import copy
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn import CrossEntropyLoss
from torch.nn import CosineEmbeddingLoss
ffscores = []
class MultiHeadAttention(nn.Module):
def __init__(self, heads, d_model, dropout=0.1):
s... | 6,881 | 33.238806 | 104 | py |
CaBERT-SLU | CaBERT-SLU-main/model/baseline_eca.py | import torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F
import numpy as np
from transformers import BertTokenizer, BertModel
class ECA(nn.Module):
def __init__(self, opt, num_labels=2, num_slot_labels=10):
super(ECA, self).__init__()
self.device = torch.d... | 4,601 | 37.033058 | 122 | py |
CaBERT-SLU | CaBERT-SLU-main/model/transformer.py | """Transformer module with masks"""
import math
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn import TransformerEncoder, TransformerEncoderLayer
class TransformerModel(nn.Module):
def __init__(self, ninp, nhead, nhid, nlayers, dropout=0.5):
super(TransformerModel, self).... | 1,979 | 36.358491 | 100 | py |
CaBERT-SLU | CaBERT-SLU-main/model/mia.py | import os.path
import math
import copy
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn import CrossEntropyLoss
from torch.nn import CosineEmbeddingLoss
class MultiHeadAttention(nn.Module):
def __init__(self, heads, d_model, dropout=0.1):
super().__init__... | 4,445 | 32.428571 | 103 | py |
CaBERT-SLU | CaBERT-SLU-main/model/torchcrf.py | """SOURCE CODE FROM PYTORCH-CRF
"""
from typing import List, Optional
import torch
import torch.nn as nn
class CRF(nn.Module):
"""Conditional random field.
This module implements a conditional random field [LMP01]_. The forward computation
of this class computes the log likelihood of the given sequence of... | 14,331 | 43.098462 | 95 | py |
CaBERT-SLU | CaBERT-SLU-main/model/bert_model_context.py | import torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F
import numpy as np
from transformers import BertTokenizer, BertModel
from model.transformer import TransformerModel
from model.transformer_new import Transformer
from model.CHAN import ContextAttention
from model.torchcrf imp... | 8,750 | 41.072115 | 127 | py |
LayerAct | LayerAct-main/ResNet.py | from functools import partial
from typing import Any, Callable, List, Optional, Type, Union
import numpy as np
import random
import os
import torch
import torch.nn as nn
from torch import Tensor
def random_seed_set(rs) :
torch.manual_seed(rs)
torch.cuda.manual_seed(rs)
torch.cuda.manual_seed_all(rs)
... | 11,184 | 33.953125 | 149 | py |
LayerAct | LayerAct-main/test.py | import argparse
import os
import numpy as np
import pandas as pd
import random
import torch
import torch.nn as nn
import torch.nn.parallel
import torch.backends.cudnn as cudnn
import torch.optim
import torch.utils.data
from collections import OrderedDict as OD
from LayerAct import LA_HardSiLU, LA_SiLU
import data_aug... | 6,329 | 42.356164 | 149 | py |
LayerAct | LayerAct-main/train_validate.py | import time
from enum import Enum
import torch
import torch.nn.parallel
import torch.optim
import torch.utils.data
import shutil
def save_checkpoint(state, is_best, filename='checkpoint.pth.tar'):
torch.save(state, filename)
def accuracy(output, target, topk=(1,)):
"""Computes the accuracy over the k top pre... | 7,326 | 32.153846 | 101 | py |
LayerAct | LayerAct-main/train_parallel.py | import argparse
import time
import os
import sys
import numpy as np
import random
import shutil
import torch
import torch.nn as nn
import torch.nn.parallel
import torch.backends.cudnn as cudnn
import torch.optim
import torch.utils.data
from LayerAct import LA_HardSiLU, LA_SiLU
import data_augmentation
from train_val... | 8,871 | 42.920792 | 166 | py |
LayerAct | LayerAct-main/ResNet_small.py | import torch.nn as nn
import torch.nn.functional as F
class ResNet(nn.Module):
def __init__(self, activation, activation_params, rs, layers, num_classes):
super(ResNet, self).__init__()
self.conv1 = nn.Conv2d(3, 16, kernel_size=3, stride=1, padding=1)
self.norm1 = nn.BatchNorm2d(16)
... | 3,640 | 36.536082 | 101 | py |
LayerAct | LayerAct-main/LayerAct.py | # importing
import torch
import torch.nn as nn
import warnings
warnings.filterwarnings('ignore')
# function to calculate the layer-direction mean and variance.
def calculate_mean_std_for_forward(inputs, std = True) :
if len(inputs.shape) < 4 :
cal_dim = [1]
else :
cal_dim = [1, 2, 3]
... | 6,523 | 32.803109 | 125 | py |
LayerAct | LayerAct-main/data_augmentation.py | import os
import numpy as np
import torch.utils.data
import torchvision
import torchvision.transforms as transforms
from torch.utils.data.sampler import SubsetRandomSampler
from sklearn.model_selection import StratifiedShuffleSplit
import random
from ResNet import resnet18, resnet50, resnet101
from ResNet_small impor... | 9,943 | 39.422764 | 128 | py |
LayerAct | LayerAct-main/train.py | import argparse
import time
import os
import sys
import numpy as np
import random
import shutil
import torch
import torch.nn as nn
import torch.nn.parallel
import torch.backends.cudnn as cudnn
import torch.optim
import torch.utils.data
from LayerAct import LA_HardSiLU, LA_SiLU
import data_augmentation
from train_val... | 8,519 | 42.469388 | 165 | py |
mkbe | mkbe-master/DesGAN/generate.py | import argparse
import numpy as np
import random
import torch
from torch.autograd import Variable
from models import load_models, generate
###############################################################################
# Generation methods
#############################################################################... | 5,149 | 36.867647 | 79 | py |
mkbe | mkbe-master/DesGAN/utils.py | import os
import torch
import numpy as np
import random
def load_kenlm():
global kenlm
import kenlm
def to_gpu(gpu, var):
if gpu:
return var.cuda()
return var
class Dictionary(object):
def __init__(self):
self.word2idx = {}
self.idx2word = {}
self.word2idx['<pad... | 8,267 | 30.557252 | 79 | py |
mkbe | mkbe-master/DesGAN/models.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
from torch.nn.utils.rnn import pack_padded_sequence, pad_packed_sequence
from utils import to_gpu
import json
import os
import numpy as np
class MLP_D(nn.Module):
def __init__(self, ninput, noutput, layers,
... | 12,561 | 33.991643 | 82 | py |
mkbe | mkbe-master/DesGAN/train.py | import argparse
import os
import time
import math
import numpy as np
import random
import sys
import json
from sklearn import preprocessing
import torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F
from torch.autograd import Variable
from utils import to_gpu, Corpus, batchify, tra... | 26,814 | 37.472023 | 100 | py |
mkbe | mkbe-master/MKBE/models/yago_convE_kb_model.py | import tensorflow as tf
from tensorpack import *
from tensorflow.contrib.keras import backend as K
class YAGOConveMultimodel(ModelDesc):
def __init__(self, hyperparams):
super(YAGOConveMultimodel, self).__init__()
self.hyperparams = hyperparams
def _get_inputs(self):
return [InputDesc... | 9,042 | 45.137755 | 120 | py |
UString | UString-master/main.py | #!/usr/bin/env python
# coding: utf-8
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
import torch
import os, time
import argparse
import shutil
from torch.utils.data import DataLoader
from src.Models import UString
from src.eval_tools im... | 23,703 | 48.280665 | 185 | py |
UString | UString-master/demo.py | from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
import cv2
import os, sys
import os.path as osp
import argparse
import torch
import torch.nn as nn
from torchvision import models, transforms
from PIL import Image
import matplotlib.pyplot as... | 18,597 | 44.920988 | 152 | py |
UString | UString-master/src/DataLoader.py | from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
import numpy as np
import pickle
import torch
from torch.utils.data import Dataset
import networkx
import itertools
class DADDataset(Dataset):
def __init__(self, data_path, feature, phase='train... | 15,669 | 39.386598 | 141 | py |
UString | UString-master/src/BayesModels.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import math
class Gaussian(object):
def __init__(self, mu, rho):
super().__init__()
self.mu = mu
self.rho = rho
self.normal = torch.distributions.Normal(0,1)
@property
def sigma(self):
return tor... | 3,130 | 38.632911 | 100 | py |
UString | UString-master/src/Models.py | from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import inspect
from torch.nn.parameter import Parameter
import torch
import torch.nn as nn
from src.utils import glorot, zeros, uniform, reset
from torch_geometric.utils import remove_self_loops, add_self_loops... | 20,930 | 41.03012 | 145 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.