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
BackwardCompatibilityML-dev
BackwardCompatibilityML-dev/backwardcompatibilityml/tensorflow/helpers.py
import tensorflow.compat.v2 as tf def bc_fit(h2, training_set=None, testing_set=None, epochs=None, bc_loss=None, optimizer=None): """ This function is used to train a model h2, using an instance of a Tensorflow BCLoss function that has been instantiated using an existing model h1 and regularization parame...
2,952
34.154762
96
py
BackwardCompatibilityML-dev
BackwardCompatibilityML-dev/backwardcompatibilityml/tensorflow/loss/new_error.py
import tensorflow.compat.v2 as tf class BCNLLLoss(object): """ Backward Compatibility New Error Negative Log Likelihood Loss This class implements the backward compatibility loss function with the underlying loss function being the Negative Log Likelihood loss. Note that the final layer of e...
9,939
35.544118
87
py
BackwardCompatibilityML-dev
BackwardCompatibilityML-dev/backwardcompatibilityml/tensorflow/loss/strict_imitation.py
import tensorflow.compat.v2 as tf import tensorflow.compat.v1 as tf1 class BCStrictImitationNLLLoss(object): """ Strict Imitation Negative Log Likelihood Loss This class implements the strict imitation loss function with the underlying loss function being the Negative Log Likelihood loss. No...
10,303
36.74359
124
py
BackwardCompatibilityML-dev
BackwardCompatibilityML-dev/development/model-comparison/app.py
# Copyright (c) Microsoft Corporation # Licensed under the MIT License. import os import copy import io import numpy as np import torch import torch.nn as nn import torch.optim as optim import torch.nn.functional as F import torchvision import random from backwardcompatibilityml import loss as bcloss from backwardcomp...
7,441
36.585859
139
py
BackwardCompatibilityML-dev
BackwardCompatibilityML-dev/development/compatibility-analysis/app.py
# Copyright (c) Microsoft Corporation # Licensed under the MIT License. import os import copy import io import numpy as np import torch import torch.nn as nn import torch.optim as optim import torch.nn.functional as F import torchvision import random from backwardcompatibilityml import loss as bcloss from backwardcomp...
8,557
37.723982
139
py
PPGANs-Privacy-preserving-GANs
PPGANs-Privacy-preserving-GANs-master/PPGANS/gradient_noise.py
import inspect import keras from keras import backend as K def _get_shape(x): if hasattr(x, 'dense_shape'): return x.dense_shape return K.shape(x) def add_gradient_noise(BaseOptimizer): if not ( inspect.isclass(BaseOptimizer) and issubclass(BaseOptimizer, keras.optimizers.Optimi...
1,618
28.981481
99
py
PPGANs-Privacy-preserving-GANs
PPGANs-Privacy-preserving-GANs-master/PPGANS/dpgan.py
import os os.environ["KERAS_BACKEND"] = "tensorflow" import numpy as np from tqdm import tqdm import matplotlib.pyplot as plt from keras.layers import Input from keras.models import Model, Sequential from keras.layers.core import Reshape, Dense, Dropout, Flatten from keras.layers.advanced_activations import LeakyReLU...
5,294
33.835526
117
py
GDANet
GDANet-main/main_cls.py
from __future__ import print_function import os import argparse import torch import torch.nn as nn import torch.optim as optim from torch.optim.lr_scheduler import CosineAnnealingLR from util.data_util import ModelNet40 from model.GDANet_cls import GDANET import numpy as np from torch.utils.data import DataLoader from ...
9,519
41.123894
119
py
GDANet
GDANet-main/main_ptseg.py
from __future__ import print_function import os import argparse import torch import torch.optim as optim from torch.optim.lr_scheduler import CosineAnnealingLR, StepLR from util.data_util import PartNormalDataset import torch.nn.functional as F import torch.nn as nn from model.GDANet_ptseg import GDANet import numpy as...
20,206
44.511261
151
py
GDANet
GDANet-main/voting_eval_modelnet.py
from __future__ import print_function import os import argparse import torch import torch.nn as nn import torch.nn.functional as F from util.data_util import ModelNet40 from model.GDANet_cls import GDANET import numpy as np from torch.utils.data import DataLoader from util.util import cal_loss, IOStream import sklearn....
4,737
37.836066
118
py
GDANet
GDANet-main/util/data_util.py
import glob import h5py import numpy as np from torch.utils.data import Dataset import os import json def load_data(partition): all_data = [] all_label = [] for h5_name in glob.glob('./data/modelnet40_ply_hdf5_2048/ply_data_%s*.h5' % partition): f = h5py.File(h5_name) data = f['data'][:].a...
6,371
37.853659
116
py
GDANet
GDANet-main/util/GDANet_util.py
import torch from torch import nn def knn(x, k): inner = -2*torch.matmul(x.transpose(2, 1), x) xx = torch.sum(x**2, dim=1, keepdim=True) pairwise_distance = -xx - inner - xx.transpose(2, 1) idx = pairwise_distance.topk(k=k, dim=-1)[1] # (batch_size, num_points, k) return idx, pairwise_distance...
7,130
32.478873
101
py
GDANet
GDANet-main/util/util.py
import numpy as np import torch import torch.nn.functional as F def cal_loss(pred, gold, smoothing=True): ''' Calculate cross entropy loss, apply label smoothing if needed. ''' gold = gold.contiguous().view(-1) # gold is the groudtruth label in the dataloader if smoothing: eps = 0.2 n_cl...
2,582
35.9
151
py
GDANet
GDANet-main/model/GDANet_ptseg.py
import torch.nn as nn import torch import torch.nn.functional as F from util.GDANet_util import local_operator_withnorm, local_operator, GDM, SGCAM class GDANet(nn.Module): def __init__(self, num_classes): super(GDANet, self).__init__() self.bn1 = nn.BatchNorm2d(64, momentum=0.1) self.bn1...
4,987
37.96875
92
py
GDANet
GDANet-main/model/GDANet_cls.py
import torch.nn as nn import torch import torch.nn.functional as F from util.GDANet_util import local_operator, GDM, SGCAM class GDANET(nn.Module): def __init__(self): super(GDANET, self).__init__() self.bn1 = nn.BatchNorm2d(64, momentum=0.1) self.bn11 = nn.BatchNorm2d(64, momentum=0.1) ...
4,241
36.210526
85
py
PosterLayout-CVPR2023
PosterLayout-CVPR2023-main/dataloader.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Wed Nov 2 18:13:15 2022 @author: kinsleyhsu """ import os import numpy as np import torch from torch.utils.data import Dataset, DataLoader from torchvision import transforms from pandas import read_csv from PIL import Image from designSeq import reorder ...
4,825
34.485294
106
py
PosterLayout-CVPR2023
PosterLayout-CVPR2023-main/eval.py
# -*- coding: utf-8 -*- """ Created on Sun Oct 23 20:18:00 2022 @author: kinsleyhsu """ import torch import os import copy import numpy as np import cv2 from PIL import Image, ImageDraw from math import log gpu = torch.cuda.is_available() device_ids = [0, 1, 2, 3] device = torch.device(f"cuda:{device_ids[0]}" if gpu...
12,437
29.560197
115
py
PosterLayout-CVPR2023
PosterLayout-CVPR2023-main/infer.py
# -*- coding: utf-8 -*- """ Created on Sat Oct 15 14:08:12 2022 @author: kinsleyhsu """ import torch import torch.nn as nn import torch.optim as optim from torch.utils.data import DataLoader from dataloader import canvas from model import generator # import your model module from PIL import Image, ImageDraw import ma...
3,151
28.457944
102
py
SGAttack
SGAttack-master/src/classifier/gcn.py
import tensorflow as tf from distutils.version import LooseVersion if LooseVersion(tf.__version__) > LooseVersion("1.14"): import tensorflow.compat.v1 as tf if LooseVersion(tf.__version__) > LooseVersion("2.0"): tf.disable_v2_behavior() import numpy as np import scipy.sparse as sp from tensorflow.keras.initial...
9,629
41.422907
165
py
spacepy
spacepy-main/tests/test_plot_utils.py
#!/usr/bin/env python2.6 # -*- coding: utf-8 -*- """ Test suite for plot.utils Copyright 2010-2015 Los Alamos National Security, LLC. """ try: import cStringIO as StringIO sio = StringIO.StringIO except ImportError: import io sio = io.BytesIO import datetime import unittest import warnings import ma...
6,543
38.185629
97
py
dipn
dipn-main/main.py
#!/usr/bin/env python import time import os import random import threading import argparse import matplotlib.pyplot as plt import numpy as np import scipy as sc import cv2 from collections import namedtuple import torch from torch.autograd import Variable from robot import Robot from trainer import Trainer from logger...
47,659
55.805721
275
py
dipn
dipn-main/push_main.py
import time import os import random import threading import argparse import matplotlib.pyplot as plt import numpy as np import scipy as sc import cv2 from collections import namedtuple import torch from torch.autograd import Variable from robot import Robot from trainer import Trainer from logger import Logger import u...
40,740
55.74234
264
py
dipn
dipn-main/train_maskrcnn.py
import torch import torchvision from dataset import SegmentationDataset import utils import argparse import time import os from vision.coco_utils import get_coco_api_from_dataset from vision.coco_eval import CocoEvaluator import vision.transforms as T import math from torchvision.models.detection.faster_rcnn import Fas...
10,784
37.655914
125
py
dipn
dipn-main/utils.py
import struct from collections import defaultdict, deque import time import datetime import torch.distributed as dist import math import numpy as np import cv2 import torch import torch.nn as nn import torch.nn.functional as F from torch.autograd import Variable def get_pointcloud(color_img, depth_img, camera_intrins...
23,455
36.5296
127
py
dipn
dipn-main/logger.py
import time import datetime import os import numpy as np import cv2 import torch # import h5py class Logger(): def __init__(self, continue_logging, logging_directory): # Create directory to save data timestamp = time.time() timestamp_value = datetime.datetime.fromtimestamp(timestamp) ...
6,784
59.044248
156
py
dipn
dipn-main/dataset.py
from torch.utils.data.sampler import Sampler import os import numpy as np import torch import torch.utils.data import cv2 import imutils from torchvision.transforms import functional as TF from PIL import Image import torchvision import random from constants import is_real, workspace_limits, heightmap_resolution, PUSH_...
46,102
49.166485
312
py
dipn
dipn-main/train_push_prediction.py
import torch from torchvision import transforms as T from push_net import PushPredictionNet from dataset import PushPredictionMultiDataset, ClusterRandomSampler from torch.utils.data.sampler import RandomSampler import utils import argparse import time import os import numpy as np import cv2 from torch.utils.tensorboar...
36,316
45.204835
279
py
dipn
dipn-main/action_utils_mask.py
import cv2 import imutils import math from constants import is_real, workspace_limits, DEPTH_MIN, colors_lower, colors_upper, resolution_pad, resolution, resolution_crop, padding_width, heightmap_resolution, distance import random import numpy as np from scipy import spatial import torch from dataset import PushPredict...
20,903
49.25
178
py
dipn
dipn-main/models.py
#!/usr/bin/env python from collections import OrderedDict import numpy as np from scipy import ndimage import torch import torch.nn as nn import torch.nn.functional as F from torch.autograd import Variable import torchvision import matplotlib.pyplot as plt import time from vision.backbone_utils import resnet_fpn_net f...
14,982
47.332258
134
py
dipn
dipn-main/push_net.py
import torch import torch.nn as nn import torch.nn.functional as F from vision.resnet import ResNetSmallNoFC, Bottleneck, BasicBlock from vision.backbone_utils import resent_backbone from collections import OrderedDict from torchvision.models.segmentation.fcn import FCN, FCNHead from torchvision.models.segmentation.dee...
4,125
37.203704
115
py
dipn
dipn-main/train_foreground.py
import torch from torchvision import transforms as T from models import reinforcement_net from dataset import ForegroundDataset import utils import argparse import time import os from constants import PUSH_Q, GRASP_Q def get_data_loader(dataset_root, batch_size, fine_tuning_num=None): # use our dataset and define...
8,946
36.911017
160
py
dipn
dipn-main/trainer.py
import os import time import numpy as np import cv2 import torch import torch.nn as nn import torch.nn.functional as F from torch.autograd import Variable from utils import CrossEntropyLoss2d from models import reinforcement_net, reactive_net from scipy import ndimage import matplotlib.pyplot as plt from constants impo...
39,811
53.536986
193
py
dipn
dipn-main/vision/backbone_utils.py
from collections import OrderedDict from torch import nn from torchvision.ops.feature_pyramid_network import FeaturePyramidNetwork, LastLevelMaxPool import torch.nn.functional as F from torchvision.ops import misc as misc_nn_ops from ._utils import IntermediateLayerGetter from . import resnet from torchvision.models.se...
13,594
44.166113
159
py
dipn
dipn-main/vision/_utils.py
from collections import OrderedDict import torch from torch import nn from torch.jit.annotations import Dict from torch.nn import functional as F class IntermediateLayerGetter(nn.ModuleDict): """ Module wrapper that returns intermediate layers from a model It has a strong assumption that the modules hav...
2,641
37.289855
89
py
dipn
dipn-main/vision/resnet.py
import torch import torch.nn as nn from torchvision.models.utils import load_state_dict_from_url __all__ = ['ResNet', 'resnet10', 'resnet18', 'resnet34', 'resnet50', 'resnet101', 'resnet152', 'resnext50_32x4d', 'resnext101_32x8d', 'wide_resnet50_2', 'wide_resnet101_2'] model_urls = { 'resn...
18,977
39.989201
107
py
dipn
dipn-main/vision/coco_utils.py
import copy import os from PIL import Image import torch import torch.utils.data import torchvision from pycocotools import mask as coco_mask from pycocotools.coco import COCO class FilterAndRemapCocoCategories(object): def __init__(self, categories, remap=True): self.categories = categories sel...
7,759
34.272727
83
py
dipn
dipn-main/vision/coco_eval.py
import json import tempfile import numpy as np import copy import time import torch import torch._six from pycocotools.cocoeval import COCOeval from pycocotools.coco import COCO import pycocotools.mask as mask_util from collections import defaultdict import utils class CocoEvaluator(object): def __init__(self...
11,999
33.383954
107
py
dipn
dipn-main/vision/transforms.py
import random import torch from torchvision.transforms import functional as F def _flip_coco_person_keypoints(kps, width): flip_inds = [0, 2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15] flipped_data = kps[:, flip_inds] flipped_data[..., 0] = width - flipped_data[..., 0] # Maintain COCO conven...
1,358
28.543478
74
py
Impact-of-FC-layers
Impact-of-FC-layers-master/Source Codes/CIFAR-10/CNN2_CIFAR10.py
from __future__ import print_function import keras from keras.utils import np_utils import scipy from keras.datasets import cifar10 from keras.preprocessing.image import ImageDataGenerator from keras.models import Sequential from keras.preprocessing import image from keras.applications.imagenet_utils import preprocess_...
7,662
39.760638
120
py
Impact-of-FC-layers
Impact-of-FC-layers-master/Source Codes/CIFAR-10/CNN4_CIFAR-10.py
from __future__ import print_function import keras from keras.utils import np_utils from keras.datasets import cifar10 from keras.preprocessing.image import ImageDataGenerator from keras.models import Sequential from keras.preprocessing import image from keras.applications.imagenet_utils import preprocess_input from k...
9,307
41.697248
120
py
Impact-of-FC-layers
Impact-of-FC-layers-master/Source Codes/CIFAR-10/CNN1_CIFAR10.py
from __future__ import print_function import keras from keras.utils import np_utils import scipy from keras.datasets import cifar10 from keras.preprocessing.image import ImageDataGenerator from keras.models import Sequential from keras.preprocessing import image from keras.applications.imagenet_utils import preprocess_...
6,958
40.177515
143
py
Impact-of-FC-layers
Impact-of-FC-layers-master/Source Codes/CIFAR-10/CNN3_CIFAR10.py
from __future__ import print_function import keras from keras.utils import np_utils import scipy from keras.datasets import cifar10 from keras.preprocessing.image import ImageDataGenerator from keras.models import Sequential from keras.preprocessing import image from keras.applications.imagenet_utils import preprocess_...
8,874
42.719212
139
py
Impact-of-FC-layers
Impact-of-FC-layers-master/Source Codes/Tiny ImageNet/CNN1_TinyImageNet.py
from __future__ import print_function import keras from keras.utils import np_utils import scipy from keras.preprocessing.image import ImageDataGenerator from keras.models import Sequential from keras.preprocessing import image from keras.applications.imagenet_utils import preprocess_input from keras.layers import Dens...
8,411
36.891892
120
py
Impact-of-FC-layers
Impact-of-FC-layers-master/Source Codes/Tiny ImageNet/CNN2_TinyImageNet.py
from __future__ import print_function import keras from keras.utils import np_utils import scipy from keras.preprocessing.image import ImageDataGenerator from keras.models import Sequential from keras.preprocessing import image from keras.applications.imagenet_utils import preprocess_input from keras.layers import Dens...
9,158
37.483193
120
py
Impact-of-FC-layers
Impact-of-FC-layers-master/Source Codes/Tiny ImageNet/CNN3_TinyImageNet.py
from __future__ import print_function import keras from keras.utils import np_utils import scipy from keras.preprocessing.image import ImageDataGenerator from keras.models import Sequential from keras.preprocessing import image from keras.applications.imagenet_utils import preprocess_input from keras.layers import Dens...
9,682
38.361789
120
py
Impact-of-FC-layers
Impact-of-FC-layers-master/Source Codes/CRC_HistoPhenoTypes/CNN3_CRC.py
from __future__ import print_function import keras from keras.utils import np_utils from keras.datasets import cifar10 from keras.preprocessing.image import ImageDataGenerator from keras.models import Sequential from keras.preprocessing import image from keras.applications.imagenet_utils import preprocess_input from k...
11,721
41.31769
139
py
Impact-of-FC-layers
Impact-of-FC-layers-master/Source Codes/CRC_HistoPhenoTypes/CNN2_CRC.py
from __future__ import print_function import keras from keras.utils import np_utils from keras.datasets import cifar10 from keras.preprocessing.image import ImageDataGenerator from keras.models import Sequential from keras.preprocessing import image from keras.applications.imagenet_utils import preprocess_input from k...
10,614
39.056604
120
py
Impact-of-FC-layers
Impact-of-FC-layers-master/Source Codes/CRC_HistoPhenoTypes/CNN4_CRC.py
from __future__ import print_function import keras from keras.utils import np_utils from keras.datasets import cifar10 from keras.preprocessing.image import ImageDataGenerator from keras.models import Sequential from keras.preprocessing import image from keras.applications.imagenet_utils import preprocess_input from k...
10,751
41.330709
120
py
Impact-of-FC-layers
Impact-of-FC-layers-master/Source Codes/CRC_HistoPhenoTypes/CNN1_CRC.py
from __future__ import print_function from keras.utils import np_utils from keras.datasets import cifar10 from keras.preprocessing.image import ImageDataGenerator from keras.models import Sequential from keras.preprocessing import image from keras.applications.imagenet_utils import preprocess_input from keras.layers im...
9,325
39.547826
143
py
Impact-of-FC-layers
Impact-of-FC-layers-master/Source Codes/CIFAR-100/CNN1_CIFAR100.py
from __future__ import print_function import keras from keras.utils import np_utils import scipy from keras.datasets import cifar100 from keras.preprocessing.image import ImageDataGenerator from keras.models import Sequential from keras.preprocessing import image from keras.applications.imagenet_utils import preprocess...
6,999
40.176471
143
py
Impact-of-FC-layers
Impact-of-FC-layers-master/Source Codes/CIFAR-100/CNN3_CIFAR100.py
from __future__ import print_function import keras from keras.utils import np_utils import scipy from keras.datasets import cifar100 from keras.preprocessing.image import ImageDataGenerator from keras.models import Sequential from keras.preprocessing import image from keras.applications.imagenet_utils import preprocess...
8,887
42.783251
139
py
Impact-of-FC-layers
Impact-of-FC-layers-master/Source Codes/CIFAR-100/CNN4_CIFAR-100.py
from __future__ import print_function import keras from keras.utils import np_utils from keras.datasets import cifar10 from keras.preprocessing.image import ImageDataGenerator from keras.models import Sequential from keras.preprocessing import image from keras.applications.imagenet_utils import preprocess_input from k...
9,310
41.711009
120
py
Impact-of-FC-layers
Impact-of-FC-layers-master/Source Codes/CIFAR-100/CNN2_CIFAR100.py
from __future__ import print_function import keras from keras.utils import np_utils import scipy from keras.datasets import cifar100 from keras.preprocessing.image import ImageDataGenerator from keras.models import Sequential from keras.preprocessing import image from keras.applications.imagenet_utils import preprocess...
7,426
39.145946
120
py
cmcl_vqa_pl
cmcl_vqa_pl-master/run.py
import os import copy import pytorch_lightning as pl os.environ["NCCL_DEBUG"] = "INFO" from meter.config import ex from meter.modules import METERTransformerSS from meter.datamodules.multitask_datamodule import MTDataModule import resource rlimit = resource.getrlimit(resource.RLIMIT_NOFILE) # resource.setrlimit(resou...
2,365
29.333333
97
py
cmcl_vqa_pl
cmcl_vqa_pl-master/meter/datamodules/f30k_caption_karpathy_datamodule.py
from ..datasets import F30KCaptionKarpathyDataset from .datamodule_base import BaseDataModule from torch.utils.data import DataLoader class F30KCaptionKarpathyDataModule(BaseDataModule): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @property def dataset_cls(self): ...
1,414
25.203704
52
py
cmcl_vqa_pl
cmcl_vqa_pl-master/meter/datamodules/multitask_datamodule.py
import functools from pytorch_lightning import LightningDataModule from torch.utils.data import DataLoader from torch.utils.data.dataset import ConcatDataset from torch.utils.data.distributed import DistributedSampler from . import _datamodules class MTDataModule(LightningDataModule): def __init__(self, _config...
2,711
31.674699
85
py
cmcl_vqa_pl
cmcl_vqa_pl-master/meter/datamodules/datamodule_base.py
import torch from pytorch_lightning import LightningDataModule from torch.utils.data import DataLoader from transformers import ( DataCollatorForLanguageModeling, DataCollatorForWholeWordMask, BertTokenizer, RobertaTokenizer, AutoModelForTokenClassification ) def get_pretrained_tokenizer(from_pre...
6,133
30.947917
83
py
cmcl_vqa_pl
cmcl_vqa_pl-master/meter/datamodules/multitask_datamodule_vlp.py
import functools from pytorch_lightning import LightningDataModule from torch.utils.data import DataLoader from torch.utils.data.dataset import ConcatDataset from torch.utils.data.distributed import DistributedSampler from . import _datamodules class MTDataModule(LightningDataModule): def __init__(self, _config...
2,755
31.809524
85
py
cmcl_vqa_pl
cmcl_vqa_pl-master/meter/datamodules/nl_datamodule.py
import functools from pytorch_lightning import LightningDataModule from torch.utils.data import DataLoader from torch.utils.data.dataset import ConcatDataset from torch.utils.data.distributed import DistributedSampler from . import _datamodules class NLDataModule(LightningDataModule): def __init__(self, _config...
2,720
32.182927
85
py
cmcl_vqa_pl
cmcl_vqa_pl-master/meter/gadgets/my_metrics.py
import torch from pytorch_lightning.metrics import Metric class Accuracy(Metric): def __init__(self, dist_sync_on_step=False): super().__init__(dist_sync_on_step=dist_sync_on_step) self.add_state("correct", default=torch.tensor(0.0), dist_reduce_fx="sum") self.add_state("total", default=to...
2,359
32.714286
82
py
cmcl_vqa_pl
cmcl_vqa_pl-master/meter/modules/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 LayerNorm(nn.LayerNorm): """Subclass torch's LayerNorm to handle fp16.""" def forward(self, x: torch.Tensor): orig_type = x.dtype ret...
11,209
39.179211
142
py
cmcl_vqa_pl
cmcl_vqa_pl-master/meter/modules/meter_utils.py
import torch import random from transformers.optimization import AdamW from transformers import ( get_polynomial_decay_schedule_with_warmup, get_cosine_schedule_with_warmup, ) from .dist_utils import all_gather from .objectives import compute_irtr_recall from ..gadgets.my_metrics import Accuracy, VQAScore, Sca...
12,258
38.801948
100
py
cmcl_vqa_pl
cmcl_vqa_pl-master/meter/modules/swin_transformer.py
""" Swin Transformer A PyTorch impl of : `Swin Transformer: Hierarchical Vision Transformer using Shifted Windows` - https://arxiv.org/pdf/2103.14030 Code/weights from https://github.com/microsoft/Swin-Transformer, original copyright/license info below """ # -------------------------------------------------------- ...
27,086
41.191589
125
py
cmcl_vqa_pl
cmcl_vqa_pl-master/meter/modules/bert_model.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...
76,759
41.858738
213
py
cmcl_vqa_pl
cmcl_vqa_pl-master/meter/modules/meter_module.py
import torch import torch.nn as nn import pytorch_lightning as pl import numpy as np from transformers.models.bert.modeling_bert import BertConfig, BertModel, BertForMaskedLM from .bert_model import BertCrossLayer from . import swin_transformer as swin from . import heads, objectives, meter_utils from .clip_model impo...
17,580
43.84949
138
py
cmcl_vqa_pl
cmcl_vqa_pl-master/meter/modules/dist_utils.py
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved """ This file contains primitives for multi-gpu communication. This is useful when doing distributed training. """ import functools import logging import numpy as np import pickle import torch import torch.distributed as dist import torch _LOCAL_...
7,814
27.837638
100
py
cmcl_vqa_pl
cmcl_vqa_pl-master/meter/modules/objectives.py
import torch import torch.nn as nn import torch.nn.functional as F import os import glob import json import tqdm import functools from torch.utils.data.distributed import DistributedSampler from einops import rearrange from .dist_utils import all_gather def compute_mlm_oracle(pl_module, batch): infer = pl_modul...
19,551
34.484574
109
py
cmcl_vqa_pl
cmcl_vqa_pl-master/meter/modules/swin_helpers.py
""" Model creation / weight loading / state_dict helpers Hacked together by / Copyright 2020 Ross Wightman """ import logging import os import math from collections import OrderedDict from copy import deepcopy from typing import Any, Callable, Optional, Tuple import torch import torch.nn as nn from timm.models.featu...
23,446
43.323251
130
py
cmcl_vqa_pl
cmcl_vqa_pl-master/meter/modules/heads.py
import torch import torch.nn as nn import torch.nn.functional as F from transformers.models.bert.modeling_bert import BertPredictionHeadTransform class Pooler(nn.Module): def __init__(self, hidden_size): super().__init__() self.dense = nn.Linear(hidden_size, hidden_size) self.activation =...
1,257
27.590909
83
py
cmcl_vqa_pl
cmcl_vqa_pl-master/meter/modules/beit_helpers.py
import torch import json, os from transformers import BeitModel, BeitConfig, BeitForMaskedImageModeling def build_beit_model(original_config_dir, image_size): config = json.load(open(os.path.join(original_config_dir, 'config.json'), 'r')) if config['image_size'] == image_size: return BeitForMaskedImag...
1,649
42.421053
132
py
cmcl_vqa_pl
cmcl_vqa_pl-master/meter/modules/meter_clip_score.py
import torch import torch.nn as nn import pytorch_lightning as pl import numpy as np import clip from transformers.models.bert.modeling_bert import BertConfig, BertModel, BertForMaskedLM from .bert_model import BertCrossLayer from . import swin_transformer as swin from . import heads, objectives, meter_utils from .cli...
12,330
44.168498
138
py
cmcl_vqa_pl
cmcl_vqa_pl-master/meter/datasets/base_cv_dataset.py
import torch import os, io, random import pyarrow as pa import numpy as np from PIL import Image from ..transforms import keys_to_transforms class BaseCVDataset(torch.utils.data.Dataset): def __init__( self, data_dir: str, transform_keys: list, image_size: int, names: list,...
4,744
32.892857
111
py
cmcl_vqa_pl
cmcl_vqa_pl-master/meter/datasets/base_dataset.py
import random import torch import io import pyarrow as pa import os from PIL import Image from ..transforms import keys_to_transforms class BaseDataset(torch.utils.data.Dataset): def __init__( self, data_dir: str, transform_keys: list, image_size: int, names: list, ...
10,145
36.577778
111
py
cmcl_vqa_pl
cmcl_vqa_pl-master/meter/datasets/base_nlp_dataset.py
import torch from torch.utils.data import Dataset, random_split from datasets import load_from_disk class BaseNLPDataset(Dataset): def __init__(self, data_dir, split, max_text_len=512): super().__init__() self.data_dir = data_dir self.max_text_len = max_text_len dataset = load_fro...
3,425
40.780488
91
py
cmcl_vqa_pl
cmcl_vqa_pl-master/meter/datasets/rte_dataset.py
import os from .base_nlp_dataset import BaseNLPDataset import torch class RTEDataset(BaseNLPDataset): def __init__(self, data_dir, split, max_text_len=512): data_dir = os.path.join(data_dir, 'rte') super().__init__(data_dir, split, max_text_len) def __getitem__(self, index): data = sel...
1,514
37.846154
104
py
cmcl_vqa_pl
cmcl_vqa_pl-master/meter/transforms/transform.py
from .utils import ( inception_normalize, imagenet_normalize, MinMaxResize, ) from PIL import Image from torchvision import transforms from torchvision.transforms import Compose, Resize, CenterCrop, ToTensor, Normalize from .randaug import RandAugment from transformers import DetrFeatureExtractor from funct...
3,178
28.435185
96
py
cmcl_vqa_pl
cmcl_vqa_pl-master/meter/transforms/utils.py
from torchvision import transforms from PIL import Image class MinMaxResize: def __init__(self, shorter=800, longer=1333): self.min = shorter self.max = longer def __call__(self, x): w, h = x.size scale = self.min / min(w, h) if h < w: newh, neww = self.min...
1,792
27.919355
98
py
cmcl_vqa_pl
cmcl_vqa_pl-master/meter/transforms/randaug.py
# code in this file is adpated from rpmcruz/autoaugment # https://github.com/rpmcruz/autoaugment/blob/master/transformations.py import random import PIL, PIL.ImageOps, PIL.ImageEnhance, PIL.ImageDraw import numpy as np import torch from PIL import Image def ShearX(img, v): # [-0.3, 0.3] assert -0.3 <= v <= 0.3 ...
6,990
24.892593
134
py
ChineseGLUE
ChineseGLUE-master/baselines/models/xlnet/data_utils.py
# -*- coding: utf-8 -*- from __future__ import absolute_import from __future__ import division from __future__ import print_function import json import os import random from absl import flags import absl.logging as _logging # pylint: disable=unused-import import numpy as np import tensorflow as tf from prepro_u...
29,866
31.605895
80
py
ChineseGLUE
ChineseGLUE-master/baselines/models_pytorch/classifier_pytorch/run_classifier.py
# coding=utf-8 # Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team. # Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a cop...
29,378
55.173996
181
py
ChineseGLUE
ChineseGLUE-master/baselines/models_pytorch/classifier_pytorch/convert_albert_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,991
40.555556
110
py
ChineseGLUE
ChineseGLUE-master/baselines/models_pytorch/classifier_pytorch/convert_ernie_original_pad_checkpoint_to_pytorch.py
#!/usr/bin/env python # encoding: utf-8 import collections import os import sys import numpy as np import argparse import paddle.fluid as fluid import torch import json if not os.path.exists('ERNIE'): os.system('git clone https://github.com/PaddlePaddle/ERNIE.git') sys.path = ['./ERNIE'] + sys.path try: from m...
8,630
38.774194
119
py
ChineseGLUE
ChineseGLUE-master/baselines/models_pytorch/classifier_pytorch/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
ChineseGLUE
ChineseGLUE-master/baselines/models_pytorch/classifier_pytorch/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
ChineseGLUE
ChineseGLUE-master/baselines/models_pytorch/classifier_pytorch/tools/common.py
import os import random import torch import numpy as np import json import pickle import torch.nn as nn from collections import OrderedDict from pathlib import Path import logging logger = logging.getLogger() def print_config(config): info = "Running with the following configs:\n" for k, v in config.items(): ...
10,704
29.240113
128
py
ChineseGLUE
ChineseGLUE-master/baselines/models_pytorch/classifier_pytorch/processors/glue.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...
24,809
34.544413
130
py
ChineseGLUE
ChineseGLUE-master/baselines/models_pytorch/classifier_pytorch/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
ChineseGLUE
ChineseGLUE-master/baselines/models_pytorch/classifier_pytorch/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,082
53.484615
135
py
ChineseGLUE
ChineseGLUE-master/baselines/models_pytorch/classifier_pytorch/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,772
50.793269
296
py
ChineseGLUE
ChineseGLUE-master/baselines/models_pytorch/classifier_pytorch/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,864
49.237752
201
py
ChineseGLUE
ChineseGLUE-master/baselines/models_pytorch/classifier_pytorch/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...
43,409
52.06846
472
py
ChineseGLUE
ChineseGLUE-master/baselines/models_pytorch/classifier_pytorch/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,643
50.864348
187
py
ChineseGLUE
ChineseGLUE-master/baselines/models_pytorch/classifier_pytorch/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...
33,126
48.965309
148
py
ChineseGLUE
ChineseGLUE-master/baselines/models_pytorch/classifier_pytorch/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,836
48.57717
148
py
ChineseGLUE
ChineseGLUE-master/baselines/models_pytorch/classifier_pytorch/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...
22,451
43.636183
183
py
ChineseGLUE
ChineseGLUE-master/baselines/models_pytorch/classifier_pytorch/transformers/configuration_ctrl.py
# coding=utf-8 # Copyright 2018 Salesforce 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 at # # htt...
5,775
39.111111
120
py
ChineseGLUE
ChineseGLUE-master/baselines/models_pytorch/classifier_pytorch/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,622
34.763077
144
py
ChineseGLUE
ChineseGLUE-master/baselines/models_pytorch/classifier_pytorch/transformers/__init__.py
__version__ = "2.1.1" # 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...
5,761
58.402062
109
py
ChineseGLUE
ChineseGLUE-master/baselines/models_pytorch/classifier_pytorch/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
ChineseGLUE
ChineseGLUE-master/baselines/models_pytorch/classifier_pytorch/transformers/modeling_albert.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,163
49.810507
153
py