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 |
|---|---|---|---|---|---|---|
GRM | GRM-main/lib/train/train_script.py | # For import modules
import importlib
import os
from torch.nn import BCEWithLogitsLoss
from torch.nn.functional import l1_loss
# Distributed training related
from torch.nn.parallel import DistributedDataParallel as DDP
# Network related
from lib.models.grm import build_grm
# Forward propagation related
from lib.train... | 3,349 | 37.953488 | 123 | py |
GRM | GRM-main/lib/train/dataset/base_image_dataset.py | import torch.utils.data
from lib.train.data.image_loader import jpeg4py_loader
class BaseImageDataset(torch.utils.data.Dataset):
"""
Base class for image datasets.
"""
def __init__(self, name, root, image_loader=jpeg4py_loader):
"""
Args:
root: The root path to the datase... | 2,455 | 21.953271 | 119 | py |
GRM | GRM-main/lib/train/dataset/tracking_net.py | import os
import os.path
import random
from collections import OrderedDict
import numpy as np
import pandas
import torch
from lib.train.admin import env_settings
from lib.train.data import jpeg4py_loader
from .base_video_dataset import BaseVideoDataset
def list_sequences(root, set_ids):
"""
Lists all the vi... | 6,243 | 38.025 | 169 | py |
GRM | GRM-main/lib/train/dataset/lasot.py | import csv
import os
import os.path
import random
from collections import OrderedDict
import numpy as np
import pandas
import torch
from lib.train.admin import env_settings
from lib.train.data import jpeg4py_loader
from .base_video_dataset import BaseVideoDataset
class Lasot(BaseVideoDataset):
"""
LaSOT dat... | 6,579 | 38.401198 | 119 | py |
GRM | GRM-main/lib/train/dataset/got10k.py | import csv
import os
import os.path
import random
from collections import OrderedDict
import numpy as np
import pandas
import torch
from lib.train.admin import env_settings
from lib.train.data import jpeg4py_loader
from .base_video_dataset import BaseVideoDataset
class Got10k(BaseVideoDataset):
"""
GOT-10k ... | 7,530 | 40.607735 | 122 | py |
GRM | GRM-main/lib/train/dataset/coco.py | import os
import random
from collections import OrderedDict
import torch
from pycocotools.coco import COCO
from lib.train.admin import env_settings
from lib.train.data import jpeg4py_loader
from .base_image_dataset import BaseImageDataset
class MSCOCO(BaseImageDataset):
"""
The COCO object detection dataset... | 5,758 | 36.154839 | 120 | py |
GRM | GRM-main/lib/train/dataset/coco_seq.py | import os
import random
from collections import OrderedDict
import torch
from pycocotools.coco import COCO
from lib.train.admin import env_settings
from lib.train.data import jpeg4py_loader
from .base_video_dataset import BaseVideoDataset
class MSCOCOSeq(BaseVideoDataset):
"""
The COCO dataset. COCO is an i... | 6,401 | 36.22093 | 120 | py |
GRM | GRM-main/lib/train/dataset/base_video_dataset.py | import torch.utils.data
from lib.train.data.image_loader import jpeg4py_loader_w_failsafe
class BaseVideoDataset(torch.utils.data.Dataset):
"""
Base class for video datasets.
"""
def __init__(self, name, root, image_loader=jpeg4py_loader_w_failsafe):
"""
Args:
root: The r... | 3,137 | 23.138462 | 119 | py |
GRM | GRM-main/lib/train/actors/grm.py | import torch
from lib.utils.box_ops import box_cxcywh_to_xyxy, box_xywh_to_xyxy
from . import BaseActor
from ...utils.heapmap_utils import generate_heatmap
from ...utils.mask_utils import generate_mask_cond
class GRMActor(BaseActor):
"""
Actor for training GRM models.
"""
def __init__(self, net, obj... | 5,064 | 40.859504 | 120 | py |
GRM | GRM-main/lib/train/admin/tensorboard.py | import os
from collections import OrderedDict
try:
from torch.utils.tensorboard import SummaryWriter
except:
print('you are using tensorboardX instead sis you have a too old pytorch version')
from tensorboardX import SummaryWriter
class TensorboardWriter:
def __init__(self, directory, loader_names):
... | 1,169 | 39.344828 | 117 | py |
GRM | GRM-main/lib/train/admin/multigpu.py | import torch.nn as nn
# Here we use DistributedDataParallel(DDP) rather than DataParallel(DP) for multiple GPUs training
def is_multi_gpu(net):
return isinstance(net, (MultiGPU, nn.parallel.distributed.DistributedDataParallel))
class MultiGPU(nn.parallel.distributed.DistributedDataParallel):
def __getattr... | 469 | 25.111111 | 98 | py |
GRM | GRM-main/lib/train/data/processing_utils.py | import math
import cv2 as cv
import numpy as np
import torch
import torch.nn.functional as F
# Modified from the original test implementation
# Replace cv.BORDER_REPLICATE with cv.BORDER_CONSTANT
# Add a variable called att_mask for computing attention and positional encoding later
def sample_target(im, target_bb,... | 6,794 | 36.541436 | 118 | py |
GRM | GRM-main/lib/train/data/sampler.py | import random
import torch.utils.data
from lib.utils import TensorDict
def no_processing(data):
return data
class TrackingSampler(torch.utils.data.Dataset):
"""
Class responsible for sampling frames from training sequences to form batches.
The sampling is done in the following ways. First a datas... | 17,994 | 48.986111 | 122 | py |
GRM | GRM-main/lib/train/data/processing.py | import torch
import torch.nn.functional as F
import torchvision.transforms as transforms
import lib.train.data.processing_utils as prutils
from lib.utils import TensorDict
def stack_tensors(x):
if isinstance(x, (list, tuple)) and isinstance(x[0], torch.Tensor):
return torch.stack(x)
return x
class ... | 8,634 | 51.333333 | 124 | py |
GRM | GRM-main/lib/train/data/bounding_box_utils.py | import torch
def rect_to_rel(bb, sz_norm=None):
"""
Convert standard rectangular parametrization of the bounding box [x, y, w, h] to
relative parametrization [cx/sw, cy/sh, log(w), log(h)], where [cx, cy] is the center coordinate.
Args:
bb: N x 4 tensor of boxes.
sz_norm: [N] x 2 tens... | 3,018 | 28.598039 | 104 | py |
GRM | GRM-main/lib/train/data/loader.py | import collections
import importlib
import torch
import torch.utils.data.dataloader
from torch._six import string_classes
from lib.utils import TensorDict, TensorList
def _check_use_shared_memory():
if hasattr(torch.utils.data.dataloader, '_use_shared_memory'):
return getattr(torch.utils.data.dataloader... | 9,442 | 47.178571 | 119 | py |
GRM | GRM-main/lib/train/data/transforms.py | import random
import cv2 as cv
import numpy as np
import torch
import torchvision.transforms.functional as tvisf
class Transform:
"""
A set of transformations, used for e.g. data augmentation.
Args:
transforms: An arbitrary number of transformations, derived from the TransformBase class.
... | 12,764 | 32.680739 | 133 | py |
GRM | GRM-main/lib/train/trainers/base_trainer.py | import glob
import os
import traceback
import torch
from torch.utils.data.distributed import DistributedSampler
from lib.train.admin import multigpu
class BaseTrainer:
"""
Base trainer class. Contains functions for training and saving/loading checkpoints.
Trainer classes should inherit from this one and... | 12,125 | 40.813793 | 119 | py |
GRM | GRM-main/lib/train/trainers/ltr_trainer.py | import os
import time
from collections import OrderedDict
import torch
from torch.utils.data.distributed import DistributedSampler
from lib.train.admin import AverageMeter, StatValue
from lib.train.admin import TensorboardWriter
from lib.train.data.wandb_logger import WandbWriter
from lib.train.trainers import BaseTr... | 7,957 | 39.191919 | 112 | py |
GRM | GRM-main/lib/utils/heapmap_utils.py | import numpy as np
import torch
def generate_heatmap(bboxes, patch_size=320, stride=16):
"""
Generate ground truth heatmap same as CenterNet.
Args:
bboxes (torch.Tensor): Shape of [num_search, bs, 4].
Returns:
gaussian_maps: List of generated heatmap.
"""
gaussian_maps = lis... | 5,637 | 35.61039 | 98 | py |
GRM | GRM-main/lib/utils/misc.py | """
Misc functions, including distributed helpers.
Mostly copy-paste from torchvision references.
"""
import datetime
import os
import pickle
import subprocess
import time
from collections import defaultdict, deque
from typing import Optional, List
import torch
import torch.distributed as dist
# Needed due to empty ... | 14,878 | 31.06681 | 132 | py |
GRM | GRM-main/lib/utils/merge.py | import torch
def merge_template_search(inp_list, return_search=False, return_template=False):
# Note: search region related features must be in the last place
seq_dict = {'feat': torch.cat([x['feat'] for x in inp_list], dim=0),
'mask': torch.cat([x['mask'] for x in inp_list], dim=1),
... | 1,265 | 37.363636 | 89 | py |
GRM | GRM-main/lib/utils/variable_hook.py | import torch
from bytecode import Bytecode, Instr
class get_local(object):
cache = dict()
is_activate = False
def __init__(self, varname):
self.varname = varname
def __call__(self, func):
if not type(self).is_activate:
return func
type(self).cache[func.__qualname... | 1,513 | 29.28 | 110 | py |
GRM | GRM-main/lib/utils/focal_loss.py | from abc import ABC
import torch
import torch.nn as nn
import torch.nn.functional as F
class FocalLoss(nn.Module, ABC):
def __init__(self, alpha=2, beta=4):
super(FocalLoss, self).__init__()
self.alpha = alpha
self.beta = beta
def forward(self, prediction, target):
positive_i... | 2,303 | 33.909091 | 116 | py |
GRM | GRM-main/lib/utils/box_ops.py | 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_c + 0.5 * h)]
return torch.stack(b, dim=-1)
def box_xywh_to_xyxy(x):
x1, y1, w, h = x.unbind(-1)
b = [x1, y1, x1 + ... | 2,513 | 22.716981 | 57 | py |
GRM | GRM-main/lib/utils/mask_utils.py | import torch
def generate_bbox_mask(bbox_mask, bbox):
b, h, w = bbox_mask.shape
for i in range(b):
bbox_i = bbox[i].cpu().tolist()
bbox_mask[i, max(int(bbox_i[1]), 0):min(int(bbox_i[1] + bbox_i[3] + 1), h),
max(int(bbox_i[0]), 0):min(int(bbox_i[0] + bbox_i[2] + 1), w)] = 1
return b... | 707 | 32.714286 | 108 | py |
GRM | GRM-main/lib/utils/tensor.py | import copy
import functools
from collections import OrderedDict
import torch
class TensorDict(OrderedDict):
"""
Container mainly used for dicts of torch tensors. Extends OrderedDict with pytorch functionality.
"""
def concat(self, other):
"""
Concatenates two dicts without copying i... | 8,332 | 32.06746 | 107 | py |
GRM | GRM-main/tracking/test.py | import argparse
import os
import sys
import warnings
import torch
prj_path = os.path.join(os.path.dirname(__file__), '..')
if prj_path not in sys.path:
sys.path.append(prj_path)
warnings.filterwarnings('ignore')
from lib.test.evaluation import get_dataset
from lib.test.evaluation.running import run_dataset
from... | 2,765 | 34.922078 | 112 | py |
GRM | GRM-main/tracking/train.py | import argparse
import os
import random
import warnings
warnings.filterwarnings('ignore')
def parse_args():
"""
Args for training.
"""
parser = argparse.ArgumentParser(description='parse args for training')
# For train
parser.add_argument('--script', type=str, default='grm', help='training s... | 2,962 | 50.086207 | 123 | py |
smiles-transformer | smiles-transformer-master/smiles_transformer/enumerator.py | #Experimental Class for Smiles Enumeration, Iterator and SmilesIterator adapted from Keras 1.2.2
from rdkit import Chem
import numpy as np
import threading
class Iterator(object):
"""Abstract base class for data iterators.
# Arguments
n: Integer, total number of samples in the dataset to loop over.
... | 8,361 | 36.330357 | 146 | py |
smiles-transformer | smiles-transformer-master/smiles_transformer/pretrain_trfm.py | import argparse
import math
import os
import numpy as np
import pandas as pd
import torch
from torch import nn
from torch import optim
from torch.autograd import Variable
from torch.nn import functional as F
from torch.utils.data import DataLoader
from tqdm import tqdm
from build_vocab import WordVocab
from dataset i... | 7,351 | 40.772727 | 124 | py |
smiles-transformer | smiles-transformer-master/smiles_transformer/utils.py | import torch
import math
import torch.nn as nn
from rdkit import Chem
from rdkit import rdBase
rdBase.DisableLog('rdApp.*')
# Split SMILES into words
def split(sm):
'''
function: Split SMILES into words. Care for Cl, Br, Si, Se, Na etc.
input: A SMILES
output: A string with space between words
'''
... | 5,877 | 29.14359 | 100 | py |
smiles-transformer | smiles-transformer-master/smiles_transformer/dataset.py | import random
import pandas as pd
import torch
from torch.utils.data import Dataset, DataLoader
from enumerator import SmilesEnumerator
from utils import split
PAD = 0
MAX_LEN = 220
class Randomizer(object):
def __init__(self):
self.sme = SmilesEnumerator()
def __call__(self, sm):
sm_r ... | 1,573 | 26.614035 | 84 | py |
smiles-transformer | smiles-transformer-master/smiles_transformer/pretrain_rnn.py | import argparse
import random
import numpy as np
from tqdm import tqdm
from torch.utils.data import DataLoader
import os
import math
import argparse
import torch
from torch import nn
from torch import optim
from torch.autograd import Variable
from torch.nn.utils import clip_grad_norm_
from torch.nn import functional as... | 10,694 | 44.901288 | 124 | py |
VLI_SDRO | VLI_SDRO-main/Models/LXMERT/src/param_dro.py | # coding=utf-8
# Copyleft 2019 project LXRT.
import argparse
import random
import numpy as np
import torch
def get_optimizer(optim):
# Bind the optimizer
if optim == 'rms':
print("Optimizer: Using RMSProp")
optimizer = torch.optim.RMSprop
elif optim == 'adam':
print("Optimizer: U... | 4,918 | 41.773913 | 117 | py |
VLI_SDRO | VLI_SDRO-main/Models/LXMERT/src/vqa_aug.py | # coding=utf-8
# Copyleft 2019 project LXRT.
import os
import collections
import torch
import torch.nn as nn
from torch.utils.data.dataloader import DataLoader
from tqdm import tqdm
from param import args
from pretrain.qa_answer_table import load_lxmert_qa
from tasks.vqa_model import VQAModel
from tasks.vqa_data_aug... | 8,728 | 35.987288 | 126 | py |
VLI_SDRO | VLI_SDRO-main/Models/LXMERT/src/param.py | # coding=utf-8
# Copyleft 2019 project LXRT.
import argparse
import random
import numpy as np
import torch
def get_optimizer(optim):
# Bind the optimizer
if optim == 'rms':
print("Optimizer: Using RMSProp")
optimizer = torch.optim.RMSprop
elif optim == 'adam':
print("Optimizer: U... | 5,092 | 42.529915 | 117 | py |
VLI_SDRO | VLI_SDRO-main/Models/LXMERT/src/pretrain/qa_answer_table.py | # coding=utf-8
# Copyleft 2019 project LXRT.
import json
import torch
class AnswerTable:
ANS_CONVERT = {
"a man": "man",
"the man": "man",
"a woman": "woman",
"the woman": "woman",
'one': '1',
'two': '2',
'three': '3',
'four': '4',
'five': '... | 5,015 | 30.54717 | 85 | py |
VLI_SDRO | VLI_SDRO-main/Models/LXMERT/src/pretrain/lxmert_data.py | # coding=utf-8
# Copyleft 2019 project LXRT.
from collections import defaultdict
import json
import random
import numpy as np
from torch.utils.data import Dataset
from param import args
from pretrain.qa_answer_table import AnswerTable
from utils import load_obj_tsv
TINY_IMG_NUM = 500
FAST_IMG_NUM = 5000
Split2ImgF... | 8,847 | 33.5625 | 89 | py |
VLI_SDRO | VLI_SDRO-main/Models/LXMERT/src/pretrain/lxmert_pretrain.py | # coding=utf-8
# Copyleft 2019 project LXRT.
import collections
import os
import random
from tqdm import tqdm
import numpy as np
import torch
import torch.nn as nn
from torch.utils.data import DataLoader
from param import args
from pretrain.lxmert_data import InputExample, LXMERTDataset, LXMERTTorchDataset, LXMERTEv... | 15,616 | 34.818807 | 110 | py |
VLI_SDRO | VLI_SDRO-main/Models/LXMERT/src/lxrt/optimization.py | # coding=utf-8
# Copyright 2019 project LXRT
# 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:/... | 7,927 | 42.801105 | 141 | py |
VLI_SDRO | VLI_SDRO-main/Models/LXMERT/src/lxrt/entry.py | # coding=utf-8
# Copyright 2019 project LXRT.
# 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 ... | 5,278 | 32.624204 | 100 | py |
VLI_SDRO | VLI_SDRO-main/Models/LXMERT/src/lxrt/modeling.py | # coding=utf-8
# Copyright 2019 project LXRT.
# 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 ... | 43,875 | 42.0579 | 136 | py |
VLI_SDRO | VLI_SDRO-main/Models/LXMERT/src/lxrt/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.
"""
import json
import logging
import os
import shutil
import tempfile
from functools import wraps
from hashlib import sha256
import sys
from i... | 8,209 | 32.104839 | 112 | py |
VLI_SDRO | VLI_SDRO-main/Models/LXMERT/src/tasks/vqa_data.py | # coding=utf-8
# Copyleft 2019 project LXRT.
import json
import os
import pickle
import numpy as np
import torch
from torch.utils.data import Dataset
from param import args
from utils import load_obj_tsv
# Load part of the dataset for fast checking.
# Notice that here is the number of images instead of the number o... | 6,548 | 30.037915 | 99 | py |
VLI_SDRO | VLI_SDRO-main/Models/LXMERT/src/tasks/gqa_model.py | # coding=utf-8
# Copyleft 2019 project LXRT.
import torch.nn as nn
from param import args
from lxrt.entry import LXRTEncoder
from lxrt.modeling import BertLayerNorm, GeLU
# Max length including <bos> and <eos>
MAX_GQA_LENGTH = 20
class GQAModel(nn.Module):
def __init__(self, num_answers):
super().__ini... | 1,224 | 25.630435 | 70 | py |
VLI_SDRO | VLI_SDRO-main/Models/LXMERT/src/tasks/nlvr2_dro_2.py | # coding=utf-8
# Copyleft 2019 project LXRT.
import os
import collections
import json
from tqdm import tqdm
import torch
import torch.nn as nn
from torch.utils.data.dataloader import DataLoader
from lxrt.optimization import BertAdam
from param import args
from tasks.nlvr2_model import NLVR2Model
from tasks.nlvr2_data_... | 15,122 | 38.692913 | 144 | py |
VLI_SDRO | VLI_SDRO-main/Models/LXMERT/src/tasks/vqa_dro.py | # coding=utf-8
# Copyleft 2019 project LXRT.
import os
import collections
import operator
import torch
import torch.nn as nn
from torch.utils.data.dataloader import DataLoader
from tqdm import tqdm
from param import args
from pretrain.qa_answer_table import load_lxmert_qa
from tasks.vqa_model import VQAModel
from tas... | 18,468 | 38.212314 | 126 | py |
VLI_SDRO | VLI_SDRO-main/Models/LXMERT/src/tasks/nlvr2_data_dro.py | # coding=utf-8
# Copyleft 2019 project LXRT.
import json
import random
import numpy as np
from torch.utils.data import Dataset
from param import args
from utils import load_obj_tsv
# Load part of the dataset for fast checking.
# Notice that here is the number of images instead of the number of data,
# which means al... | 11,625 | 33.912913 | 153 | py |
VLI_SDRO | VLI_SDRO-main/Models/LXMERT/src/tasks/nlvr2_data_dro_2.py | # coding=utf-8
# Copyleft 2019 project LXRT.
import json
import random
import numpy as np
from torch.utils.data import Dataset
from param import args
from utils import load_obj_tsv
# Load part of the dataset for fast checking.
# Notice that here is the number of images instead of the number of data,
# which means al... | 8,531 | 33.967213 | 155 | py |
VLI_SDRO | VLI_SDRO-main/Models/LXMERT/src/tasks/gqa_data.py | # coding=utf-8
# Copyleft 2019 project LXRT.
import json
import numpy as np
import torch
from torch.utils.data import Dataset
from param import args
from utils import load_obj_tsv
# Load part of the dataset for fast checking.
# Notice that here is the number of images instead of the number of data,
# which means al... | 5,985 | 29.697436 | 119 | py |
VLI_SDRO | VLI_SDRO-main/Models/LXMERT/src/tasks/vqa_model.py | # coding=utf-8
# Copyleft 2019 project LXRT.
import torch.nn as nn
from param import args
from lxrt.entry import LXRTEncoder
from lxrt.modeling import BertLayerNorm, GeLU
# Max length including <bos> and <eos>
MAX_VQA_LENGTH = 20
class VQAModel(nn.Module):
def __init__(self, num_answers):
super().__ini... | 1,298 | 24.98 | 70 | py |
VLI_SDRO | VLI_SDRO-main/Models/LXMERT/src/tasks/vqa.py | # coding=utf-8
# Copyleft 2019 project LXRT.
import os
import collections
import torch
import torch.nn as nn
from torch.utils.data.dataloader import DataLoader
from tqdm import tqdm
from param import args
from pretrain.qa_answer_table import load_lxmert_qa
from tasks.vqa_model import VQAModel
from tasks.vqa_data imp... | 7,794 | 35.255814 | 98 | py |
VLI_SDRO | VLI_SDRO-main/Models/LXMERT/src/tasks/nlvr2_data.py | # coding=utf-8
# Copyleft 2019 project LXRT.
import json
import random
import numpy as np
from torch.utils.data import Dataset
from param import args
from utils import load_obj_tsv
# Load part of the dataset for fast checking.
# Notice that here is the number of images instead of the number of data,
# which means al... | 6,818 | 32.263415 | 157 | py |
VLI_SDRO | VLI_SDRO-main/Models/LXMERT/src/tasks/vqa_data_dro.py | # coding=utf-8
# Copyleft 2019 project LXRT.
import json
import os
import pickle
import random
import numpy as np
import torch
from torch.utils.data import Dataset
from param import args
from utils import load_obj_tsv
VQA_DATA_ROOT = '/scratch/achaud39/VQA/'
MSCOCO_IMGFEAT_ROOT = '/scratch/achaud39/VQA/data/mscoco... | 9,284 | 32.886861 | 99 | py |
VLI_SDRO | VLI_SDRO-main/Models/LXMERT/src/tasks/nlvr2.py | # coding=utf-8
# Copyleft 2019 project LXRT.
import os
import collections
from tqdm import tqdm
import torch
import torch.nn as nn
from torch.utils.data.dataloader import DataLoader
from param import args
from tasks.nlvr2_model import NLVR2Model
from tasks.nlvr2_data import NLVR2Dataset, NLVR2TorchDataset, NLVR2Eval... | 6,553 | 34.048128 | 98 | py |
VLI_SDRO | VLI_SDRO-main/Models/LXMERT/src/tasks/vqa_data_aug.py | # coding=utf-8
# Copyleft 2019 project LXRT.
import json
import os
import pickle
import random
import numpy as np
import torch
from torch.utils.data import Dataset
from param import args
from utils import load_obj_tsv
# Load part of the dataset for fast checking.
# Notice that here is the number of images instead of... | 6,933 | 30.09417 | 99 | py |
VLI_SDRO | VLI_SDRO-main/Models/LXMERT/src/tasks/nlvr2_model.py | # coding=utf-8
# Copyleft 2019 project LXRT.
import torch.nn as nn
from lxrt.modeling import GeLU, BertLayerNorm
from lxrt.entry import LXRTEncoder
from param import args
class NLVR2Model(nn.Module):
def __init__(self):
super().__init__()
self.lxrt_encoder = LXRTEncoder(
args,
... | 1,773 | 30.678571 | 94 | py |
VLI_SDRO | VLI_SDRO-main/Models/LXMERT/src/tasks/vqa_aug.py | # coding=utf-8
# Copyleft 2019 project LXRT.
import os
import collections
import torch
import torch.nn as nn
from torch.utils.data.dataloader import DataLoader
from tqdm import tqdm
from param import args
from pretrain.qa_answer_table import load_lxmert_qa
from tasks.vqa_model import VQAModel
from tasks.vqa_data_aug... | 7,798 | 35.274419 | 98 | py |
VLI_SDRO | VLI_SDRO-main/Models/LXMERT/src/tasks/gqa.py | # coding=utf-8
# Copyleft 2019 project LXRT.
import os
import collections
import torch
from tqdm import tqdm
import torch.nn as nn
from torch.utils.data.dataloader import DataLoader
from param import args
from pretrain.qa_answer_table import load_lxmert_qa
from tasks.gqa_model import GQAModel
from tasks.gqa_data imp... | 7,680 | 35.402844 | 98 | py |
VLI_SDRO | VLI_SDRO-main/Models/LXMERT/src/tasks/nlvr2_dro.py | # coding=utf-8
# Copyleft 2019 project LXRT.
import os
import json
import collections
from tqdm import tqdm
import torch
import torch.nn as nn
from torch.utils.data.dataloader import DataLoader
from param import args
from tasks.nlvr2_model import NLVR2Model
from tasks.nlvr2_data_dro import NLVR2Dataset_DRO, NLVR2Tor... | 13,480 | 37.850144 | 129 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/pretrain.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
UNITER pre-training
"""
import argparse
from collections import defaultdict
import json
import math
import os
from os.path import exists, join
from time import time
import torch
from torch.utils.data import DataLoader
from torch.nn import functi... | 25,777 | 39.090202 | 79 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/train_itm.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
UNITER finetuning for Image-Text Retrieval
"""
import argparse
import os
from os.path import exists, join
from time import time
import torch
from torch.nn.utils import clip_grad_norm_
from torch.utils.data import DataLoader, ConcatDataset
from a... | 17,930 | 42.627737 | 79 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/prepro.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
preprocess NLVR annotations into LMDB
"""
import argparse
import json
import os
from os.path import exists
from cytoolz import curry
from tqdm import tqdm
from pytorch_pretrained_bert import BertTokenizer
from data.data import open_lmdb
@curr... | 3,426 | 32.598039 | 78 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/train_ve_adv.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
UNITER finetuning for SNLI-VE
"""
import argparse
import json
import os
from os.path import exists, join
import pickle
from time import time
import torch
from torch.nn import functional as F
from torch.nn.utils import clip_grad_norm_
from torch.... | 27,397 | 47.925 | 134 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/inf_vcr.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
run inference of VCR for submission
"""
import argparse
import json
import os
from os.path import exists
import pandas as pd
from time import time
import torch
from torch.nn import functional as F
from torch.utils.data import DataLoader
from ap... | 10,903 | 36.993031 | 78 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/train_vcr_adv.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
UNITER finetuning for VCR
"""
import argparse
import json
import os
from os.path import abspath, dirname, exists, join
from time import time
import torch
from torch.nn import functional as F
from torch.nn.utils import clip_grad_norm_
from torch.... | 32,988 | 44.88178 | 98 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/inf_vqa.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
run inference of VQA for submission
"""
import argparse
import json
import os
from os.path import exists
from time import time
from torch.nn import functional as F
import torch
from torch.utils.data import DataLoader
from apex import amp
from ho... | 8,340 | 36.236607 | 121 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/inf_nlvr2.py | """run inference of NLVR2 (single GPU only)"""
import argparse
import json
import os
from os.path import exists
from time import time
import numpy as np
import torch
from torch.utils.data import DataLoader
from torch.nn import functional as F
from apex import amp
from horovod import torch as hvd
from tqdm import tqdm ... | 6,317 | 38.4875 | 77 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/inf_itm.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
run inference for Image Text Retrieval
"""
import argparse
import json
import os
from os.path import exists
import pickle
from time import time
import torch
from torch.utils.data import DataLoader
from apex import amp
from horovod import torch ... | 6,482 | 38.290909 | 79 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/train_nlvr2_adv.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
UNITER finetuning for NLVR2
"""
import argparse
import os
from os.path import exists, join
from time import time
import torch
from torch.nn import functional as F
from torch.nn.utils import clip_grad_norm_
from torch.utils.data import DataLoader... | 27,802 | 47.185442 | 134 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/train_vqa_adv_stat.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
UNITER finetuning for VQA
"""
import argparse
import json
import os
from os.path import abspath, dirname, exists, join
from time import time
import torch
from torch.nn import functional as F
from torch.nn.utils import clip_grad_norm_
from torch.... | 33,490 | 45.906162 | 134 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/train_itm_hard_negatives.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
UNITER finetuning for Image-Text Retrieval with hard negatives
"""
import argparse
import os
from os.path import exists, join
from time import time
import torch
from torch.nn.utils import clip_grad_norm_
from torch.utils.data import DataLoader, ... | 19,146 | 42.417234 | 79 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/train_vqa_adv.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
UNITER finetuning for VQA
"""
import argparse
import json
import os
from os.path import abspath, dirname, exists, join
from time import time
import torch
from torch.nn import functional as F
from torch.nn.utils import clip_grad_norm_
from torch.... | 27,510 | 47.606007 | 134 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/train_nlvr2_adv_stat.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
UNITER finetuning for NLVR2
"""
import argparse
import os
from os.path import exists, join
from time import time
import torch
from torch.nn import functional as F
from torch.nn.utils import clip_grad_norm_
from torch.utils.data import DataLoader... | 35,045 | 45.978552 | 134 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/optim/misc.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
Misc lr helper
"""
from torch.optim import Adam, Adamax
from .adamw import AdamW
def build_optimizer(model, opts):
param_optimizer = list(model.named_parameters())
no_decay = ['bias', 'LayerNorm.bias', 'LayerNorm.weight']
optimizer... | 1,037 | 27.833333 | 65 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/optim/adamw.py | """
AdamW optimizer (weight decay fix)
copied from hugginface (https://github.com/huggingface/transformers).
"""
import math
import torch
from torch.optim import Optimizer
class AdamW(Optimizer):
""" Implements Adam algorithm with weight decay fix.
Parameters:
lr (float): learning rate. Default 1e-3.... | 4,450 | 41.798077 | 79 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/scripts/convert_ckpt.py | import sys
from collections import OrderedDict
import torch
bert_ckpt, output_ckpt = sys.argv[1:]
bert = torch.load(bert_ckpt)
uniter = OrderedDict()
for k, v in bert.items():
uniter[k.replace('bert', 'uniter')] = v
torch.save(uniter, output_ckpt)
| 256 | 17.357143 | 43 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/utils/misc.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
Misc utilities
"""
import json
import random
import sys
import torch
import numpy as np
from utils.logger import LOGGER
class NoOp(object):
""" useful for distributed training No-Ops """
def __getattr__(self, name):
return sel... | 1,507 | 20.239437 | 70 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/utils/save.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
saving utilities
"""
import json
import os
from os.path import abspath, dirname, exists, join
import subprocess
import torch
from utils.logger import LOGGER
def save_training_meta(args):
if args.rank > 0:
return
if not exists... | 2,734 | 35.959459 | 73 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/utils/itm_eval.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
Image Text Retrieval evaluation helper
"""
from time import time
import torch
from horovod import torch as hvd
from tqdm import tqdm
from .logger import LOGGER
from .misc import NoOp
from .distributed import all_gather_list
@torch.no_grad()
d... | 3,661 | 30.843478 | 72 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/utils/distributed.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
distributed API using Horovod
Modified from OpenNMT's native pytorch distributed utils
(https://github.com/OpenNMT/OpenNMT-py)
"""
import math
import pickle
import torch
from horovod import torch as hvd
def all_reduce_and_rescale_tensors(tenso... | 6,296 | 28.985714 | 77 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/data/vcr.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
VCR dataset
"""
import copy
import json
import torch
from torch.nn.utils.rnn import pad_sequence
from toolz.sandbox import unzip
from cytoolz import concat
from .data import (DetectFeatTxtTokDataset, TxtTokLmdb, DetectFeatLmdb,
... | 11,651 | 37.582781 | 82 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/data/mlm.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
MLM datasets
"""
import random
import torch
from torch.nn.utils.rnn import pad_sequence
from toolz.sandbox import unzip
from .data import (DetectFeatTxtTokDataset, TxtTokLmdb,
pad_tensors, get_gather_index)
def random_word(... | 4,551 | 32.226277 | 79 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/data/sampler.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
sampler for length bucketing (batch by tokens)
"""
import random
from torch.utils.data import Sampler
from cytoolz import partition_all
class TokenBucketSampler(Sampler):
def __init__(self, lens, bucket_size, batch_size,
d... | 2,031 | 33.440678 | 75 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/data/vqa_stat.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
VQA dataset
"""
import torch
from torch.nn.utils.rnn import pad_sequence
from toolz.sandbox import unzip
import json
import random
import copy
from os.path import abspath, dirname, exists, join
from .data_stat import DetectFeatTxtTokDataset, pad_... | 9,243 | 34.015152 | 139 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/data/mrm.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
MRM Datasets
"""
import random
import torch
from torch.nn.utils.rnn import pad_sequence
from toolz.sandbox import unzip
from .data import DetectFeatTxtTokDataset, pad_tensors, get_gather_index
def _get_img_mask(mask_prob, num_bb):
img_mask... | 7,228 | 34.965174 | 79 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/data/vqa.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
VQA dataset
"""
import torch
from torch.nn.utils.rnn import pad_sequence
from toolz.sandbox import unzip
import json
from .data import DetectFeatTxtTokDataset, pad_tensors, get_gather_index
ans2label = json.load(open('/src/utils/ans2label.json'... | 4,588 | 31.090909 | 78 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/data/data.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
Dataset interfaces
"""
from collections import defaultdict
from contextlib import contextmanager
import io
import json
from os.path import exists
import random
import numpy as np
import torch
from torch.utils.data import Dataset, ConcatDataset
im... | 11,383 | 31.158192 | 78 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/data/data_stat.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
Dataset interfaces
"""
from collections import defaultdict
from contextlib import contextmanager
import io
import json
from os.path import exists
import numpy as np
import torch
from torch.utils.data import Dataset, ConcatDataset
import horovod.... | 12,314 | 31.070313 | 78 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/data/nlvr2.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
NLVR2 dataset
"""
import copy
import torch
from torch.nn.utils.rnn import pad_sequence
from toolz.sandbox import unzip
from cytoolz import concat
from .data import (DetectFeatTxtTokDataset, TxtTokLmdb, DetectFeatLmdb,
get_ids... | 7,623 | 32.004329 | 76 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/data/loader.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
A prefetch loader to speedup data loading
Modified from Nvidia Deep Learning Examples
(https://github.com/NVIDIA/DeepLearningExamples/tree/master/PyTorch).
"""
import random
import torch
from torch.utils.data import DataLoader
from utils.distri... | 4,747 | 32.202797 | 79 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/data/nlvr2_stat.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
NLVR2 dataset
"""
import copy
import torch
import random
from torch.nn.utils.rnn import pad_sequence
from toolz.sandbox import unzip
from cytoolz import concat
from .data import (DetectFeatTxtTokDataset, TxtTokLmdb, DetectFeatLmdb,
... | 11,696 | 36.854369 | 141 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/data/itm.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
Itm dataset
"""
from collections import defaultdict
import copy
import random
import torch
from torch.nn.utils.rnn import pad_sequence
from toolz.sandbox import unzip
from cytoolz import concat
import numpy as np
from .data import (DetectFeatTx... | 16,959 | 35.162047 | 79 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/model/vcr.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
Uniter for VCR model
"""
from collections import defaultdict
from torch import nn
from torch.nn import functional as F
from apex.normalization.fused_layer_norm import FusedLayerNorm as LayerNorm
# from .layer import GELU
from .model import (
... | 3,208 | 39.1125 | 80 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/model/pretrain.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
UNITER for pretraining
"""
from collections import defaultdict
import torch
from torch import nn
from torch.nn import functional as F
from apex.normalization.fused_layer_norm import FusedLayerNorm as LayerNorm
from .layer import GELU, BertOnlyM... | 10,155 | 43.156522 | 78 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/model/layer.py | """
BERT layers from the huggingface implementation
(https://github.com/huggingface/transformers)
"""
# coding=utf-8
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the... | 9,378 | 39.081197 | 104 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/model/model.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
Pytorch modules
some classes are modified from HuggingFace
(https://github.com/huggingface/transformers)
"""
import copy
import json
import logging
from io import open
import torch
from torch import nn
from apex.normalization.fused_layer_norm im... | 17,010 | 42.730077 | 81 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/model/vqa.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
Uniter for VQA model
"""
from collections import defaultdict
from torch import nn
from torch.nn import functional as F
from apex.normalization.fused_layer_norm import FusedLayerNorm as LayerNorm
from .layer import GELU
from .model import Uniter... | 2,092 | 36.375 | 75 | py |
VLI_SDRO | VLI_SDRO-main/Models/VILLA/model/nlvr2.py | """
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
Uniter for NLVR2 model
"""
from collections import defaultdict
import torch
from torch import nn
from torch.nn import functional as F
from .model import UniterPreTrainedModel, UniterModel
from .attention import MultiheadAttention
class Uniter... | 8,737 | 41.009615 | 76 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.