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 |
|---|---|---|---|---|---|---|
FATE | FATE-master/python/federatedml/nn/backend/utils/data.py | import numpy as np
from torch.utils.data import Dataset as torchDataset
from federatedml.util import LOGGER
from federatedml.nn.dataset.base import Dataset, get_dataset_class
from federatedml.nn.dataset.image import ImageDataset
from federatedml.nn.dataset.table import TableDataset
from federatedml.nn.dataset.graph imp... | 2,598 | 35.605634 | 109 | py |
FATE | FATE-master/python/federatedml/nn/backend/utils/common.py | import torch as t
import numpy as np
import tempfile
ML_PATH = 'federatedml.nn'
LLM_PATH = "fate_llm"
HOMOMODELMETA = "HomoNNMeta"
HOMOMODELPARAM = "HomoNNParam"
def global_seed(seed):
# set random seed of torch
t.manual_seed(seed)
t.cuda.manual_seed_all(seed)
t.backends.cudnn.deterministic = True
... | 968 | 20.065217 | 72 | py |
FATE | FATE-master/python/federatedml/nn/backend/utils/distributed_util.py | #
# Copyright 2019 The FATE Authors. 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 copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | 815 | 27.137931 | 75 | py |
FATE | FATE-master/python/federatedml/nn/homo/client.py | import json
import torch
import inspect
from fate_arch.computing.non_distributed import LocalData
from fate_arch.computing import is_table
from federatedml.model_base import ModelBase
from federatedml.nn.homo.trainer.trainer_base import get_trainer_class, TrainerBase
from federatedml.nn.backend.utils.data import load_d... | 15,960 | 35.861432 | 145 | py |
FATE | FATE-master/python/federatedml/nn/homo/trainer/fedavg_trainer.py | import torch
import torch as t
import torch.distributed as dist
import tqdm
import numpy as np
import transformers
from torch.nn import DataParallel
from torch.utils.data import DataLoader
from torch.utils.data.distributed import DistributedSampler
from federatedml.framework.homo.aggregator.secure_aggregator import Sec... | 25,839 | 41.291326 | 146 | py |
FATE | FATE-master/python/federatedml/nn/homo/trainer/trainer_base.py | import os
import abc
import importlib
import torch as t
import numpy as np
from torch.nn import Module
from typing import List
from federatedml.util import consts
from federatedml.util import LOGGER
from federatedml.model_base import serialize_models
from federatedml.nn.backend.utils.common import ML_PATH
from federat... | 20,753 | 35.410526 | 131 | py |
FATE | FATE-master/python/federatedml/nn/homo/trainer/fedavg_graph_trainer.py | import torch
import torch as t
import numpy as np
from torch_geometric.loader import NeighborLoader
from federatedml.framework.homo.aggregator.secure_aggregator import SecureAggregatorClient as SecureAggClient
from federatedml.nn.dataset.base import Dataset
from federatedml.nn.homo.trainer.fedavg_trainer import FedAVGT... | 11,560 | 41.977695 | 152 | py |
FATE | FATE-master/python/federatedml/nn/hetero/host.py | #
# Copyright 2019 The FATE Authors. 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 copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | 5,442 | 36.027211 | 82 | py |
FATE | FATE-master/python/federatedml/nn/hetero/guest.py | #!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2019 The FATE Authors. 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 copy of the License at
#
# http://www.apache.org/lic... | 12,612 | 37.571865 | 96 | py |
FATE | FATE-master/python/federatedml/nn/hetero/nn_component/bottom_model.py | #!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2019 The FATE Authors. 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 copy of the License at
#
# http://www.apache.org/lic... | 3,119 | 32.913043 | 120 | py |
FATE | FATE-master/python/federatedml/nn/hetero/nn_component/top_model.py | #!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2019 The FATE Authors. 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 copy of the License at
#
# http://www.apache.org/lic... | 5,348 | 35.636986 | 117 | py |
FATE | FATE-master/python/federatedml/nn/hetero/nn_component/torch_model.py | import numpy as np
import tempfile
from federatedml.util import LOGGER
try: # for the situation that torch is not installed, but other modules still can be used
import torch
import torch as t
import copy
from types import SimpleNamespace
from torch import autograd
from federatedml.nn.backend.t... | 6,909 | 30.697248 | 112 | py |
FATE | FATE-master/python/federatedml/nn/hetero/protection_enhance/coae.py | from federatedml.util import LOGGER
from federatedml.util import consts
try:
import torch
import torch as t
from torch import nn
from torch.nn import Module
from torch.nn import functional as F
except ImportError:
Module = object
def entropy(tensor):
return -t.sum(tensor * t.log2(tensor))... | 4,246 | 25.710692 | 79 | py |
FATE | FATE-master/python/federatedml/nn/hetero/interactive/he_interactive_layer.py | #
# Copyright 2019 The FATE Authors. 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 copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | 36,890 | 37.071207 | 122 | py |
FATE | FATE-master/python/federatedml/nn/hetero/interactive/utils/numpy_layer.py | import torch
import numpy as np
from federatedml.util import consts
from federatedml.secureprotol.paillier_tensor import PaillierTensor
class NumpyDenseLayer(object):
"""
NumpyDenseLayer is designed for Pailler Tensor compute
"""
def __init__(self):
self.input = None
self.model_weig... | 6,956 | 27.62963 | 123 | py |
FATE | FATE-master/python/federatedml/nn/loss/cross_entropy.py | import torch as t
from federatedml.util import consts
from torch.nn.functional import one_hot
def cross_entropy(p2, p1, reduction='mean'):
p2 = p2 + consts.FLOAT_ZERO # to avoid nan
assert p2.shape == p1.shape
if reduction == 'sum':
return -t.sum(p1 * t.log(p2))
elif reduction == 'mean':
... | 913 | 25.114286 | 66 | py |
FATE | FATE-master/python/federatedml/nn/loss/weighted_loss.py | import torch as t
from torch.nn import BCELoss
class WeightedBCE(t.nn.Module):
def __init__(self) -> None:
super().__init__()
self.loss_fn = BCELoss(reduce=False)
def forward(self, pred, label_and_weight):
label, weights = label_and_weight
losses = self.loss_fn(pred, label)
... | 425 | 24.058824 | 47 | py |
FATE | FATE-master/python/federatedml/linear_model/coordinated_linear_model/logistic_regression/homo_logistic_regression/homo_lr_client.py | #!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2019 The FATE Authors. 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 copy of the License at
#
# http://www.apache.org/lic... | 11,511 | 35.087774 | 106 | py |
FATE | FATE-master/python/federatedml/linear_model/coordinated_linear_model/logistic_regression/homo_logistic_regression/homo_lr_base.py | #!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2019 The FATE Authors. 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 copy of the License at
#
# http://www.apache.org/lic... | 8,574 | 42.090452 | 129 | py |
FATE | FATE-master/python/federatedml/util/consts.py | #
# Copyright 2019 The FATE Authors. 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 copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | 8,740 | 22.882514 | 120 | py |
FATE | FATE-master/python/federatedml/transfer_learning/hetero_ftl/ftl_dataloder.py | import numpy as np
import tensorflow as tf
from federatedml.util import LOGGER
class FTLDataLoader(tf.keras.utils.Sequence):
def __init__(self, non_overlap_samples, overlap_samples, batch_size, guest_side=True):
self.batch_size = batch_size
self.guest_side = guest_side
self._overlap_ind... | 3,111 | 31.416667 | 114 | py |
FATE | FATE-master/python/federatedml/transfer_learning/hetero_ftl/ftl_base.py | import copy
import json
import functools
import numpy as np
from federatedml.util import LOGGER
from federatedml.transfer_learning.hetero_ftl.backend.nn_model import get_nn_builder
from federatedml.model_base import ModelBase
from federatedml.param.ftl_param import FTLParam
from federatedml.transfer_learning.hetero_ftl... | 12,882 | 37.804217 | 116 | py |
FATE | FATE-master/python/federatedml/transfer_learning/hetero_ftl/backend/nn_model.py | #
# Copyright 2019 The FATE Authors. 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 copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | 1,611 | 25 | 98 | py |
FATE | FATE-master/python/federatedml/transfer_learning/hetero_ftl/backend/data_generator.py | #!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2019 The FATE Authors. 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 copy of the License at
#
# http://www.apache.org/lic... | 1,238 | 25.361702 | 75 | py |
FATE | FATE-master/python/federatedml/transfer_learning/hetero_ftl/backend/tf_keras/losses.py | #!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2019 The FATE Authors. 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 copy of the License at
#
# http://www.apache.org/lic... | 1,019 | 33 | 75 | py |
FATE | FATE-master/python/federatedml/transfer_learning/hetero_ftl/backend/tf_keras/nn_model.py | #
# Copyright 2019 The FATE Authors. 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 copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | 9,949 | 33.548611 | 102 | py |
FATE | FATE-master/python/federatedml/transfer_learning/hetero_ftl/backend/tf_keras/data_generator.py | #!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2019 The FATE Authors. 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 copy of the License at
#
# http://www.apache.org/lic... | 1,238 | 25.361702 | 75 | py |
FATE | FATE-master/python/federatedml/transfer_learning/hetero_ftl/backend/tf_keras/layers/pooling.py | #
# Copyright 2019 The FATE Authors. 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 copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | 4,149 | 39.291262 | 79 | py |
FATE | FATE-master/python/federatedml/transfer_learning/hetero_ftl/backend/tf_keras/layers/baisc.py | #
# Copyright 2019 The FATE Authors. 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 copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | 1,881 | 43.809524 | 117 | py |
FATE | FATE-master/python/federatedml/transfer_learning/hetero_ftl/backend/tf_keras/layers/util.py | #
# Copyright 2019 The FATE Authors. 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 copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | 1,052 | 30.909091 | 75 | py |
FATE | FATE-master/python/federatedml/transfer_learning/hetero_ftl/backend/tf_keras/layers/conv.py | #
# Copyright 2019 The FATE Authors. 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 copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | 3,710 | 41.655172 | 118 | py |
FATE | FATE-master/python/federatedml/transfer_learning/hetero_ftl/test/test_ftl_modules.py | #
# Copyright 2019 The FATE Authors. 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 copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | 3,947 | 44.906977 | 705 | py |
FATE | FATE-master/python/federatedml/secureprotol/encrypt.py | #
# Copyright 2019 The FATE Authors. 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 copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | 12,519 | 29.990099 | 116 | py |
FATE | FATE-master/python/federatedml/param/ftl_param.py | #!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2019 The FATE Authors. 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 copy of the License at
#
# http://www.apache.org/lic... | 8,927 | 44.090909 | 120 | py |
FATE | FATE-master/python/federatedml/param/hetero_nn_param.py | #!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2019 The FATE Authors. 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 copy of the License at
#
# http://www.apache.org/lic... | 12,596 | 41.557432 | 139 | py |
FATE | FATE-master/python/federatedml/param/boosting_param.py | #!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2019 The FATE Authors. 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 copy of the License at
#
# http://www.apache.org/lic... | 35,803 | 51.268613 | 130 | py |
FATE | FATE-master/python/federatedml/param/homo_nn_param.py | from federatedml.param.base_param import BaseParam
class TrainerParam(BaseParam):
def __init__(self, trainer_name=None, **kwargs):
super(TrainerParam, self).__init__()
self.trainer_name = trainer_name
self.param = kwargs
def check(self):
if self.trainer_name is not None:
... | 2,502 | 31.506494 | 107 | py |
FATE | FATE-master/python/federatedml/ensemble/basic_algorithms/decision_tree/tree_core/splitter.py | #!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2019 The FATE Authors. 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 copy of the License at
#
# http://www.apache.org/lic... | 23,387 | 44.063584 | 122 | py |
FATE | FATE-master/python/federatedml/protobuf/homo_model_convert/homo_model_convert.py | #
# Copyright 2021 The FATE Authors. 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 copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | 6,574 | 38.136905 | 94 | py |
FATE | FATE-master/python/federatedml/protobuf/homo_model_convert/test/homo_nn_test.py | #!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2021 The FATE Authors. 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 copy of the License at
#
# http://www.apache.org/lice... | 3,476 | 33.425743 | 106 | py |
FATE | FATE-master/python/federatedml/protobuf/homo_model_convert/tf_keras/nn.py | #
# Copyright 2021 The FATE Authors. 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 copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | 1,695 | 35.869565 | 103 | py |
FATE | FATE-master/python/federatedml/protobuf/homo_model_convert/pytorch/nn.py | #
# Copyright 2021 The FATE Authors. 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 copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | 1,278 | 28.744186 | 80 | py |
FATE | FATE-master/python/federatedml/framework/homo/aggregator/secure_aggregator.py | from federatedml.framework.homo.blocks import RandomPaddingCipherClient, RandomPaddingCipherServer, PadsCipher, RandomPaddingCipherTransVar
from federatedml.framework.homo.aggregator.aggregator_base import AggregatorBaseClient, AutoSuffix, AggregatorBaseServer
import numpy as np
from federatedml.framework.weights impor... | 11,628 | 39.378472 | 139 | py |
CRL | CRL-main/run_continual.py | import torch
from config import Param
from methods.utils import setup_seed
from methods.manager import Manager
def run(args):
setup_seed(args.seed)
print("hyper-parameter configurations:")
print(str(args.__dict__))
manager = Manager(args)
manager.train(args)
if __name__ == '__main__':
par... | 653 | 24.153846 | 72 | py |
CRL | CRL-main/methods/utils.py | from dataloaders.data_loader import get_data_loader
import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
from tqdm import tqdm, trange
import random
class Moment:
def __init__(self, args) -> None:
self.labels = None
self.mem_labels = None
self.memle... | 5,091 | 38.78125 | 119 | py |
CRL | CRL-main/methods/model.py | import torch.nn as nn
import torch
import torch.nn.functional as F
from .backbone import Bert_Encoder
class Encoder(nn.Module):
def __init__(self, args):
super().__init__()
self.encoder = Bert_Encoder(args)
self.output_size = self.encoder.out_dim
dim_in = self.output_size
s... | 644 | 27.043478 | 48 | py |
CRL | CRL-main/methods/backbone.py | import torch.nn as nn
import torch
import numpy as np
from transformers import BertModel, BertConfig
class Bert_Encoder(nn.Module):
def __init__(self, config, out_token=False):
super(Bert_Encoder, self).__init__()
# load model
self.encoder = BertModel.from_pretrained(config.bert_path).cud... | 3,220 | 42.527027 | 115 | py |
CRL | CRL-main/methods/manager.py | from dataloaders.sampler import data_sampler
from dataloaders.data_loader import get_data_loader
from .model import Encoder
from .utils import Moment, dot_dist
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
import numpy as np
import random
from tqdm import tqdm, trange
fr... | 14,339 | 42.98773 | 139 | py |
CRL | CRL-main/dataloaders/data_loader.py | import torch
from torch.utils.data import Dataset, DataLoader
class data_set(Dataset):
def __init__(self, data,config=None):
self.data = data
self.config = config
self.bert = True
def __len__(self):
return len(self.data)
def __getitem__(self, idx):
return (self.da... | 1,180 | 24.673913 | 89 | py |
wav2letter | wav2letter-main/recipes/lexicon_free/utilities/compute_upper_ppl_convlm.py | """
Copyright (c) Facebook, Inc. and its affiliates.
All rights reserved.
This source code is licensed under the MIT-style license found in the
LICENSE file in the root directory of this source tree.
----------
Compute upper limit on word perplexity for convlm models
Command (for word) : python3 compute_upper_ppl_c... | 6,783 | 33.969072 | 88 | py |
wav2letter | wav2letter-main/recipes/lexicon_free/utilities/convlm_utils.py | """
Copyright (c) Facebook, Inc. and its affiliates.
All rights reserved.
This source code is licensed under the MIT-style license found in the
LICENSE file in the root directory of this source tree.
"""
from __future__ import absolute_import, division, print_function, unicode_literals
import torch
from fairseq impo... | 4,597 | 29.052288 | 82 | py |
wav2letter | wav2letter-main/recipes/lexicon_free/utilities/compute_lower_ppl_convlm.py | """
Copyright (c) Facebook, Inc. and its affiliates.
All rights reserved.
This source code is licensed under the MIT-style license found in the
LICENSE file in the root directory of this source tree.
----------
Compute upper and lower limits on word perplexity for convlm models
Command : python3 compute_lower_ppl_c... | 9,068 | 33.48289 | 88 | py |
wav2letter | wav2letter-main/recipes/utilities/convlm_serializer/save_pytorch_model.py | from __future__ import absolute_import, division, print_function, unicode_literals
import sys
from collections import defaultdict
import torch
def convert(model_state, key, suffix=""):
string = ""
param = model_state[key]
# param name
string += ".".join(key.split(".")[1:-1]) + suffix + "." + key.spl... | 2,325 | 32.710145 | 87 | py |
wav2letter | wav2letter-main/recipes/joint_training_vox_populi/prepare_data/common_voice_to_wav2letter.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import csv
import argparse
import torch
import torchaudio
import string
from tqdm import tqdm
from pathlib import Path
from typing import Dict,... | 7,022 | 26.758893 | 91 | py |
wav2letter | wav2letter-main/recipes/sota/2019/lm_analysis/tts_forward.py | # https://github.com/mozilla/TTS/blob/master/notebooks/Benchmark.ipynb - original code which we adapted
import io
import os
import sys
import time
from collections import OrderedDict
import numpy as np
import torch
from localimport import localimport
from matplotlib import pylab as plt
from TTS.layers import *
from TT... | 3,613 | 26.378788 | 103 | py |
wav2letter | wav2letter-main/recipes/sota/2019/rescoring/forward_lm.py | from __future__ import absolute_import, division, print_function, unicode_literals
import argparse
import os
import numpy
import torch
from fairseq.data import Dictionary
from fairseq.models.fconv_lm import FConvLanguageModel
from fairseq.models.transformer_lm import TransformerLanguageModel
def load_lm(lm_path, mo... | 5,773 | 34.207317 | 87 | py |
ERD | ERD-main/setup.py | #!/usr/bin/env python
# Copyright (c) OpenMMLab. All rights reserved.
import os
import os.path as osp
import platform
import shutil
import sys
import warnings
from setuptools import find_packages, setup
import torch
from torch.utils.cpp_extension import (BuildExtension, CppExtension,
... | 7,887 | 34.692308 | 125 | py |
ERD | ERD-main/tools/test.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import os
import os.path as osp
import warnings
from copy import deepcopy
from mmengine import ConfigDict
from mmengine.config import Config, DictAction
from mmengine.runner import Runner
from mmdet.engine.hooks.utils import trigger_visualization_hook
fr... | 5,594 | 36.3 | 79 | py |
ERD | ERD-main/tools/train.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import logging
import os
import os.path as osp
from mmengine.config import Config, DictAction
from mmengine.logging import print_log
from mmengine.registry import RUNNERS
from mmengine.runner import Runner
from mmdet.utils import setup_cache_size_limit_o... | 4,770 | 34.604478 | 79 | py |
ERD | ERD-main/tools/deployment/test_torchserver.py | import os
from argparse import ArgumentParser
import mmcv
import requests
import torch
from mmengine.structures import InstanceData
from mmdet.apis import inference_detector, init_detector
from mmdet.registry import VISUALIZERS
from mmdet.structures import DetDataSample
def parse_args():
parser = ArgumentParser... | 3,906 | 33.27193 | 77 | py |
ERD | ERD-main/tools/deployment/mmdet2torchserve.py | # Copyright (c) OpenMMLab. All rights reserved.
from argparse import ArgumentParser, Namespace
from pathlib import Path
from tempfile import TemporaryDirectory
from mmengine.config import Config
from mmengine.utils import mkdir_or_exist
try:
from model_archiver.model_packaging import package_model
from model_... | 3,748 | 32.473214 | 78 | py |
ERD | ERD-main/tools/deployment/mmdet_handler.py | # Copyright (c) OpenMMLab. All rights reserved.
import base64
import os
import mmcv
import numpy as np
import torch
from ts.torch_handler.base_handler import BaseHandler
from mmdet.apis import inference_detector, init_detector
class MMdetHandler(BaseHandler):
threshold = 0.5
def initialize(self, context):
... | 2,620 | 34.90411 | 79 | py |
ERD | ERD-main/tools/misc/download_dataset.py | import argparse
import tarfile
from itertools import repeat
from multiprocessing.pool import ThreadPool
from pathlib import Path
from tarfile import TarFile
from zipfile import ZipFile
import torch
from mmengine.utils.path import mkdir_or_exist
def parse_args():
parser = argparse.ArgumentParser(
descript... | 7,177 | 35.810256 | 144 | py |
ERD | ERD-main/tools/model_converters/selfsup2mmdet.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
from collections import OrderedDict
import torch
def moco_convert(src, dst):
"""Convert keys in pycls pretrained moco models to mmdet style."""
# load caffe model
moco_model = torch.load(src)
blobs = moco_model['state_dict']
# conver... | 1,243 | 27.930233 | 74 | py |
ERD | ERD-main/tools/model_converters/publish_model.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import subprocess
import torch
from mmengine.logging import print_log
def parse_args():
parser = argparse.ArgumentParser(
description='Process a checkpoint to be published')
parser.add_argument('in_file', help='input checkpoint filename'... | 1,966 | 30.725806 | 78 | py |
ERD | ERD-main/tools/model_converters/regnet2mmdet.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
from collections import OrderedDict
import torch
def convert_stem(model_key, model_weight, state_dict, converted_names):
new_key = model_key.replace('stem.conv', 'conv1')
new_key = new_key.replace('stem.bn', 'bn1')
state_dict[new_key] = mode... | 3,063 | 32.67033 | 77 | py |
ERD | ERD-main/tools/model_converters/upgrade_model_version.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import re
import tempfile
from collections import OrderedDict
import torch
from mmengine import Config
def is_head(key):
valid_head_list = [
'bbox_head', 'mask_head', 'semantic_head', 'grid_head', 'mask_iou_head'
]
return any(key.st... | 6,852 | 31.478673 | 79 | py |
ERD | ERD-main/tools/model_converters/detectron2_to_mmdet.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
from collections import OrderedDict
import torch
from mmengine.fileio import load
from mmengine.runner import save_checkpoint
def convert(src: str, dst: str, prefix: str = 'd2_model') -> None:
"""Convert Detectron2 checkpoint to MMDetection style.
... | 1,653 | 32.755102 | 78 | py |
ERD | ERD-main/tools/model_converters/upgrade_ssd_version.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import tempfile
from collections import OrderedDict
import torch
from mmengine import Config
def parse_config(config_strings):
temp_file = tempfile.NamedTemporaryFile()
config_path = f'{temp_file.name}.py'
with open(config_path, 'w') as f:
... | 1,793 | 29.40678 | 78 | py |
ERD | ERD-main/tools/model_converters/detectron2pytorch.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
from collections import OrderedDict
import torch
from mmengine.fileio import load
arch_settings = {50: (3, 4, 6, 3), 101: (3, 4, 23, 3)}
def convert_bn(blobs, state_dict, caffe_name, torch_name, converted_names):
# detectron replace bn with affine ... | 3,594 | 41.797619 | 78 | py |
ERD | ERD-main/tools/analysis_tools/benchmark.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import os
from mmengine import MMLogger
from mmengine.config import Config, DictAction
from mmengine.dist import init_dist
from mmengine.registry import init_default_scope
from mmengine.utils import mkdir_or_exist
from mmdet.utils.benchmark import (DataL... | 4,242 | 30.664179 | 79 | py |
ERD | ERD-main/tools/analysis_tools/optimize_anchors.py | # Copyright (c) OpenMMLab. All rights reserved.
"""Optimize anchor settings on a specific dataset.
This script provides two method to optimize YOLO anchors including k-means
anchor cluster and differential evolution. You can use ``--algorithm k-means``
and ``--algorithm differential_evolution`` to switch two method.
... | 13,631 | 34.592689 | 79 | py |
ERD | ERD-main/tools/analysis_tools/get_flops.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import tempfile
from functools import partial
from pathlib import Path
import numpy as np
import torch
from mmengine.config import Config, DictAction
from mmengine.logging import MMLogger
from mmengine.model import revert_sync_batchnorm
from mmengine.regi... | 5,026 | 34.907143 | 78 | py |
ERD | ERD-main/tools/analysis_tools/test_robustness.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import copy
import os
import os.path as osp
from mmengine.config import Config, DictAction
from mmengine.dist import get_dist_info
from mmengine.evaluator import DumpResults
from mmengine.fileio import dump
from mmengine.runner import Runner
from mmdet.e... | 9,120 | 37.004167 | 79 | py |
ERD | ERD-main/projects/Detic/demo.py | # Copyright (c) OpenMMLab. All rights reserved.
import os
import urllib
from argparse import ArgumentParser
import mmcv
import torch
from mmengine.logging import print_log
from mmengine.utils import ProgressBar, scandir
from mmdet.apis import inference_detector, init_detector
from mmdet.registry import VISUALIZERS
fr... | 4,710 | 31.944056 | 78 | py |
ERD | ERD-main/projects/Detic/detic/detic_bbox_head.py | # Copyright (c) OpenMMLab. All rights reserved.
from typing import Optional, Union
from mmengine.config import ConfigDict
from mmengine.structures import InstanceData
from torch import Tensor
from mmdet.models.layers import multiclass_nms
from mmdet.models.roi_heads.bbox_heads import Shared2FCBBoxHead
from mmdet.mode... | 4,599 | 39.707965 | 76 | py |
ERD | ERD-main/projects/Detic/detic/utils.py | # Copyright (c) OpenMMLab. All rights reserved.
import numpy as np
import torch
import torch.nn.functional as F
from mmengine.logging import print_log
from .text_encoder import CLIPTextEncoder
# download from
# https://github.com/facebookresearch/Detic/tree/main/datasets/metadata
DATASET_EMBEDDINGS = {
'lvis': 'd... | 2,864 | 35.265823 | 78 | py |
ERD | ERD-main/projects/Detic/detic/detic_roi_head.py | # Copyright (c) OpenMMLab. All rights reserved.
from typing import List, Sequence, Tuple
import torch
from mmengine.structures import InstanceData
from torch import Tensor
from mmdet.models.roi_heads import CascadeRoIHead
from mmdet.models.task_modules.samplers import SamplingResult
from mmdet.models.test_time_augs i... | 13,673 | 40.816514 | 78 | py |
ERD | ERD-main/projects/Detic/detic/zero_shot_classifier.py | # Copyright (c) Facebook, Inc. and its affiliates.
import numpy as np
import torch
from torch import nn
from torch.nn import functional as F
from mmdet.registry import MODELS
@MODELS.register_module(force=True) # avoid bug
class ZeroShotClassifier(nn.Module):
def __init__(
self,
in_features: in... | 2,324 | 30.418919 | 79 | py |
ERD | ERD-main/projects/Detic/detic/centernet_rpn_head.py | # Copyright (c) OpenMMLab. All rights reserved.
import copy
from typing import List, Sequence, Tuple
import torch
import torch.nn as nn
from mmcv.cnn import Scale
from mmengine import ConfigDict
from mmengine.structures import InstanceData
from torch import Tensor
from mmdet.models.dense_heads import CenterNetUpdateH... | 7,938 | 39.299492 | 79 | py |
ERD | ERD-main/projects/Detic/detic/text_encoder.py | # Copyright (c) OpenMMLab. All rights reserved.
from typing import List, Union
import torch
import torch.nn as nn
class CLIPTextEncoder(nn.Module):
def __init__(self, model_name='ViT-B/32'):
super().__init__()
import clip
from clip.simple_tokenizer import SimpleTokenizer
self.tok... | 1,605 | 30.490196 | 79 | py |
ERD | ERD-main/projects/Detic/configs/detic_centernet2_swin-b_fpn_4x_lvis-coco-in21k.py | _base_ = 'mmdet::common/lsj-200e_coco-detection.py'
custom_imports = dict(
imports=['projects.Detic.detic'], allow_failed_imports=False)
image_size = (1024, 1024)
batch_augments = [dict(type='BatchFixedSizePad', size=image_size)]
cls_layer = dict(
type='ZeroShotClassifier',
zs_weight_path='rand',
zs_... | 9,887 | 32.070234 | 79 | py |
ERD | ERD-main/projects/DiffusionDet/diffusiondet/loss.py | # Copyright (c) OpenMMLab. All rights reserved.
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
# Modified from https://github.com/ShoufaChen/DiffusionDet/blob/main/diffusiondet/loss.py # noqa
# This work is licensed under the CC-BY-NC 4.0 License.
# Users should be careful about adopting the... | 14,481 | 41.345029 | 142 | py |
ERD | ERD-main/projects/DiffusionDet/diffusiondet/head.py | # Copyright (c) OpenMMLab. All rights reserved.
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
# Modified from https://github.com/ShoufaChen/DiffusionDet/blob/main/diffusiondet/detector.py # noqa
# Modified from https://github.com/ShoufaChen/DiffusionDet/blob/main/diffusiondet/head.py # noq... | 43,032 | 40.577778 | 106 | py |
ERD | ERD-main/projects/DiffusionDet/configs/diffusiondet_r50_fpn_500-proposals_1-step_crop-ms-480-800-450k_coco.py | _base_ = [
'mmdet::_base_/datasets/coco_detection.py',
'mmdet::_base_/schedules/schedule_1x.py',
'mmdet::_base_/default_runtime.py'
]
custom_imports = dict(
imports=['projects.DiffusionDet.diffusiondet'], allow_failed_imports=False)
# model settings
model = dict(
type='DiffusionDet',
data_prep... | 6,186 | 32.263441 | 79 | py |
ERD | ERD-main/projects/DiffusionDet/model_converters/diffusiondet_resnet_to_mmdet.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
from collections import OrderedDict
import numpy as np
import torch
from mmengine.fileio import load
def convert(src, dst):
if src.endswith('pth'):
src_model = torch.load(src)
else:
src_model = load(src)
dst_state_dict = Ord... | 3,395 | 37.157303 | 77 | py |
ERD | ERD-main/projects/SparseInst/sparseinst/sparseinst.py | # Copyright (c) Tianheng Cheng and its affiliates. All Rights Reserved
from typing import List, Tuple, Union
import torch
import torch.nn.functional as F
from mmengine.structures import InstanceData
from torch import Tensor
from mmdet.models import BaseDetector
from mmdet.models.utils import unpack_gt_instances
from ... | 7,972 | 37.516908 | 78 | py |
ERD | ERD-main/projects/SparseInst/sparseinst/loss.py | # Copyright (c) Tianheng Cheng and its affiliates. All Rights Reserved
import torch
import torch.nn as nn
import torch.nn.functional as F
from scipy.optimize import linear_sum_assignment
from torch.cuda.amp import autocast
from mmdet.registry import MODELS, TASK_UTILS
from mmdet.utils import reduce_mean
def compute... | 9,212 | 35.852 | 79 | py |
ERD | ERD-main/projects/SparseInst/sparseinst/encoder.py | # Copyright (c) Tianheng Cheng and its affiliates. All Rights Reserved
import torch
import torch.nn as nn
import torch.nn.functional as F
from mmengine.model.weight_init import caffe2_xavier_init, kaiming_init
from mmdet.registry import MODELS
class PyramidPoolingModule(nn.Module):
def __init__(self,
... | 3,806 | 35.961165 | 78 | py |
ERD | ERD-main/projects/SparseInst/sparseinst/decoder.py | # Copyright (c) Tianheng Cheng and its affiliates. All Rights Reserved
import math
import torch
import torch.nn as nn
import torch.nn.functional as F
from mmengine.model.weight_init import caffe2_xavier_init, kaiming_init
from torch.nn import init
from mmdet.registry import MODELS
def _make_stack_3x3_convs(num_con... | 13,792 | 33.396509 | 79 | py |
ERD | ERD-main/projects/SparseInst/configs/sparseinst_r50_iam_8xb8-ms-270k_coco.py | _base_ = [
'mmdet::_base_/datasets/coco_instance.py',
'mmdet::_base_/schedules/schedule_1x.py',
'mmdet::_base_/default_runtime.py'
]
custom_imports = dict(
imports=['projects.SparseInst.sparseinst'], allow_failed_imports=False)
model = dict(
type='SparseInst',
data_preprocessor=dict(
t... | 4,133 | 27.122449 | 79 | py |
ERD | ERD-main/projects/EfficientDet/convert_tf_to_pt.py | import argparse
import numpy as np
import torch
from tensorflow.python.training import py_checkpoint_reader
torch.set_printoptions(precision=20)
def tf2pth(v):
if v.ndim == 4:
return np.ascontiguousarray(v.transpose(3, 2, 0, 1))
elif v.ndim == 2:
return np.ascontiguousarray(v.transpose())
... | 26,971 | 42.017544 | 79 | py |
ERD | ERD-main/projects/EfficientDet/efficientdet/bifpn.py | from typing import List
import torch
import torch.nn as nn
from mmcv.cnn.bricks import Swish
from mmengine.model import BaseModule
from mmdet.registry import MODELS
from mmdet.utils import MultiConfig, OptConfigType
from .utils import DepthWiseConvBlock, DownChannelBlock, MaxPool2dSamePadding
class BiFPNStage(nn.Mo... | 12,443 | 39.534202 | 77 | py |
ERD | ERD-main/projects/EfficientDet/efficientdet/utils.py | import math
from typing import Tuple, Union
import torch
import torch.nn as nn
from mmcv.cnn.bricks import Swish, build_norm_layer
from torch.nn import functional as F
from torch.nn.init import _calculate_fan_in_and_fan_out, trunc_normal_
from mmdet.registry import MODELS
from mmdet.utils import OptConfigType
def v... | 4,897 | 30.6 | 78 | py |
ERD | ERD-main/projects/EfficientDet/efficientdet/huber_loss.py | # Copyright (c) OpenMMLab. All rights reserved.
from typing import Optional
import torch
import torch.nn as nn
from torch import Tensor
from mmdet.models.losses.utils import weighted_loss
from mmdet.registry import MODELS
@weighted_loss
def huber_loss(pred: Tensor, target: Tensor, beta: float = 1.0) -> Tensor:
... | 2,888 | 30.402174 | 78 | py |
ERD | ERD-main/projects/EfficientDet/efficientdet/efficientdet_head.py | # Copyright (c) OpenMMLab. All rights reserved.
from typing import List, Tuple
import torch
import torch.nn as nn
from mmcv.cnn.bricks import Swish, build_norm_layer
from mmengine.model import bias_init_with_prob
from torch import Tensor
from mmdet.models.dense_heads.anchor_head import AnchorHead
from mmdet.models.ut... | 10,986 | 40.935115 | 79 | py |
ERD | ERD-main/projects/EfficientDet/efficientdet/tensorflow/anchor_generator.py | # Copyright (c) OpenMMLab. All rights reserved.
from typing import Optional, Tuple, Union
import torch
from torch import Tensor
from mmdet.models.task_modules.prior_generators.anchor_generator import \
AnchorGenerator
from mmdet.registry import TASK_UTILS
from mmdet.structures.bbox import HorizontalBoxes
DeviceT... | 4,261 | 37.745455 | 78 | py |
ERD | ERD-main/projects/EfficientDet/efficientdet/tensorflow/yxyx_bbox_coder.py | # Copyright (c) OpenMMLab. All rights reserved.
import warnings
import numpy as np
import torch
from mmdet.models.task_modules.coders.delta_xywh_bbox_coder import \
DeltaXYWHBBoxCoder
from mmdet.registry import TASK_UTILS
from mmdet.structures.bbox import HorizontalBoxes, get_box_tensor
@TASK_UTILS.register_mod... | 15,367 | 40.535135 | 79 | py |
ERD | ERD-main/projects/EfficientDet/efficientdet/tensorflow/trans_max_iou_assigner.py | # Copyright (c) OpenMMLab. All rights reserved.
from typing import Optional
import torch
from mmengine.structures import InstanceData
from mmdet.models.task_modules.assigners.assign_result import AssignResult
from mmdet.models.task_modules.assigners.max_iou_assigner import MaxIoUAssigner
from mmdet.registry import TA... | 5,094 | 44.900901 | 79 | py |
ERD | ERD-main/.dev_scripts/download_checkpoints.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import math
import os
import os.path as osp
from multiprocessing import Pool
import torch
from mmengine.config import Config
from mmengine.utils import mkdir_or_exist
def download(url, out_file, min_bytes=math.pow(1024, 2), progress=True):
# math.p... | 2,822 | 32.607143 | 77 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.