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 |
|---|---|---|---|---|---|---|
transformers | transformers-main/utils/check_dummies.py | # coding=utf-8
# Copyright 2020 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... | 6,221 | 35.816568 | 118 | py |
transformers | transformers-main/utils/check_table.py | # coding=utf-8
# Copyright 2020 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... | 7,490 | 40.159341 | 116 | py |
transformers | transformers-main/utils/test_module/custom_modeling.py | import torch
from transformers import PreTrainedModel
from .custom_configuration import CustomConfig, NoSuperInitConfig
class CustomModel(PreTrainedModel):
config_class = CustomConfig
def __init__(self, config):
super().__init__(config)
self.linear = torch.nn.Linear(config.hidden_size, conf... | 772 | 21.735294 | 77 | py |
RWKV-LM | RWKV-LM-main/RWKV-v4/verify.py | ########################################################################################################
# The RWKV Language Model - https://github.com/BlinkDL/RWKV-LM
########################################################################################################
# this is for verifying the results of differe... | 3,441 | 36.824176 | 228 | py |
RWKV-LM | RWKV-LM-main/RWKV-v4/run.py | ########################################################################################################
# The RWKV Language Model - https://github.com/BlinkDL/RWKV-LM
########################################################################################################
import numpy as np
import math, os
import time... | 5,528 | 35.86 | 228 | py |
RWKV-LM | RWKV-LM-main/RWKV-v4/train.py | ########################################################################################################
# The RWKV Language Model - https://github.com/BlinkDL/RWKV-LM
########################################################################################################
import os
import logging, types
from src.utils... | 12,277 | 42.69395 | 204 | py |
RWKV-LM | RWKV-LM-main/RWKV-v4/src/model_run.py | ########################################################################################################
# The RWKV Language Model - https://github.com/BlinkDL/RWKV-LM
########################################################################################################
import types
import copy
import torch
import m... | 14,599 | 36.150127 | 148 | py |
RWKV-LM | RWKV-LM-main/RWKV-v4/src/utils.py | ########################################################################################################
# The RWKV Language Model - https://github.com/BlinkDL/RWKV-LM
########################################################################################################
import os
try:
NUM_GPUS = int(os.environ['... | 5,626 | 35.538961 | 104 | py |
RWKV-LM | RWKV-LM-main/RWKV-v4/src/model.py | ########################################################################################################
# The RWKV Language Model - https://github.com/BlinkDL/RWKV-LM
########################################################################################################
import math, os
import numpy as np
import logg... | 15,730 | 36.906024 | 198 | py |
RWKV-LM | RWKV-LM-main/RWKV-v4/src/binidx.py | from lib2to3.pgen2 import token
import os
import torch
import numpy as np
import shutil
import struct
from functools import lru_cache
from itertools import accumulate
def print_rank_0(*message):
"""If distributed is initialized print only on rank 0."""
if torch.distributed.is_initialized():
if torch.di... | 6,647 | 29.635945 | 87 | py |
RWKV-LM | RWKV-LM-main/RWKV-v4/src/trainer.py | ########################################################################################################
# The RWKV Language Model - https://github.com/BlinkDL/RWKV-LM
########################################################################################################
import os
NUM_GPUS = int(os.environ['RWKV_NUM_... | 8,055 | 41.851064 | 190 | py |
RWKV-LM | RWKV-LM-main/RWKV-v2-RNN/run.py | # -*- coding:utf-8 -*-
########################################################################################################
# The RWKV v2-RNN Language Model - https://github.com/BlinkDL/RWKV-LM
########################################################################################################
import numpy as ... | 4,784 | 34.708955 | 170 | py |
RWKV-LM | RWKV-LM-main/RWKV-v2-RNN/train.py | ########################################################################################################
# The RWKV v2-RNN Language Model - https://github.com/BlinkDL/RWKV-LM
########################################################################################################
import logging
import datetime
import j... | 4,176 | 41.191919 | 204 | py |
RWKV-LM | RWKV-LM-main/RWKV-v2-RNN/src/model_run.py | import types
import copy
import torch
from torch.nn import functional as F
RWKV_K_CLAMP = 60
RWKV_K_EPS = 1e-16
RWKV_HEAD_QK_DIM = 256
DEBUG_TIME = False # True False - show trained time-coeffs
class RWKV_RNN():
def __init__(self, MODEL_NAME, RUN_DEVICE, model_type, n_layer, n_embd, ctx_len):
self.RUN... | 4,598 | 30.9375 | 85 | py |
RWKV-LM | RWKV-LM-main/RWKV-v2-RNN/src/utils.py | ########################################################################################################
# The RWKV v2-RNN Language Model - https://github.com/BlinkDL/RWKV-LM
########################################################################################################
import json
import random
import time
i... | 4,082 | 32.195122 | 104 | py |
RWKV-LM | RWKV-LM-main/RWKV-v2-RNN/src/model.py | ########################################################################################################
# The RWKV v2-RNN Language Model - https://github.com/BlinkDL/RWKV-LM
########################################################################################################
from torch.utils.cpp_extension import l... | 13,280 | 36.945714 | 176 | py |
RWKV-LM | RWKV-LM-main/RWKV-v2-RNN/src/trainer.py | ########################################################################################################
# The RWKV v2-RNN Language Model - https://github.com/BlinkDL/RWKV-LM
########################################################################################################
from torch.utils.data.dataloader import... | 7,098 | 40.51462 | 155 | py |
RWKV-LM | RWKV-LM-main/RWKV-v1/train.py | ########################################################################################################
# The RWKV Language Model - https://github.com/BlinkDL/RWKV-LM
########################################################################################################
import os, sys, time, math, random, json, date... | 6,908 | 47.314685 | 211 | py |
RWKV-LM | RWKV-LM-main/RWKV-v1/src/utils.py | import random
import numpy as np
import torch
import torch.nn as nn
from torch.nn import functional as F
def top_k_logits(logits, k):
v, ix = torch.topk(logits, k)
out = logits.clone()
out[out < v[:, [-1]]] = -float('Inf')
return out
def top_p_probs(probs, p):
out = probs.clone()
sorted_probs... | 1,513 | 28.686275 | 106 | py |
RWKV-LM | RWKV-LM-main/RWKV-v1/src/model.py | ########################################################################################################
# The RWKV Language Model - https://github.com/BlinkDL/RWKV-LM
########################################################################################################
import math
import logging
import torch
import... | 22,021 | 41.513514 | 154 | py |
RWKV-LM | RWKV-LM-main/RWKV-v1/src/trainer.py | import math, sys, datetime
import logging
import numpy as np
from tqdm.auto import tqdm
import torch
import torch.optim as optim
from torch.optim.lr_scheduler import LambdaLR
from torch.utils.data.dataloader import DataLoader
logger = logging.getLogger(__name__)
# print('logging to wandb... (comment it if you don\'t h... | 6,197 | 46.312977 | 171 | py |
RWKV-LM | RWKV-LM-main/RWKV-v4neo/img_demoAE.py | ########################################################################################################
# The RWKV Language Model - https://github.com/BlinkDL/RWKV-LM
########################################################################################################
import torch, types, os
import numpy as np
fro... | 6,185 | 36.26506 | 104 | py |
RWKV-LM | RWKV-LM-main/RWKV-v4neo/verify.py | ########################################################################################################
# The RWKV Language Model - https://github.com/BlinkDL/RWKV-LM
########################################################################################################
# this is for verifying the results of differe... | 3,525 | 32.580952 | 228 | py |
RWKV-LM | RWKV-LM-main/RWKV-v4neo/run.py | ########################################################################################################
# The RWKV Language Model - https://github.com/BlinkDL/RWKV-LM
########################################################################################################
import numpy as np
import math, os, sys, types... | 7,845 | 31.966387 | 359 | py |
RWKV-LM | RWKV-LM-main/RWKV-v4neo/chat.py | ########################################################################################################
# The RWKV Language Model - https://github.com/BlinkDL/RWKV-LM
########################################################################################################
print('Loading...')
from src.model_run import ... | 12,062 | 32.323204 | 348 | py |
RWKV-LM | RWKV-LM-main/RWKV-v4neo/train.py | ########################################################################################################
# The RWKV Language Model - https://github.com/BlinkDL/RWKV-LM
########################################################################################################
if __name__ == "__main__":
from argparse i... | 17,755 | 48.322222 | 227 | py |
RWKV-LM | RWKV-LM-main/RWKV-v4neo/src/model_run.py | ########################################################################################################
# The RWKV Language Model - https://github.com/BlinkDL/RWKV-LM
########################################################################################################
import types
import torch
import math, os, gc
... | 8,874 | 36.289916 | 110 | py |
RWKV-LM | RWKV-LM-main/RWKV-v4neo/src/utils.py | import json, time, random, os
import numpy as np
import torch
from torch.nn import functional as F
time_slot = {}
time_ref = time.time_ns()
def record_time(name):
if name not in time_slot:
time_slot[name] = 1e20
tt = (time.time_ns() - time_ref) / 1e9
if tt < time_slot[name]:
time_slot[name... | 4,587 | 34.022901 | 105 | py |
RWKV-LM | RWKV-LM-main/RWKV-v4neo/src/model.py | ########################################################################################################
# The RWKV Language Model - https://github.com/BlinkDL/RWKV-LM
########################################################################################################
import os, math, gc, importlib
import torch
# ... | 26,853 | 42.104334 | 287 | py |
RWKV-LM | RWKV-LM-main/RWKV-v4neo/src/dataset.py | ########################################################################################################
# The RWKV Language Model - https://github.com/BlinkDL/RWKV-LM
########################################################################################################
import json, math, random, os, sys
import nump... | 11,791 | 46.934959 | 249 | py |
RWKV-LM | RWKV-LM-main/RWKV-v4neo/src/model_img.py | ########################################################################################################
# The RWKV Language Model - https://github.com/BlinkDL/RWKV-LM
########################################################################################################
import numpy as np
import os, math, gc
import ... | 16,780 | 36.541387 | 182 | py |
RWKV-LM | RWKV-LM-main/RWKV-v4neo/src/binidx.py | from lib2to3.pgen2 import token
import os
import torch
import numpy as np
import shutil
import struct
from functools import lru_cache
from itertools import accumulate
def print_rank_0(*message):
pass
# """If distributed is initialized print only on rank 0."""
# if torch.distributed.is_initialized():
# ... | 8,648 | 31.033333 | 95 | py |
RWKV-LM | RWKV-LM-main/RWKV-v4neo/src/trainer.py | import os, math, time, datetime, subprocess
import torch
from torch.utils.data import DataLoader
import pytorch_lightning as pl
from pytorch_lightning.utilities import rank_zero_info, rank_zero_only
def my_save(dd, ff):
if '14b-run1' in ff:
fn = ff.split('/')[-1]
fff = '/dev/shm/' + fn
torc... | 9,823 | 43.858447 | 217 | py |
RWKV-LM | RWKV-LM-main/RWKV-v4neo/math_demo/run.py | ########################################################################################################
# The RWKV Language Model - https://github.com/BlinkDL/RWKV-LM
########################################################################################################
import numpy as np
np.set_printoptions(precisi... | 6,006 | 38.781457 | 248 | py |
RWKV-LM | RWKV-LM-main/RWKV-v3/verify.py | ########################################################################################################
# The RWKV Language Model - https://github.com/BlinkDL/RWKV-LM
########################################################################################################
# this is for verifying the results of differe... | 2,359 | 34.757576 | 121 | py |
RWKV-LM | RWKV-LM-main/RWKV-v3/run.py | ########################################################################################################
# The RWKV Language Model - https://github.com/BlinkDL/RWKV-LM
########################################################################################################
import numpy as np
import math
import time
imp... | 3,542 | 34.787879 | 177 | py |
RWKV-LM | RWKV-LM-main/RWKV-v3/train.py | ########################################################################################################
# The RWKV Language Model - https://github.com/BlinkDL/RWKV-LM
########################################################################################################
import os
# if False: # True False ---> Set t... | 5,576 | 45.865546 | 204 | py |
RWKV-LM | RWKV-LM-main/RWKV-v3/src/model_run.py | ########################################################################################################
# The RWKV Language Model - https://github.com/BlinkDL/RWKV-LM
########################################################################################################
import types
import copy
import torch
import m... | 11,329 | 34.40625 | 131 | py |
RWKV-LM | RWKV-LM-main/RWKV-v3/src/utils.py | ########################################################################################################
# The RWKV Language Model - https://github.com/BlinkDL/RWKV-LM
########################################################################################################
import json
import random
import time
import m... | 4,075 | 32.138211 | 104 | py |
RWKV-LM | RWKV-LM-main/RWKV-v3/src/model.py | ########################################################################################################
# The RWKV Language Model - https://github.com/BlinkDL/RWKV-LM
########################################################################################################
from torch.utils.cpp_extension import load
imp... | 14,277 | 38.225275 | 176 | py |
RWKV-LM | RWKV-LM-main/RWKV-v3/src/trainer.py | ########################################################################################################
# The RWKV Language Model - https://github.com/BlinkDL/RWKV-LM
########################################################################################################
from torch.utils.data.dataloader import DataLo... | 7,082 | 40.180233 | 155 | py |
RGBT-Salient-Object-Detection | RGBT-Salient-Object-Detection-master/Code/ADF/vgg.py | import torch
import torch.nn as nn
class MSA(nn.Module):
def __init__(self,in_ch,useCA=True):
super(MSA,self).__init__()
self.useCA=useCA
#for spatial mask in: max_map avg_map
self.s_mask=nn.Sequential(
nn.Conv2d(2, 1, 3, 1,1),
nn.ReLU(),
nn.Co... | 3,533 | 32.980769 | 106 | py |
RGBT-Salient-Object-Detection | RGBT-Salient-Object-Detection-master/Code/ADF/dataset.py | import os
from PIL import Image
import cv2
import torch
from torch.utils import data
import numpy as np
import random
dataset_mean_rgb=np.array([140.72236226, 157.80380783, 135.71176741]) #mean value of trainset rgb
dataset_mean_t=np.array([87.13143683, 92.03255377, 192.20629105]) #mean value of trainset t
class Im... | 3,862 | 35.443396 | 148 | py |
RGBT-Salient-Object-Detection | RGBT-Salient-Object-Detection-master/Code/ADF/run.py | coding='utf-8'
import config
import os
import solver
from dataset import get_loader
import torch
import random
import numpy as np
if __name__ == '__main__':
random.seed(1185)
np.random.seed(1185)
torch.manual_seed(1185)
if config.cuda:
torch.cuda.set_device(config.GPUid)
torch.backends... | 926 | 28.903226 | 80 | py |
RGBT-Salient-Object-Detection | RGBT-Salient-Object-Detection-master/Code/ADF/solver.py | import torch
from collections import OrderedDict
from torch.nn import functional as F
from torch.optim import Adam
from APMFnet import build_model
from LaplaceEdge import Laplace_edge_layer
import numpy as np
import os
import cv2
import time
def train(train_loader,config):
net = build_model(config)
lap = Lapl... | 4,145 | 37.747664 | 116 | py |
RGBT-Salient-Object-Detection | RGBT-Salient-Object-Detection-master/Code/ADF/LaplaceEdge.py | import torch.nn as nn
import torch
import numpy as np
#laplace operator layer for edge extraction
class Laplace_edge_layer(nn.Module):
def __init__(self):
super(Laplace_edge_layer,self).__init__()
self.laplace=nn.Conv2d(in_channels=1,out_channels=1,kernel_size=3,stride=1,padding=1,bias=False)
... | 1,452 | 40.514286 | 135 | py |
RGBT-Salient-Object-Detection | RGBT-Salient-Object-Detection-master/Code/ADF/APMFnet.py | import torch
from torch import nn
import torch.nn.functional as F
import vgg
class fusnet(nn.Module):
def __init__(self):
super(fusnet, self).__init__()
self.extract=[]
layers=[]
self.extract = [4, 11, 18, 25]
layers += [nn.MaxPool2d(kernel_size=3, stride=2, padding=1),
... | 7,398 | 41.039773 | 167 | py |
RGBT-Salient-Object-Detection | RGBT-Salient-Object-Detection-master/Code/MIED/test.py | coding='utf-8'
import os
from torch.utils.data import DataLoader
from lib.dataset import Data
import torch.nn.functional as F
import torch
import cv2
import time
from net import Mnet
import numpy as np
os.environ["CUDA_VISIBLE_DEVICES"] = "4"
if __name__ == '__main__':
model_path='./model/normal.pth'
out_path =... | 1,227 | 32.189189 | 85 | py |
RGBT-Salient-Object-Detection | RGBT-Salient-Object-Detection-master/Code/MIED/vgg.py | import torch.nn as nn
# vgg16
def vgg(cfg, i, batch_norm=False):
layers = []
in_channels = i
stage = 1
for v in cfg:
if v == 'M':
stage += 1
if stage == 6:
layers += [nn.MaxPool2d(kernel_size=3, stride=1, padding=1)]
else:
layer... | 1,727 | 35 | 106 | py |
RGBT-Salient-Object-Detection | RGBT-Salient-Object-Detection-master/Code/MIED/net.py | import torch
from torch import nn
import torch.nn.functional as F
import vgg
def convblock(in_,out_,ks,st,pad):
return nn.Sequential(
nn.Conv2d(in_,out_,ks,st,pad),
nn.BatchNorm2d(out_),
nn.ReLU(inplace=True)
)
class GFB(nn.Module):
def __init__(self,in_1,in_2):
super(GFB, ... | 5,951 | 32.627119 | 114 | py |
RGBT-Salient-Object-Detection | RGBT-Salient-Object-Detection-master/Code/MIED/train.py | coding='utf-8'
import os
from net import Mnet
import torch
import random
import numpy as np
import torch.optim as optim
from torch.utils.data import DataLoader
from lib.dataset import Data
from lib.data_prefetcher import DataPrefetcher
from torch.nn import functional as F
import cv2
import scipy.io as sio
from eval imp... | 2,791 | 35.25974 | 127 | py |
RGBT-Salient-Object-Detection | RGBT-Salient-Object-Detection-master/Code/MIED/lib/transform.py | #!/usr/bin/python3
#coding=utf-8
import cv2
import torch
import numpy as np
class Compose(object):
def __init__(self, *ops):
self.ops = ops
def __call__(self, rgb,t, mask):
for op in self.ops:
rgb,t, mask = op(rgb,t, mask)
return rgb,t, mask
class Normalize(object):
... | 2,346 | 26.611765 | 89 | py |
RGBT-Salient-Object-Detection | RGBT-Salient-Object-Detection-master/Code/MIED/lib/dataset.py | #coding=utf-8
import os
import cv2
import numpy as np
try:
from . import transform
except:
import transform
from torch.utils.data import Dataset
#BGR
mean_rgb = np.array([[[0.551*255, 0.619*255, 0.532*255]]])
mean_t =np.array([[[0.341*255, 0.360*255, 0.753*255]]])
std_rgb = np.array([[[0.241 * 255, 0.236 * 2... | 1,916 | 36.588235 | 121 | py |
RGBT-Salient-Object-Detection | RGBT-Salient-Object-Detection-master/Code/MIED/lib/data_prefetcher.py | import torch
class DataPrefetcher(object):
def __init__(self, loader):
self.loader = iter(loader)
self.stream = torch.cuda.Stream()
self.preload()
def preload(self):
try:
self.next_rgb, self.next_t, self.next_gt,_,_ = next(self.loader)
except StopIteration:
... | 1,056 | 32.03125 | 76 | py |
jax-bayes | jax-bayes-master/setup.py | # Copyright (c) James Vuckovic. All rights reserved.
# Licensed under the MIT license.
"""Setup for pip package.
Adapted from https://github.com/deepmind/dm-haiku/blob/master/setup.py
"""
from setuptools import find_namespace_packages
from setuptools import setup
def _get_version():
with open('jax_bayes/__init__.... | 2,091 | 31.184615 | 76 | py |
jax-bayes | jax-bayes-master/examples/shallow/variational_2d.py | """ Example for Black Box Variational Inference (BBVI)
Adapted from https://github.com/HIPS/autograd/blob/master/examples/black_box_svi.py
"""
from matplotlib import pyplot as plt
from tqdm import trange
import jax
import numpy as onp
import jax.numpy as jnp
from jax.experimental import optimizers
import jax.scipy.... | 3,396 | 28.284483 | 83 | py |
jax-bayes | jax-bayes-master/examples/shallow/mcmc_2d.py | import numpy as onp
import jax
import jax.numpy as np
import jax.scipy.stats.multivariate_normal as mvn
import itertools, math
import time
from matplotlib import pyplot as plt
import seaborn as sns
from jax_bayes.mcmc import (
langevin_fns,
mala_fns,
rk_langevin_fns,
hmc_fns,
rms_langevin_fns,
rwmh_fns
)
from ... | 3,834 | 23.119497 | 75 | py |
jax-bayes | jax-bayes-master/examples/shallow/mcmc_1d.py | #mcmc_1d.py
import jax.numpy as jnp
import jax.scipy.stats.norm as norm
import jax
from copy import copy, deepcopy
import itertools, math
import time
from matplotlib import pyplot as plt
import seaborn as sns
from jax_bayes.mcmc import (
langevin_fns,
mala_fns,
rk_langevin_fns,
hmc_fns,
rms_langevin_fns,
rwmh_f... | 3,204 | 23.280303 | 78 | py |
jax-bayes | jax-bayes-master/examples/deep/nn_regression/mlp_regression.py | import numpy as np
np.random.seed(0)
import haiku as hk
import jax.numpy as jnp
from jax.experimental import optimizers
import jax
from tqdm import tqdm, trange
from matplotlib import pyplot as plt
def build_dataset():
n_train, n_test, d = 200, 100, 1
xlims = [-1.0, 5.0]
x_train = np.random.rand(n_train, d) * (x... | 2,810 | 25.027778 | 78 | py |
jax-bayes | jax-bayes-master/examples/deep/nn_regression/mlp_regression_var.py | import numpy as np
np.random.seed(0)
import haiku as hk
import jax.numpy as jnp
from jax.experimental import optimizers
import jax
from tqdm import tqdm, trange
from matplotlib import pyplot as plt
from jax_bayes.variational import diagonal_mvn_fns
from jax_bayes.utils import confidence_bands
def build_dataset():
... | 5,307 | 32.383648 | 91 | py |
jax-bayes | jax-bayes-master/examples/deep/nn_regression/mlp_regression_mcmc.py |
import numpy as np
np.random.seed(0)
import haiku as hk
import jax.numpy as jnp
from jax.experimental import optimizers
import jax
from tqdm import tqdm, trange
from matplotlib import pyplot as plt
from jax_bayes.utils import confidence_bands
from jax_bayes.mcmc import (
# langevin_fns,
mala_fns,
# hmc_fns,
)
... | 4,615 | 25.994152 | 90 | py |
jax-bayes | jax-bayes-master/examples/deep/mnist/mnist_mcmc.py | import haiku as hk
import jax.numpy as jnp
from jax.experimental import optimizers
import jax
import jax_bayes
from jax_bayes.mcmc import mala_fns
import sys, os, math, time
import numpy as np
from tqdm import trange
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
import tensorflow_datasets as tfds
from matplotlib impor... | 7,638 | 36.082524 | 100 | py |
jax-bayes | jax-bayes-master/jax_bayes/utils.py | import jax
import jax.numpy as jnp
def certainty_acc(pp, targets, cert_threshold=0.5):
""" Calculates the accuracy-at-certainty from the predictive probabilites pp
on the targets.
Args:
pp: (batch_size, n_classes) array of probabilities
targets: (batch_size, n_calsses) array of label class... | 1,370 | 28.804348 | 80 | py |
jax-bayes | jax-bayes-master/jax_bayes/__init__.py | """ jax-bayes is a bayesian inference library for JAX """
from jax_bayes import mcmc
from jax_bayes import variational
from jax_bayes import utils
__version__ = "0.1.1"
__all__ = (
"mcmc",
"variational",
"utils"
) | 228 | 16.615385 | 57 | py |
jax-bayes | jax-bayes-master/jax_bayes/mcmc/sampler.py | from collections import namedtuple
import functools
import jax
import jax.numpy as jnp
from jax._src.util import partial, safe_zip, safe_map, unzip2
from jax._src.tree_util import (
tree_flatten,
tree_unflatten,
register_pytree_node,
)
from jax.tree_util import tree_map, tree_leaves
map = safe_map
zip =... | 9,010 | 42.531401 | 112 | py |
jax-bayes | jax-bayes-master/jax_bayes/mcmc/utils.py | import time
from tqdm import tqdm
import jax
from jax import grad, value_and_grad
centered_uniform = \
lambda *args, **kwargs: jax.random.uniform(*args, **kwargs) - 0.5
init_distributions = dict(normal=jax.random.normal,
uniform=centered_uniform)
#redefine elementwise_grad operation
el... | 2,934 | 31.252747 | 95 | py |
jax-bayes | jax-bayes-master/jax_bayes/mcmc/sampler_fns.py | import math
import jax
import jax.numpy as jnp
from jax.example_libraries.optimizers import make_schedule
from .sampler import sampler
from .utils import init_distributions
centered_uniform = \
lambda *args, **kwargs: jax.random.uniform(*args, **kwargs) - 0.5
init_distributions = dict(normal=jax.random.normal,
... | 17,156 | 32.773622 | 95 | py |
jax-bayes | jax-bayes-master/jax_bayes/variational/variational_family.py | from collections import namedtuple
import functools
import jax
from jax._src.util import partial, safe_zip, safe_map, unzip2
from jax._src.tree_util import tree_flatten, tree_unflatten, register_pytree_node
from ..mcmc.sampler import SamplerKeys, SamplerState
map = safe_map
zip = safe_zip
VariationalParams = namedt... | 5,353 | 38.367647 | 92 | py |
jax-bayes | jax-bayes-master/jax_bayes/variational/families.py | import math
import jax
import jax.numpy as jnp
import numpy as np
from .variational_family import variational_family
def elbo_reparam(logprob, samples, var_approx, var_params):
return jnp.mean(logprob(samples) - var_approx(samples, var_params))
def gaussian_elbo_reparam(logprob, samples, var_params):
retur... | 3,054 | 33.325843 | 82 | py |
coco-doc-gh-pages | coco-doc-gh-pages/docs/bbob-constrained/functions/source/conf.py | # -*- coding: utf-8 -*-
#
# docs/bbob-biobj/functions documentation build configuration file, created by
# sphinx-quickstart on Thu Dec 24 16:35:27 2015.
#
# This file is execfile()d with the current directory set to its
# containing dir.
#
# Note that not all possible configuration values are present in this
# autogen... | 13,493 | 35.668478 | 178 | py |
coco-doc-gh-pages | coco-doc-gh-pages/docs/coco-generic/coco-experimental-setup/source/conf.py | # -*- coding: utf-8 -*-
#
# docs/coco-generic/coco-experimental-setup documentation build configuration
# file, created by sphinx-quickstart on Fri Feb 12 14:40:02 2016.
#
# This file is execfile()d with the current directory set to its
# containing dir.
#
# Note that not all possible configuration values are present i... | 12,509 | 34.239437 | 160 | py |
coco-doc-gh-pages | coco-doc-gh-pages/docs/coco-generic/coco-perf-assessment/source/conf.py | # -*- coding: utf-8 -*-
#
# docs/coco-generic/coco-perf-assessment documentation build configuration
# file, created by sphinx-quickstart on Fri Feb 12 14:40:02 2016.
#
# This file is execfile()d with the current directory set to its
# containing dir.
#
# Note that not all possible configuration values are present in t... | 13,008 | 34.350543 | 160 | py |
coco-doc-gh-pages | coco-doc-gh-pages/docs/bbob-largescale/functions/source/conf.py | # -*- coding: utf-8 -*-
#
# docs/bbob-biobj/functions documentation build configuration file, created by
# sphinx-quickstart on Thu Dec 24 16:35:27 2015.
#
# This file is execfile()d with the current directory set to its
# containing dir.
#
# Note that not all possible configuration values are present in this
# autogen... | 13,643 | 35.579088 | 160 | py |
coco-doc-gh-pages | coco-doc-gh-pages/docs/bbob-biobj/functions/source/conf.py | # -*- coding: utf-8 -*-
#
# docs/bbob-biobj/functions documentation build configuration file, created by
# sphinx-quickstart on Thu Dec 24 16:35:27 2015.
#
# This file is execfile()d with the current directory set to its
# containing dir.
#
# Note that not all possible configuration values are present in this
# autogen... | 13,844 | 36.018717 | 160 | py |
coco-doc-gh-pages | coco-doc-gh-pages/docs/bbob-biobj/perf-assessment/source/conf.py | # -*- coding: utf-8 -*-
#
# docs/bbob-biobj/perf-assessment documentation build configuration file,
# created by sphinx-quickstart on Tue Jan 26 22:28:28 2016.
#
# This file is execfile()d with the current directory set to its
# containing dir.
#
# Note that not all possible configuration values are present in this
# a... | 13,375 | 34.386243 | 160 | py |
coco-doc-gh-pages | coco-doc-gh-pages/docs/coco-doc/source/conf.py | # -*- coding: utf-8 -*-
#
# docs/coco-generic/coco-experimental-setup documentation build configuration
# file, created by sphinx-quickstart on Fri Feb 12 14:40:02 2016.
#
# This file is execfile()d with the current directory set to its
# containing dir.
#
# Note that not all possible configuration values are present i... | 13,618 | 34.839474 | 160 | py |
RMwGGIS | RMwGGIS-main/RMwGGIS/main_ggis_synthetic.py | import os
import sys
import numpy as np
import random
import torch
from torch.optim import Adam
import torch.autograd as autograd
import torch.nn.functional as F
import argparse
from texttable import Texttable
from tqdm import tqdm
from distutils.util import strtobool
import time
import json
from utils import plot_hea... | 12,831 | 47.790875 | 228 | py |
RMwGGIS | RMwGGIS-main/RMwGGIS/main_rm_synthetic.py | import os
import sys
import numpy as np
import random
import torch
from torch.optim import Adam
import torch.autograd as autograd
import argparse
from texttable import Texttable
from tqdm import tqdm
from distutils.util import strtobool
import time
import json
from utils import plot_heat, plot_samples, estimate_hammin... | 11,418 | 45.79918 | 228 | py |
RMwGGIS | RMwGGIS-main/RMwGGIS/utils.py | import numpy as np
from sympy.combinatorics.graycode import GrayCode, bin_to_gray, gray_to_bin
import torch
from torch import nn
from torch.nn import functional as F
import matplotlib.pyplot as plt
# ### Code adapted https://github.com/google-research/google-research/tree/master/aloe/aloe
# def get_binmap(discrete_dim... | 8,223 | 37.251163 | 166 | py |
RMwGGIS | RMwGGIS-main/RMwGGIS/model.py | import torch
from torch import nn
from torch.nn import functional as F
# Code adapted from https://github.com/google-research/google-research/tree/master/aloe/aloe
class Lambda(nn.Module):
def __init__(self, f):
super(Lambda, self).__init__()
self.f = f
def forward(self, x):
return... | 1,926 | 28.19697 | 94 | py |
RMwGGIS | RMwGGIS-main/RMwGGIS/main_randn_synthetic.py | import os
import sys
import numpy as np
import random
import torch
from torch.optim import Adam
import torch.autograd as autograd
import torch.nn.functional as F
import argparse
from texttable import Texttable
from tqdm import tqdm
from distutils.util import strtobool
import time
import json
from utils import plot_hea... | 12,105 | 48.012146 | 228 | py |
GRM | GRM-main/lib/vis/plotting.py | import cv2
import matplotlib.pyplot as plt
import numpy as np
import torch
def draw_figure(fig):
fig.canvas.draw()
fig.canvas.flush_events()
plt.pause(0.001)
def show_tensor(a: torch.Tensor, fig_num=None, title=None, range=(None, None), ax=None):
"""
Display a 2D tensor.
Args:
fig_n... | 5,232 | 31.302469 | 115 | py |
GRM | GRM-main/lib/vis/utils.py | import numpy as np
import torch
def numpy_to_torch(a: np.ndarray):
return torch.from_numpy(a).float().permute(2, 0, 1).unsqueeze(0)
| 138 | 18.857143 | 68 | py |
GRM | GRM-main/lib/vis/visdom_cus.py | import copy
from collections import OrderedDict
from enum import Enum
import cv2
import numpy as np
import torch
import visdom
import visdom.server
from lib.vis.plotting import overlay_mask, show_image_with_boxes
from lib.vis.utils import numpy_to_torch
class cv_colors(Enum):
WHITE = (255, 255, 255)[::-1]
R... | 18,834 | 36.745491 | 121 | py |
GRM | GRM-main/lib/models/layers/frozen_bn.py | import torch
class FrozenBatchNorm2d(torch.nn.Module):
"""
BatchNorm2d where the batch statistics and the affine parameters are fixed.
Copy-paste from torchvision.misc.ops with added eps before rqsrt,
without which any other models than torchvision.models.resnet[18,34,50,101]
produce NaNs.
""... | 1,566 | 38.175 | 79 | py |
GRM | GRM-main/lib/models/layers/head.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from lib.models.layers.frozen_bn import FrozenBatchNorm2d
def conv(in_planes, out_planes, kernel_size=3, stride=1, padding=1, dilation=1, freeze_bn=False):
if freeze_bn:
return nn.Sequential(
nn.Conv2d(in_planes, out_planes, k... | 6,423 | 39.402516 | 97 | py |
GRM | GRM-main/lib/models/layers/patch_embed.py | import torch.nn as nn
from timm.models.layers import to_2tuple
class PatchEmbed(nn.Module):
"""
2D image to patch embedding.
"""
def __init__(self, img_size=224, patch_size=16, in_chans=3, embed_dim=768, norm_layer=None, flatten=True):
super().__init__()
img_size = to_2tuple(img_size... | 1,255 | 35.941176 | 110 | py |
GRM | GRM-main/lib/models/grm/utils.py | import torch
def combine_tokens(template_tokens, search_tokens, mode='direct'):
if mode == 'direct':
merged_feature = torch.cat((template_tokens, search_tokens), dim=1)
else:
raise NotImplementedError
return merged_feature
def recover_tokens(merged_tokens, mode='direct'):
if mode == ... | 1,412 | 26.173077 | 92 | py |
GRM | GRM-main/lib/models/grm/vit.py | """
Vision Transformer (ViT) in PyTorch.
"""
import math
from functools import partial
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from timm.models.helpers import named_apply, adapt_input_conv
from timm.models.layers import Mlp, DropPath, trunc_normal_, lecun_normal_
from li... | 26,457 | 48.920755 | 132 | py |
GRM | GRM-main/lib/models/grm/base_backbone.py | import torch
import torch.nn as nn
from timm.models.layers import to_2tuple
from lib.models.layers.patch_embed import PatchEmbed
from lib.models.grm.utils import combine_tokens, recover_tokens
class BaseBackbone(nn.Module):
def __init__(self):
super().__init__()
# For original ViT
self.po... | 4,548 | 40.733945 | 118 | py |
GRM | GRM-main/lib/models/grm/grm.py | """
Basic GRM model.
"""
import os
import torch
from torch import nn
from lib.models.layers.head import build_box_head
from lib.models.grm.vit import vit_base_patch16_224_base, vit_base_patch16_224_large
from lib.utils.box_ops import box_xyxy_to_cxcywh
class GRM(nn.Module):
"""
This is the base class for G... | 5,037 | 37.753846 | 120 | py |
GRM | GRM-main/lib/test/tracker/data_utils.py | import numpy as np
import torch
from lib.utils.misc import NestedTensor
class Preprocessor(object):
def __init__(self):
self.mean = torch.tensor([0.485, 0.456, 0.406]).view((1, 3, 1, 1)).cuda()
self.std = torch.tensor([0.229, 0.224, 0.225]).view((1, 3, 1, 1)).cuda()
def process(self, img_arr... | 2,173 | 40.807692 | 100 | py |
GRM | GRM-main/lib/test/tracker/basetracker.py | import time
from _collections import OrderedDict
import torch
from lib.train.data.processing_utils import transform_image_to_crop
from lib.vis.visdom_cus import Visdom
class BaseTracker:
"""
Base class for all trackers.
"""
def __init__(self, params):
self.params = params
self.visdo... | 3,094 | 33.775281 | 108 | py |
GRM | GRM-main/lib/test/tracker/grm.py | import os
# For debug
import cv2
import torch
from lib.models.grm import build_grm
from lib.test.tracker.basetracker import BaseTracker
from lib.test.tracker.data_utils import Preprocessor
from lib.test.utils.hann import hann2d
from lib.train.data.processing_utils import sample_target
from lib.utils.box_ops import cl... | 6,310 | 42.524138 | 120 | py |
GRM | GRM-main/lib/test/evaluation/running.py | import multiprocessing
import os
import sys
from collections import OrderedDict
from itertools import product
import numpy as np
import torch
from lib.test.evaluation import Sequence, Tracker
def _save_tracker_output(seq: Sequence, tracker: Tracker, output: dict):
"""
Saves the output of the tracker.
""... | 6,513 | 33.834225 | 116 | py |
GRM | GRM-main/lib/test/analysis/plot_results.py | import json
import os
import pickle
import matplotlib
import matplotlib.pyplot as plt
import tikzplotlib
import torch
from lib.test.analysis.extract_results import extract_results
from lib.test.evaluation.environment import env_settings
def get_plot_draw_styles():
plot_draw_style = [{'color': (1.0, 0.0, 0.0), '... | 22,478 | 44.229376 | 120 | py |
GRM | GRM-main/lib/test/analysis/extract_results.py | import os
import pickle
import sys
import numpy as np
import torch
from tqdm import tqdm
from lib.test.utils.load_text import load_text
env_path = os.path.join(os.path.dirname(__file__), '../../..')
if env_path not in sys.path:
sys.path.append(env_path)
from lib.test.evaluation.environment import env_settings
... | 8,341 | 41.779487 | 132 | py |
GRM | GRM-main/lib/test/utils/hann.py | import math
import torch
import torch.nn.functional as F
def hann1d(sz: int, centered=True) -> torch.Tensor:
"""
1D cosine window.
"""
if centered:
return 0.5 * (1 - torch.cos((2 * math.pi / (sz + 1)) * torch.arange(1, sz + 1).float()))
w = 0.5 * (1 + torch.cos((2 * math.pi / (sz + 2)) *... | 4,402 | 36.956897 | 120 | py |
GRM | GRM-main/lib/train/base_functions.py | import torch
from torch.utils.data.distributed import DistributedSampler
import lib.train.data.transforms as tfm
from lib.train.data import sampler, opencv_loader, processing, LTRLoader
# Datasets related
from lib.train.dataset import Lasot, Got10k, MSCOCOSeq, TrackingNet
from lib.utils.misc import is_main_process
d... | 5,787 | 51.144144 | 117 | py |
GRM | GRM-main/lib/train/run_training.py | import argparse
import importlib
import os
import random
import warnings
warnings.filterwarnings('ignore')
import cv2 as cv
import numpy as np
import torch.backends.cudnn
import torch.distributed as dist
torch.backends.cudnn.benchmark = False
import _init_paths
import lib.train.admin.settings as ws_settings
def i... | 5,139 | 42.931624 | 118 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.