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 |
|---|---|---|---|---|---|---|
dct-fast-weights | dct-fast-weights-master/custom_layer.py | import torch
# DCT-parameterized linear layer with custom backward pass
class LinearWithDCT(torch.autograd.Function):
@staticmethod
def forward(ctx, input, coeffs, idct_weight1, idct_weight2, dct_weight1,
dct_weight2, ind, zero_weights, bias=None):
ctx.save_for_backward(
i... | 6,399 | 32.333333 | 79 | py |
dct-fast-weights | dct-fast-weights-master/external_torch_dct.py | # Taken from https://github.com/zh217/torch-dct/blob/master/torch_dct/_dct.py
#
# (c) Copyright 2018 Ziyang Hu.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, includin... | 2,394 | 39.59322 | 79 | py |
dct-fast-weights | dct-fast-weights-master/dct_fast_rnn.py | # Fast RNN models with DCT-parameterized weights;
# DCT coefficients are parameterised by LSTMs.
import math
import torch
import torch.nn as nn
import torch_dct as dct
from external_torch_dct import DCTLayer
from custom_layer import LinearWithDCT
# Fast weight RNN layer with DCT-parameterized weights;
# DCT coeffi... | 22,071 | 34.947883 | 79 | py |
dct-fast-weights | dct-fast-weights-master/dct_lstm.py | # LSTM layers with DCT-parameterized weights
import torch
import math
import numpy as np
import torch_dct as dct
import torch.nn.functional as F
import torch.nn as nn
from external_torch_dct import DCTLayer
# LSTM layer with DCT-parameterized weights
class DctLSTM(nn.Module):
'''LSTM with weights genereted by... | 29,819 | 35.18932 | 79 | py |
deepscribe | deepscribe-main/setup.py | import setuptools
with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()
setuptools.setup(
name="deepscribe2",
version="0.1",
author="Edward Williams",
author_email="eddiecwilliams@gmail.com",
description="Such deep, so scribe, wow",
long_description=long_descrip... | 844 | 23.852941 | 52 | py |
deepscribe | deepscribe-main/eval_e2e.py | from deepscribe2.pipeline import DeepScribePipeline
from torchmetrics.detection.mean_ap import MeanAveragePrecision
from deepscribe2.datasets import PFADetectionDataModule
import editdistance
from pathlib import Path
import wandb
import numpy as np
from tqdm import tqdm
import torch
# download checkpoint locally (if n... | 2,380 | 30.746667 | 89 | py |
deepscribe | deepscribe-main/deepscribe2/utils.py | from typing import Dict
import torch
def get_boxes(entry: Dict) -> torch.Tensor:
return torch.tensor(
[anno["bbox"] for anno in entry["annotations"]], dtype=torch.float
)
def get_centroids(coords: torch.Tensor):
output_coords = torch.zeros(coords.size()[0], 2)
output_coords[:, 0] = (coords[:... | 430 | 25.9375 | 74 | py |
deepscribe | deepscribe-main/deepscribe2/pipeline.py | import warnings
from typing import List
import pandas as pd
import torch
from torch import nn
from torchvision import transforms as T
from deepscribe2.models import ImageClassifier, RetinaNet, SequentialRANSAC
from deepscribe2.transforms import SquarePad
from deepscribe2.utils import get_centroids
warnings.simplefil... | 4,481 | 34.291339 | 98 | py |
deepscribe | deepscribe-main/deepscribe2/transforms.py | # copied from torchvision. Wanted to use transforms v2 API, but alas.
# I think torchvision transforms v2 API is now in 0.15! switch to that.
from typing import Dict, List, Optional, Tuple, Union
import torch
import torchvision
from torch import nn, Tensor
from PIL import Image
import numpy as np
from torchvision i... | 25,055 | 35.901325 | 125 | py |
deepscribe | deepscribe-main/deepscribe2/debug/trainer_old.py | import pytorch_lightning as pl
from torch.utils.data import DataLoader
from deepscribe2.datasets.dataset import CuneiformLocalizationDataset, collate_retinanet
from deepscribe2.models.detection.retinanet_old import RetinaNet
from deepscribe2 import transforms as T
from pytorch_lightning.callbacks.early_stopping import... | 2,008 | 25.434211 | 88 | py |
deepscribe | deepscribe-main/deepscribe2/debug/trainer_old_new_model.py | import pytorch_lightning as pl
from torch.utils.data import DataLoader
from deepscribe2.datasets.dataset import CuneiformLocalizationDataset, collate_retinanet
from deepscribe2.models.detection.retinanet import RetinaNet
from deepscribe2 import transforms as T
from pytorch_lightning.callbacks.early_stopping import Ear... | 2,004 | 25.381579 | 88 | py |
deepscribe | deepscribe-main/deepscribe2/models/classification.py | from typing import Any, Optional, Tuple
from itertools import product
import torch
from torch import nn
import torch.nn.functional as F
from pytorch_lightning import LightningModule
from torch.optim.lr_scheduler import ReduceLROnPlateau
import os
import timm
from torchmetrics import (
Accuracy,
ConfusionMatr... | 6,231 | 30.16 | 90 | py |
deepscribe | deepscribe-main/deepscribe2/models/detection/retinanet_head.py | # customizable retinanet head.
import math
from typing import Callable, Optional, List, Dict, Tuple
import torch
from torch import nn, Tensor
from torchvision.ops import boxes as box_ops
from torchvision.ops import misc as misc_nn_ops
from torchvision.ops import sigmoid_focal_loss
from torchvision.models.detection imp... | 11,725 | 32.792507 | 118 | py |
deepscribe | deepscribe-main/deepscribe2/models/detection/detr_module.py | import torch
from torch import nn
import pytorch_lightning as pl
from deepscribe2.models.detection.detr import (
build_position_encoding,
Backbone,
Joiner,
Transformer,
DETR,
SetCriterion,
PostProcess,
HungarianMatcher,
NestedTensor,
)
from torchmetrics.detection.mean_ap import Mea... | 5,584 | 29.856354 | 88 | py |
deepscribe | deepscribe-main/deepscribe2/models/detection/retinanet_old.py | from typing import Any, Optional
import torch
from pytorch_lightning import LightningModule
from torchmetrics.detection.mean_ap import MeanAveragePrecision
from torchvision.models.detection.retinanet import RetinaNetHead, retinanet_resnet50_fpn
class RetinaNet(LightningModule):
def __init__(
self,
... | 2,772 | 29.472527 | 88 | py |
deepscribe | deepscribe-main/deepscribe2/models/detection/retinanet.py | from typing import Any, Optional
import torch
from pytorch_lightning import LightningModule
from torch import nn
from torchmetrics.detection.mean_ap import MeanAveragePrecision
from torchvision.models.detection.backbone_utils import _resnet_fpn_extractor
from torchvision.models.detection.retinanet import RetinaNet as ... | 5,254 | 36.805755 | 138 | py |
deepscribe | deepscribe-main/deepscribe2/models/detection/detr/detr.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""
DETR model and criterion classes.
"""
import torch
import torch.nn.functional as F
from torch import nn
from .util import box_ops
from .util.misc import (NestedTensor, nested_tensor_from_tensor_list,
accuracy, get_world_s... | 17,090 | 46.475 | 113 | py |
deepscribe | deepscribe-main/deepscribe2/models/detection/detr/matcher.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""
Modules to compute the matching cost and solve the corresponding LSAP.
"""
import torch
from scipy.optimize import linear_sum_assignment
from torch import nn
from .util.box_ops import box_cxcywh_to_xyxy, generalized_box_iou
class HungarianMat... | 4,516 | 39.693694 | 119 | py |
deepscribe | deepscribe-main/deepscribe2/models/detection/detr/segmentation.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""
This file provides the definition of the convolutional heads used to predict masks, as well as the losses
"""
import io
from collections import defaultdict
from typing import List, Optional
import torch
import torch.nn as nn
import torch.nn.fun... | 16,400 | 37.77305 | 119 | py |
deepscribe | deepscribe-main/deepscribe2/models/detection/detr/position_encoding.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""
Various positional encodings for the transformer.
"""
import math
import torch
from torch import nn
from .util.misc import NestedTensor
class PositionEmbeddingSine(nn.Module):
"""
This is a more standard version of the position embedd... | 4,044 | 32.991597 | 86 | py |
deepscribe | deepscribe-main/deepscribe2/models/detection/detr/backbone.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""
Backbone modules.
"""
from collections import OrderedDict
import torch
import torch.nn.functional as F
import torchvision
from torch import nn
from torchvision.models._utils import IntermediateLayerGetter
from typing import Dict, List
from .ut... | 4,692 | 29.875 | 88 | py |
deepscribe | deepscribe-main/deepscribe2/models/detection/detr/transformer.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""
DETR Transformer class.
Copy-paste from torch.nn.Transformer with modifications:
* positional encodings are passed in MHattention
* extra LN at the end of encoder is removed
* decoder returns a stack of activations from all decoding... | 12,311 | 30.569231 | 88 | py |
deepscribe | deepscribe-main/deepscribe2/models/detection/detr/util/plot_utils.py | """
Plotting utilities to visualize training logs.
"""
import torch
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
from pathlib import Path, PurePath
def plot_logs(logs, fields=('class_error', 'loss_bbox_unscaled', 'mAP'), ewm_col=0, log_name='log.txt'):
'''
Func... | 4,514 | 40.805556 | 120 | py |
deepscribe | deepscribe-main/deepscribe2/models/detection/detr/util/misc.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""
Misc functions, including distributed helpers.
Mostly copy-paste from torchvision references.
"""
import os
import subprocess
import time
from collections import defaultdict, deque
import datetime
import pickle
from packaging import version
fro... | 10,869 | 31.064897 | 89 | py |
deepscribe | deepscribe-main/deepscribe2/models/detection/detr/util/box_ops.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""
Utilities for bounding box manipulation and GIoU.
"""
import torch
from torchvision.ops.boxes import box_area
def box_cxcywh_to_xyxy(x):
x_c, y_c, w, h = x.unbind(-1)
b = [(x_c - 0.5 * w), (y_c - 0.5 * h),
(x_c + 0.5 * w), (y_... | 2,561 | 27.786517 | 110 | py |
deepscribe | deepscribe-main/deepscribe2/datasets/direct_dataset.py | import json
from abc import ABC
from copy import deepcopy
from typing import Dict, List, Tuple, Union
import torch
import torchvision.transforms.functional as F
from PIL import Image
from torch.utils.data import Dataset
from torchvision.io import read_image
# mostly for debugging. pulls data directly from annotation... | 1,150 | 26.404762 | 70 | py |
deepscribe | deepscribe-main/deepscribe2/datasets/dataset.py | import json
from typing import Callable, Optional
import pandas as pd
import torch
from torchvision.datasets import VisionDataset
from torchvision.io import read_image
class CuneiformLocalizationDataset(VisionDataset):
"""
Object detection dataset for labeled cuneiform tablets.
"""
def __init__(
... | 2,695 | 27.083333 | 78 | py |
deepscribe | deepscribe-main/deepscribe2/datasets/dataset_folder.py | from torchvision.datasets import DatasetFolder
from torchvision.datasets.folder import default_loader, has_file_allowed_extension
from typing import Callable, Optional, Tuple, Any, List, Dict, Union, cast
import os
IMG_EXTENSIONS = [".jpg", ".png", ".jpeg"]
def make_dataset_empty_okay(
directory: str,
class_... | 5,779 | 39.138889 | 120 | py |
deepscribe | deepscribe-main/deepscribe2/datasets/datamodules.py | import json
import os
from typing import Callable, Optional, Tuple
import pytorch_lightning as pl
import torch
from torch.utils.data import DataLoader
from torchvision.io import write_jpeg
from tqdm import tqdm
import pandas as pd
from torchvision import transforms as T
from deepscribe2.transforms import SquarePad
f... | 13,350 | 33.498708 | 155 | py |
deepscribe | deepscribe-main/deepscribe2/preprocessing/merge_lines.py | from typing import List, Tuple
import numpy as np
import torch
from deepscribe2.models.line_detection import SequentialRANSAC
from deepscribe2.utils import get_centroids
def merge_boxes_e2e(
original_boxes: torch.Tensor, original_labels: List[int]
) -> Tuple[torch.Tensor, List[List[int]]]:
centroids = get_c... | 1,294 | 27.777778 | 85 | py |
deepscribe | deepscribe-main/deepscribe2/preprocessing/get_hotspots.py | # produce raw hotspot images for classification task.
# converts a dataset file into a a dataset amenable to the
# torchvision ImageFolder format.
import os
from torchvision.io import read_image, write_jpeg
from tqdm import tqdm
from argparse import ArgumentParser
import json
def parse_args():
parser = ArgumentPa... | 1,499 | 28.411765 | 93 | py |
deepscribe | deepscribe-main/deepscribe2/preprocessing/crop_images.py | # take a raw JSON export from OCHRE
# and use the dimensions of the hotspots to remove backdrop from the images.
import json
import os
from argparse import ArgumentParser
from copy import deepcopy
from typing import Dict, Tuple
from torch import Tensor
import torch
from torchvision.io import read_image, write_jpeg
fr... | 3,318 | 29.731481 | 95 | py |
deepscribe | deepscribe-main/deepscribe2/trainers/train_detr.py | import pytorch_lightning as pl
import wandb
from deepscribe2.datasets import PFADetectionDataModule
from deepscribe2.models.detection import DETRLightningModule
from deepscribe2 import transforms as T
DATA_BASE = "/local/ecw/DeepScribe_Data_2023-02-04-selected"
WANDB_PROJECT = "deepscribe-torchvision"
MONITOR_ATTRIBU... | 1,742 | 27.112903 | 86 | py |
deepscribe | deepscribe-main/deepscribe2/trainers/train_classifier.py | import pytorch_lightning as pl
from torchvision import transforms as T
from deepscribe2.datasets import PFAClassificationDataModule
from deepscribe2.models.classification import ImageClassifier
DATA_BASE = "/local/ecw/DeepScribe_Data_2023-02-04-selected"
WANDB_PROJECT = "deepscribe-torchvision-classifier"
MONITOR_ATT... | 1,167 | 28.948718 | 79 | py |
deepscribe | deepscribe-main/deepscribe2/trainers/train_detector.py | from pathlib import Path
import pytorch_lightning as pl
import wandb
from deepscribe2 import transforms as T
from deepscribe2.datasets import PFADetectionDataModule
from deepscribe2.models import RetinaNet
DATA_BASE = "/local/ecw/DeepScribe_Data_2023-02-04-selected"
WANDB_PROJECT = "deepscribe-torchvision"
MONITOR_A... | 1,537 | 26.464286 | 89 | py |
deepscribe | deepscribe-main/deepscribe2/trainers/train_detector_singleclass.py | from pathlib import Path
import pytorch_lightning as pl
import wandb
from deepscribe2 import transforms as T
from deepscribe2.datasets import PFADetectionDataModule
from deepscribe2.models.detection.retinanet import RetinaNet
DATA_BASE = "/local/ecw/DeepScribe_Data_2023-02-04-selected"
WANDB_PROJECT = "deepscribe-to... | 2,107 | 28.690141 | 120 | py |
tth | tth-master/generic_utils.py | """Python utilities required by Keras."""
import binascii
import numpy as np
import time
import sys
import six
import marshal
import types as python_types
import inspect
import codecs
import collections
_GLOBAL_CUSTOM_OBJECTS = {}
class CustomObjectScope(object):
"""Provides a scope that changes to `_GLOBAL... | 15,586 | 34.425 | 97 | py |
tth | tth-master/loss.py | # coding=utf-8
import torch
import torch.nn as nn
import numpy as np
import torch.nn.functional as F
def l2norm(X, eps=1e-13, dim=1):
"""L2-normalize columns of X
"""
norm = torch.pow(X, 2).sum(dim=dim, keepdim=True).sqrt() + eps + 1e-14
X = torch.div(X, norm)
return X
def l1norm(X, eps=1e-13, d... | 3,729 | 29.826446 | 86 | py |
tth | tth-master/common.py | #-*-coding:utf-8 -*-
# --------------------------------------------------------
# Pytorch THH
# --------------------------------------------------------
import os
import logging
import torch
ROOT_PATH = os.path.join(os.environ['HOME'], 'VisualSearch')
MIN_WORD_COUNT = 5
TEXT_ENCODINGS = ['bow', 'bow_nsw', 'gru']
D... | 659 | 22.571429 | 70 | py |
tth | tth-master/TTH_attack.py | # coding=utf-8
import os
# os.environ['CUDA_VISIBLE_DEVICES'] = "2"
import sys
import time
import json
import argparse
import random
import re
import numpy as np
import util
import evaluation
import data_provider as data
import model.TTH as tth
from common import *
from loss import l2norm
from model.model import get_... | 30,599 | 49.578512 | 192 | py |
tth | tth-master/evaluation.py | # coding=utf-8
import torch
import numpy as np
import util
from generic_utils import Progbar
def l2norm(X):
"""L2-normalize columns of X
use numpy.array
"""
norm = np.linalg.norm(X, axis=1, keepdims=True)
return 1.0 * X / (norm + 1e-10) # avoid divide by ZERO
@util.timer
def hist_sim(im, s, d... | 3,029 | 26.545455 | 88 | py |
tth | tth-master/data_provider.py | # coding=utf-8
import torch
import torch.utils.data as data
from torchvision.datasets import Kinetics400
from prefetch_generator import BackgroundGenerator
import numpy as np
import pickle
import os
from bigfile import BigFile
from textlib import TextTool, Vocabulary, negation_augumentation
from torchvision.transforms ... | 32,563 | 40.482803 | 134 | py |
tth | tth-master/bigfile.py | # coding=utf-8
import os, sys, array
import time
import numpy as np
import torch
import util
from itertools import tee
import multiprocessing as mp
class BigFile:
def __init__(self, datadir, bin_file="feature.bin"):
self.nr_of_images, self.ndims = list(map(int, open(os.path.join(datadir, 'shape.txt')).... | 10,497 | 33.646865 | 125 | py |
tth | tth-master/model/model.py | # coding=utf-8
import torch
import sys
sys.path.append('../')
import model.clip as clip
import numpy as np
import torch.nn as nn
import torch.nn.init
import torch.backends.cudnn as cudnn
from torch.nn.utils.clip_grad import clip_grad_norm_
from torch.nn.utils.rnn import pack_padded_sequence, pad_packed_sequence
from ... | 43,281 | 36.312069 | 120 | py |
tth | tth-master/model/TTH.py | import math, numbers, pdb
import numpy as np
import PIL
from torchvision.transforms import Compose, Resize, CenterCrop, TenCrop, Lambda, ToTensor, Normalize, RandomResizedCrop
import torch
from torch import nn
import torch.optim as optim
from torch.nn import functional as F
def preprocess_clip_toTensor(shape=[224, 2... | 19,650 | 48.374372 | 171 | py |
tth | tth-master/model/clip/clip.py | import hashlib
import os
import urllib
import warnings
from typing import Union, List
import torch
from PIL import Image
from torchvision.transforms import Compose, Resize, CenterCrop, ToTensor, Normalize
from tqdm import tqdm
from .model import build_model
from .simple_tokenizer import SimpleTokenizer as _Tokenizer
... | 7,276 | 36.704663 | 142 | py |
tth | tth-master/model/clip/model.py | from collections import OrderedDict
from typing import Tuple, Union
import numpy as np
import torch
import torch.nn.functional as F
from torch import nn
class Bottleneck(nn.Module):
expansion = 4
def __init__(self, inplanes, planes, stride=1):
super().__init__()
# all conv layers have strid... | 17,476 | 38.810934 | 178 | py |
iso-privacy-smpc | iso-privacy-smpc-master/main.py | # THIS IS CRITICAL FOR CRYPTEN TO WORK ON CERTAIN LINUX DISTRIBUTIONS!
# For more details see: https://github.com/facebookresearch/CrypTen/issues/88
import argparse
import torch
torch.set_num_threads(1)
from numpy.random import seed
seed(0)
torch.manual_seed(0)
from common.constants import FULLY_CONNECTED3_MODEL_T... | 3,271 | 43.216216 | 108 | py |
iso-privacy-smpc | iso-privacy-smpc-master/common/pysyft/pysyft_private_inference.py | import syft as sy
import torch
from common.private_inference import PrivateInference
class PysyftPrivateInference(PrivateInference):
"""
Class encapsulating the logic for performing private inference using PySyft.
"""
def __init__(self, test_data_loader, parameters=None):
"""
Returns... | 4,130 | 39.106796 | 117 | py |
iso-privacy-smpc | iso-privacy-smpc-master/common/crypten/crypten_private_inference.py | import warnings
import crypten
import logging
import crypten.mpc as mpc
import torch
from crypten import cryptensor
from common.constants import ALICE, BOB
from common.private_inference import PrivateInference
class CryptenPrivateInference(PrivateInference):
"""
Class encapsulating the logic for performing ... | 4,001 | 36.055556 | 117 | py |
iso-privacy-smpc | iso-privacy-smpc-master/common/model_training/model_training.py | from torch import optim, save
from torch.nn import CrossEntropyLoss
import numpy as np
from common.metrics.time_metric import TimeMetric
class ModelTraining:
"""
Class for model training.
"""
def __init__(self, model, data_loader, training_parameters, criterion=CrossEntropyLoss()):
"""
... | 3,268 | 36.574713 | 120 | py |
iso-privacy-smpc | iso-privacy-smpc-master/common/utils/data_utils.py | from numpy import savetxt, loadtxt
from torch import save
import os
class DataUtils:
"""
Common class for data utilities.
"""
@staticmethod
def save_data(data_path, data_set):
"""
Save the data and labels to a specified directory.
:param data_path: The data path where to s... | 1,592 | 36.928571 | 101 | py |
iso-privacy-smpc | iso-privacy-smpc-master/malaria/common/malaria_data_loader.py | import os
from torch.utils.data.dataloader import DataLoader
from torchvision import datasets
from torchvision.transforms import transforms
from malaria.common.constants import IMG_RESIZE, MALARIA_NORM_MEAN, MALARIA_NORM_STD, TRAIN_BATCH_SIZE
class MalariaDataLoader:
"""
A data loader class for the Malaria ... | 1,579 | 44.142857 | 111 | py |
iso-privacy-smpc | iso-privacy-smpc-master/malaria/common/conv_pool_model.py | from torch import nn
import torch.nn.functional as F
class ConvPoolModel(nn.Module):
"""
A custom CNN network.
"""
def __init__(self, input_shape, num_classes, conv_kernel_sizes, channels, avg_pool_sizes, fc_units):
"""
Creates a CNN.
:param input_shape: the input shape (image... | 2,317 | 34.121212 | 117 | py |
iso-privacy-smpc | iso-privacy-smpc-master/malaria/common/malaria_training.py | from common.model_training.model_training import ModelTraining
from malaria.common.constants import TRAINING_PARAMS, TEST_BATCH_SIZE
from malaria.common.conv_pool_model import ConvPoolModel
from malaria.common.malaria_data_loader import MalariaDataLoader
import torch
def train_malaria_model(model_path, data_path):
... | 1,575 | 38.4 | 110 | py |
iso-privacy-smpc | iso-privacy-smpc-master/malaria/crypten/crypten_malaria.py | import torch
from common.constants import CONVPOOL_MODEL_TYPE
from common.crypten.crypten_private_inference import CryptenPrivateInference
from common.model_factory import ModelFactory
from malaria.common.constants import TEST_BATCH_SIZE
from malaria.common.malaria_training import evaluate_saved_model
from malaria.cry... | 1,296 | 42.233333 | 102 | py |
iso-privacy-smpc | iso-privacy-smpc-master/mnist/common/mnist_data_loader.py | from torch.utils.data import DataLoader
from torchvision.transforms import transforms
from torchvision import datasets
from mnist.common.constants import BATCH_SIZE
class MnistDataLoader:
"""
A simple MNIST data loader.
"""
def __init__(self, data_path, test_batch_size):
"""
Creates ... | 1,012 | 33.931034 | 110 | py |
iso-privacy-smpc | iso-privacy-smpc-master/mnist/common/conv_model.py | import torch.nn as nn
import torch.nn.functional as F
class ConvModel(nn.Module):
"""
Returns a convolution model.
"""
def __init__(self, image_shape, out_channels, kernel_size, stride, padding, avg_pool_size, linear_units, num_classes):
"""
Creates a ConvModel.
:param image_s... | 2,591 | 33.56 | 122 | py |
iso-privacy-smpc | iso-privacy-smpc-master/mnist/common/mnist_training.py | import torch
from common.model_factory import ModelFactory
from common.model_training.model_training import ModelTraining
from mnist.common.constants import TRAINING_PARAMS, MNIST_DIMENSIONS, NUM_CLASSES, TEST_BATCH_SIZE
from mnist.common.mnist_data_loader import MnistDataLoader
def train_mnist_model(model_type, mod... | 1,537 | 41.722222 | 98 | py |
iso-privacy-smpc | iso-privacy-smpc-master/mnist/common/fully_connected_model.py | import torch.nn as nn
import torch.nn.functional as F
class FullyConnectedModel(nn.Module):
"""
Fully connected model.
"""
def __init__(self, input_shape, hidden_units, num_classes):
"""
Returns a FullyConnectedModel.
:param input_shape: The input shape: (image_width, image_he... | 1,471 | 27.307692 | 82 | py |
iso-privacy-smpc | iso-privacy-smpc-master/mnist/crypten/crypten_mnist.py | import torch
from common.crypten.crypten_private_inference import CryptenPrivateInference
from common.model_factory import ModelFactory
from mnist.common.constants import TEST_BATCH_SIZE, MNIST_DIMENSIONS, NUM_CLASSES
from mnist.common.mnist_training import evaluate_plain_text
from mnist.crypten.private_crypten_mnist_... | 1,352 | 49.111111 | 119 | py |
IDEAL | IDEAL-main/code/code/vat_fine.py | import contextlib
import torch
import torch.nn as nn
import torch.nn.functional as F
@contextlib.contextmanager
def _disable_tracking_bn_stats(model):
def switch_attr(m):
if hasattr(m, 'track_running_stats'):
m.track_running_stats ^= True
model.apply(switch_attr)
yield
... | 1,697 | 27.3 | 78 | py |
IDEAL | IDEAL-main/code/code/main.py | import argparse
import os
import random
import math
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.utils.data as Data
from pytorch_transformers import *
from torch.autograd import Variable
from torch.utils.data import Dataset
from torch.utils.data.sampler import Subs... | 21,857 | 37.482394 | 205 | py |
IDEAL | IDEAL-main/code/code/mixtext.py | import torch
import torch.nn as nn
from pytorch_transformers import *
from transformers.modeling_bert import BertEmbeddings, BertPooler, BertLayer
class BertModel4Mix(BertPreTrainedModel):
def __init__(self, config):
super(BertModel4Mix, self).__init__(config)
self.embeddings = BertEmbeddings(conf... | 7,413 | 38.021053 | 152 | py |
IDEAL | IDEAL-main/code/code/vat.py | import contextlib
import torch
import torch.nn as nn
import torch.nn.functional as F
@contextlib.contextmanager
def _disable_tracking_bn_stats(model):
def switch_attr(m):
if hasattr(m, 'track_running_stats'):
m.track_running_stats ^= True
model.apply(switch_attr)
yield
... | 1,976 | 29.415385 | 78 | py |
IDEAL | IDEAL-main/code/code/read_coarse_fine.py | import numpy as np
import pandas as pd
import torch
from torch.utils.data import Dataset
from pytorch_transformers import *
import torch.utils.data as Data
import pickle
import nltk
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize
class Translator:
"""Backtranslation. Here to save time, we... | 10,948 | 39.106227 | 161 | py |
IDEAL | IDEAL-main/code/code/transformers/optimization.py | # coding=utf-8
# Copyright 2018 The Google AI Language Team Authors 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/LICEN... | 8,635 | 44.452632 | 130 | py |
IDEAL | IDEAL-main/code/code/transformers/__main__.py | # coding: utf8
def main():
import sys
if (len(sys.argv) < 4 or len(sys.argv) > 6) or sys.argv[1] not in ["bert", "gpt", "transfo_xl", "gpt2", "xlnet", "xlm"]:
print(
"This command line utility let you convert original (author released) model checkpoint to pytorch.\n"
"It should be used a... | 7,085 | 53.507692 | 135 | py |
IDEAL | IDEAL-main/code/code/transformers/configuration_utils.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... | 10,612 | 50.024038 | 296 | py |
IDEAL | IDEAL-main/code/code/transformers/modeling_tf_pytorch_utils.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,432 | 41.578767 | 166 | py |
IDEAL | IDEAL-main/code/code/transformers/modeling_distilbert.py | # coding=utf-8
# Copyright 2019-present, the HuggingFace Inc. team, The Google AI Language Team and Facebook, Inc.
#
# 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.or... | 34,935 | 49.195402 | 201 | py |
IDEAL | IDEAL-main/code/code/transformers/modeling_tf_gpt2.py | # coding=utf-8
# Copyright 2018 The OpenAI Team Authors and 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 copy of the License... | 31,143 | 49.64065 | 193 | py |
IDEAL | IDEAL-main/code/code/transformers/modeling_tf_transfo_xl.py | # coding=utf-8
# Copyright 2018 Google AI, Google Brain and Carnegie Mellon University 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 Lice... | 35,424 | 45.367801 | 193 | py |
IDEAL | IDEAL-main/code/code/transformers/modeling_tf_auto.py | # coding=utf-8
# Copyright 2018 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.0
#
# Unless required by applicable... | 36,128 | 70.97012 | 472 | py |
IDEAL | IDEAL-main/code/code/transformers/modeling_utils.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... | 42,646 | 52.17581 | 472 | py |
IDEAL | IDEAL-main/code/code/transformers/modeling_tf_openai.py | # coding=utf-8
# Copyright 2018 The OpenAI Team Authors and 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 copy of the License... | 29,018 | 49.292894 | 193 | py |
IDEAL | IDEAL-main/code/code/transformers/modeling_bert.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... | 59,363 | 50.710801 | 187 | py |
IDEAL | IDEAL-main/code/code/transformers/modeling_gpt2.py | # coding=utf-8
# Copyright 2018 The OpenAI Team Authors and 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 copy of the License... | 32,977 | 49.042489 | 148 | py |
IDEAL | IDEAL-main/code/code/transformers/modeling_openai.py | # coding=utf-8
# Copyright 2018 The OpenAI Team Authors and 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 copy of the License... | 30,835 | 48.575563 | 148 | py |
IDEAL | IDEAL-main/code/code/transformers/convert_gpt2_original_tf_checkpoint_to_pytorch.py | # coding=utf-8
# Copyright 2018 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.0
#
# Unless required by applicable... | 3,074 | 39.460526 | 111 | py |
IDEAL | IDEAL-main/code/code/transformers/modeling_tf_roberta.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,902 | 50.966057 | 193 | py |
IDEAL | IDEAL-main/code/code/transformers/convert_roberta_original_pytorch_checkpoint_to_pytorch.py | # coding=utf-8
# Copyright 2018 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.0
#
# Unless required by applicable... | 8,511 | 46.027624 | 188 | py |
IDEAL | IDEAL-main/code/code/transformers/tokenization_bert.py | # coding=utf-8
# Copyright 2018 The Google AI Language Team Authors 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/LICEN... | 20,431 | 42.380042 | 183 | py |
IDEAL | IDEAL-main/code/code/transformers/convert_transfo_xl_original_tf_checkpoint_to_pytorch.py | # coding=utf-8
# Copyright 2018 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.0
#
# Unless required by applicable... | 5,518 | 45.771186 | 121 | py |
IDEAL | IDEAL-main/code/code/transformers/modeling_tf_transfo_xl_utilities.py | # coding=utf-8
# Copyright 2018 Google AI, Google Brain and Carnegie Mellon University 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 Lice... | 8,325 | 46.306818 | 110 | py |
IDEAL | IDEAL-main/code/code/transformers/modeling_tf_xlnet.py | # coding=utf-8
# Copyright 2018 Google AI, Google Brain and Carnegie Mellon University 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 Lice... | 56,203 | 50.563303 | 193 | py |
IDEAL | IDEAL-main/code/code/transformers/convert_openai_original_tf_checkpoint_to_pytorch.py | # coding=utf-8
# Copyright 2018 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.0
#
# Unless required by applicable... | 3,161 | 40.605263 | 118 | py |
IDEAL | IDEAL-main/code/code/transformers/convert_xlm_original_pytorch_checkpoint_to_pytorch.py | # coding=utf-8
# Copyright 2018 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.0
#
# Unless required by applicable... | 3,235 | 37.52381 | 117 | py |
IDEAL | IDEAL-main/code/code/transformers/modeling_tf_xlm.py | # coding=utf-8
# Copyright 2019-present, Facebook, Inc 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.0
#
# Un... | 37,847 | 49.666667 | 193 | py |
IDEAL | IDEAL-main/code/code/transformers/file_utils.py | """
Utilities for working with the local dataset cache.
This file is adapted from the AllenNLP library at https://github.com/allenai/allennlp
Copyright by the AllenNLP authors.
"""
from __future__ import (absolute_import, division, print_function, unicode_literals)
import sys
import json
import logging
import os
impor... | 11,591 | 34.667692 | 144 | py |
IDEAL | IDEAL-main/code/code/transformers/__init__.py | __version__ = "2.0.0"
# Work around to update TensorFlow's absl.logging threshold which alters the
# default Python logging output behavior when present.
# see: https://github.com/abseil/abseil-py/issues/99
# and: https://github.com/tensorflow/tensorflow/issues/26691#issuecomment-500369493
try:
import absl.logging... | 9,860 | 58.403614 | 118 | py |
IDEAL | IDEAL-main/code/code/transformers/modeling_tf_bert.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... | 54,664 | 51.311005 | 193 | py |
IDEAL | IDEAL-main/code/code/transformers/convert_bert_original_tf_checkpoint_to_pytorch.py | # coding=utf-8
# Copyright 2018 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.0
#
# Unless required by applicable... | 2,577 | 38.060606 | 101 | py |
IDEAL | IDEAL-main/code/code/transformers/modeling_tf_distilbert.py | # coding=utf-8
# Copyright 2019-present, the HuggingFace Inc. team, The Google AI Language Team and Facebook, Inc.
#
# 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.or... | 36,899 | 48.596774 | 201 | py |
IDEAL | IDEAL-main/code/code/transformers/convert_bert_pytorch_checkpoint_to_original_tf.py | # coding=utf-8
# Copyright 2018 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.0
#
# Unless required by applicable... | 4,478 | 33.19084 | 115 | py |
IDEAL | IDEAL-main/code/code/transformers/modeling_transfo_xl.py | # coding=utf-8
# Copyright 2018 Google AI, Google Brain and Carnegie Mellon University 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 Lice... | 39,657 | 43.50954 | 157 | py |
IDEAL | IDEAL-main/code/code/transformers/convert_xlnet_original_tf_checkpoint_to_pytorch.py | # coding=utf-8
# Copyright 2018 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.0
#
# Unless required by applicable... | 4,334 | 40.285714 | 126 | py |
IDEAL | IDEAL-main/code/code/transformers/modeling_xlnet.py | # coding=utf-8
# Copyright 2018 Google AI, Google Brain and Carnegie Mellon University 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 Lice... | 70,946 | 51.70951 | 169 | py |
IDEAL | IDEAL-main/code/code/transformers/modeling_xlm.py | # coding=utf-8
# Copyright 2019-present, Facebook, Inc 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.0
#
# Un... | 45,543 | 50.34611 | 163 | py |
IDEAL | IDEAL-main/code/code/transformers/modeling_tf_utils.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... | 25,779 | 52.045267 | 472 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.