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 |
|---|---|---|---|---|---|---|
LTNODE | LTNODE-main/ALTNODE/attacks/multiattack.py | import torch
from ..attack import Attack
class MultiAttack(Attack):
r"""
MultiAttack is a class to attack a model with various attacks agains same images and labels.
Arguments:
model (nn.Module): model to attack.
attacks (list): list of attacks.
Examples::
>>> atta... | 2,002 | 30.793651 | 105 | py |
LTNODE | LTNODE-main/ALTNODE/attacks/ffgsm.py | import torch
import torch.nn as nn
from ..attack import Attack
class FFGSM(Attack):
r"""
New FGSM proposed in 'Fast is better than free: Revisiting adversarial training'
[https://arxiv.org/abs/2001.03994]
Distance Measure : Linf
Arguments:
model (nn.Module): model to attack.
... | 2,016 | 33.775862 | 161 | py |
LTNODE | LTNODE-main/ALTNODE/attacks/onepixel.py | import numpy as np
import torch
import torch.nn.functional as F
from ..attack import Attack
from ._differential_evolution import differential_evolution
class OnePixel(Attack):
r"""
Attack in the paper 'One pixel attack for fooling deep neural networks'
[https://arxiv.org/abs/1710.08864]
Modifie... | 4,862 | 39.190083 | 161 | py |
LTNODE | LTNODE-main/ALTNODE/attacks/fab.py | from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import time
import os
import sys
import math
import torch
from torch.autograd.gradcheck import zero_gradients
import torch.nn as nn
import torch.nn.functional as F
from... | 30,695 | 42.233803 | 194 | py |
LTNODE | LTNODE-main/ALTNODE/attacks/bim.py | import torch
import torch.nn as nn
from ..attack import Attack
class BIM(Attack):
r"""
BIM or iterative-FGSM in the paper 'Adversarial Examples in the Physical World'
[https://arxiv.org/abs/1607.02533]
Distance Measure : Linf
Arguments:
model (nn.Module): model to attack.
ep... | 2,767 | 36.405405 | 161 | py |
LTNODE | LTNODE-main/ALTNODE/attacks/pgddlr.py | import numpy as np
import torch
import torch.nn as nn
from ..attack import Attack
class PGDDLR(Attack):
r"""
PGD based on DLR loss in the paper 'Reliable evaluation of adversarial robustness with an ensemble of diverse parameter-free attacks'
[https://arxiv.org/abs/2003.01690]
[https://github.com/fr... | 2,965 | 37.025641 | 161 | py |
LTNODE | LTNODE-main/ALTNODE/attacks/eotpgd.py | import torch
import torch.nn as nn
from ..attack import Attack
class EOTPGD(Attack):
r"""
Comment on "Adv-BNN: Improved Adversarial Defense through Robust Bayesian Neural Network"
[https://arxiv.org/abs/1907.00895]
Distance Measure : Linf
Arguments:
model (nn.Module): model to attac... | 2,441 | 33.394366 | 154 | py |
LTNODE | LTNODE-main/ALTNODE/src/probability.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.distributions import Normal
import numpy as np
from scipy.special import gamma
from torch.distributions.gamma import Gamma
from torch.distributions.uniform import Uniform
from src.utils import torch_onehot
#Line 202,105
def gumbel_softmax(l... | 15,450 | 38.415816 | 206 | py |
LTNODE | LTNODE-main/ALTNODE/src/utils.py | import os
import sys
import pickle
import numpy as np
import torch
from torch.autograd import Variable
import torch.utils.data as data
import torch.nn.functional as F
from torch.distributions import Normal
from torch.optim.lr_scheduler import MultiStepLR
import torch.nn as nn
from PIL import Image
def mkdir(paths):
... | 7,310 | 27.897233 | 89 | py |
LTNODE | LTNODE-main/ALTNODE/src/plots.py | import numpy as np
import torch
import torch.nn.functional as F
import matplotlib
import matplotlib.pyplot as plt
from src.utils import np_get_one_hot, generate_ind_batch, rms
matplotlib.use('Agg')
c = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd',
'#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf']... | 14,211 | 37 | 119 | py |
LTNODE | LTNODE-main/ALTNODE/src/baselines/train_fc.py | import os
import time
import tempfile
import torch
import torch.utils.data
import numpy as np
from src.utils import mkdir, cprint
def train_fc_baseline(net, name, save_dir, batch_size, nb_epochs, trainloader, valloader, cuda, seed,
flat_ims=False, nb_its_dev=1, early_stop=None,
... | 4,426 | 33.858268 | 129 | py |
LTNODE | LTNODE-main/ALTNODE/src/baselines/mfvi.py | import torch
import torch.nn.functional as F
import torch.nn as nn
from torch.autograd import Variable
def KLD_cost(mu_p, sig_p, mu_q, sig_q):
KLD = 0.5 * (2 * torch.log(sig_p / sig_q) - 1 + (sig_q / sig_p).pow(2) + ((mu_p - mu_q) / sig_p).pow(2)).sum()
# https://arxiv.org/abs/1312.6114 0.5 * sum(1 + log(sigm... | 4,990 | 36.526316 | 114 | py |
LTNODE | LTNODE-main/ALTNODE/src/baselines/SGD.py | import random
import numpy as np
import torch
import torch.nn as nn
class res_MLPBlock(nn.Module):
"""Skippable MLPBlock with relu"""
def __init__(self, width):
super(res_MLPBlock, self).__init__()
self.block = nn.Sequential(nn.Linear(width, width), nn.ReLU(), nn.BatchNorm1d(width)) # nn.Laye... | 1,827 | 32.851852 | 165 | py |
LTNODE | LTNODE-main/ALTNODE/src/baselines/img_utils.py | from collections import OrderedDict
import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
def load_img_resnet(model, savefile, gpu=None):
cuda_enabled = torch.cuda.is_available()
if cuda_enabled:
if gpu is None:
if not isinstance(model, nn.DataParallel):
... | 5,586 | 33.91875 | 111 | py |
LTNODE | LTNODE-main/ALTNODE/src/baselines/dropout.py | import torch
import torch.nn.functional as F
import torch.nn as nn
class res_DropoutBlock(nn.Module):
"""Skippable MLPBlock with relu"""
def __init__(self, width, p_drop=0.5):
super(res_DropoutBlock, self).__init__()
self.p_drop = p_drop
self.block = nn.Sequential(nn.Linear(width, widt... | 2,312 | 33.014706 | 91 | py |
LTNODE | LTNODE-main/ALTNODE/src/baselines/training_wrappers.py | import random
import numpy as np
import torch
import torch.backends.cudnn as cudnn
from src.utils import BaseNet, cprint, to_variable
from src.utils import rms
from src.probability import homo_Gauss_mloglike
def ensemble_predict(net, savefiles, x, return_model_std=False, return_individual_functions=False, to_cpu=F... | 6,024 | 37.870968 | 130 | py |
LTNODE | LTNODE-main/ALTNODE/src/datasets/image_loaders.py | import os
from PIL import Image
import h5py
import torch
from torchvision import transforms, datasets
from torchvision.datasets import VisionDataset
def get_image_loader(dname, batch_size, cuda, workers, distributed, data_dir='../../data', subset=None):
assert dname in ['MNIST', 'Fashion', 'SVHN', 'CIFAR10', 'C... | 9,459 | 35.809339 | 110 | py |
LTNODE | LTNODE-main/ALTNODE/src/DUN/train_fc.py | import os
import time
import tempfile
import numpy as np
import torch
import torch.utils.data
from src.utils import mkdir, cprint
def train_fc_DUN(net, name, save_dir, batch_size, nb_epochs, train_loader, val_loader,
cuda, seed, flat_ims=False, nb_its_dev=1, early_stop=None,
track_poster... | 5,435 | 34.529412 | 122 | py |
LTNODE | LTNODE-main/ALTNODE/src/DUN/stochastic_fc_models.py | import torch
import torch.nn as nn
from src.DUN.layers import bern_MLPBlock, bern_MLPBlock_nores
class arq_uncert_fc_resnet(nn.Module):
def __init__(self, input_dim, output_dim, width, n_layers, w_prior=None, BMA_prior=False):
super(arq_uncert_fc_resnet, self).__init__()
self.input_dim = input_d... | 3,365 | 40.04878 | 112 | py |
LTNODE | LTNODE-main/ALTNODE/src/DUN/stochastic_toy_node.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.modules.dropout import _DropoutNd
import torch.nn.init as init
import numpy as np
__all__ = ['toy']
class ConcatConv2d(nn.Module):
def __init__(self, dim_in, dim_out, ksize=3, stride=1, padding=0, dilation=1, groups=1, bias=True, t... | 12,126 | 33.064607 | 168 | py |
LTNODE | LTNODE-main/ALTNODE/src/DUN/layers.py | import torch.nn as nn
class global_mean_pool_2d(nn.Module):
def __init__(self):
super(global_mean_pool_2d, self).__init__()
def forward(self, x):
return x.mean(dim=(2, 3))
class res_MLPBlock(nn.Module):
def __init__(self, width):
super(res_MLPBlock, self).__init__()
self... | 6,037 | 33.112994 | 111 | py |
LTNODE | LTNODE-main/ALTNODE/src/DUN/stochastic_toy_node (copy).py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.modules.dropout import _DropoutNd
import torch.nn.init as init
import numpy as np
__all__ = ['toy']
class ConcatConv2d(nn.Module):
def __init__(self, dim_in, dim_out, ksize=3, stride=1, padding=0, dilation=1, groups=1, bias=True, t... | 9,479 | 31.57732 | 168 | py |
LTNODE | LTNODE-main/ALTNODE/src/DUN/stochastic_img_resnets (copy).py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.modules.dropout import _DropoutNd
import torch.nn.init as init
__all__ = ['ResNet', 'resnet18', 'resnet34', 'resnet50', 'resnet101','simple','simple1']
class MC_Dropout2d(_DropoutNd):
def forward(self, input):
return F.drop... | 24,209 | 37.489666 | 282 | py |
LTNODE | LTNODE-main/ALTNODE/src/DUN/sdenet_mnist.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Mar 11 16:42:11 2019
@author: lingkaikong
"""
import torch
import torch.nn as nn
import torch.nn.functional as F
import random
import torch.nn.init as init
import math
__all__ = ['SDENet_mnist']
def init_params(net):
'''Init layer parameters.'''
... | 5,255 | 30.473054 | 147 | py |
LTNODE | LTNODE-main/ALTNODE/src/DUN/stochastic_concentric_node.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.modules.dropout import _DropoutNd
import torch.nn.init as init
__all__ = ['concentric']
class NODE(nn.Module):
def __init__(self, dim):
super(NODE, self).__init__()
#self.norm1 = norm(dim)
#self.tanh = nn... | 9,029 | 37.262712 | 169 | py |
LTNODE | LTNODE-main/ALTNODE/src/DUN/training_wrappers.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.backends.cudnn as cudnn
from src.utils import BaseNet, cprint, to_variable
from src.utils import rms
from src.probability import homo_Gauss_mloglike, depth_gamma
class DUN(BaseNet):
def __init__(self, model, prob_model, N_train, lr=1... | 16,273 | 49.540373 | 212 | py |
LTNODE | LTNODE-main/ALTNODE/src/DUN/stochastic_img_resnets.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.modules.dropout import _DropoutNd
import torch.nn.init as init
__all__ = ['ResNet', 'resnet18', 'resnet34', 'resnet50', 'resnet101','simple','simple1']
class MC_Dropout2d(_DropoutNd):
def forward(self, input):
return F.drop... | 26,749 | 37.544669 | 282 | py |
LTNODE | LTNODE-main/ALTNODE/src/DUN/sdode_img_resnets.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.modules.dropout import _DropoutNd
import torch.nn.init as init
__all__ = ['ResNet', 'resnet18', 'resnet34', 'resnet50', 'resnet101','simple']
class MC_Dropout2d(_DropoutNd):
def forward(self, input):
return F.dropout2d(inpu... | 17,750 | 35.98125 | 282 | py |
LTNODE | LTNODE-main/ALTNODE/torch_ACA/misc.py | """
Misc functions forked from https://github.com/rtqichen/torchdiffeq/blob/master/torchdiffeq/_impl/misc.py
"""
import torch
import warnings
def _possibly_nonzero(x):
return isinstance(x, torch.Tensor) or x != 0
def _scaled_dot_product(scale, xs, ys):
"""Calculate a scaled, vector inner product between lists... | 3,325 | 38.595238 | 110 | py |
LTNODE | LTNODE-main/ALTNODE/torch_ACA/fixed_grid_solver.py | import abc
import torch
import copy
import numpy as np
from torch import nn
from .utils import monotonic
__all__ = ['Euler','RK2','RK4']
class FixedGridSolver(nn.Module):
__metaclass__ = abc.ABCMeta
def __init__(self, func, t0=0.0, t1=1.0, h = 0.1, rtol=1e-3, atol=1e-6, neval_max=500000,
pri... | 9,753 | 36.953307 | 167 | py |
LTNODE | LTNODE-main/ALTNODE/torch_ACA/odesolver/adaptive_grid_solver.py | """
This file contains a class of ODE solvers, which support arbitraty evaluation time between initial time t0, and end time t1.
e.g. evaluate at time points s1, s2, s3, s4, .. where t0 < s1 < s2 < ... t1
or t1 < s1 < s2 < s3 < ... t0
The freedom with evaluation time points comes at a price, that it's hard t... | 33,444 | 42.099227 | 135 | py |
LTNODE | LTNODE-main/ALTNODE/torch_ACA/odesolver_mem/adaptive_grid_solver_endtime.py | """
This file contains a class of ODE solvers, which support "checkpoint" strategy to save memory.
However, denoting the initial time as t0 and end time as t1, this file only supports evaluate at t1.
t1 can be either greater or smaller than t0.
"""
import abc
import torch
import copy
import numpy as np
from torch.autog... | 25,112 | 40.646766 | 182 | py |
LTNODE | LTNODE-main/ALTNODE/torch_ACA/odesolver_mem/adjoint_mem.py |
import torch
import torch.nn as nn
from .ode_solver_endtime import odesolve_endtime
from torch.autograd import Variable
import copy
__all__ = ['odesolve_adjoint']
def flatten_params(params):
flat_params = [p.contiguous().view(-1) for p in params]
return torch.cat(flat_params) if len(flat_params) > 0 else torc... | 6,638 | 33.942105 | 153 | py |
PointContrast | PointContrast-main/pretrain/pointcontrast/ddp_train.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import open3d as o3d # prevent loading error
import sys
import os
import json
import logging
import torch
from omegaconf import OmegaConf
... | 2,032 | 24.734177 | 78 | py |
PointContrast | PointContrast-main/pretrain/pointcontrast/model/res16unet.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from model.resnet import ResNetBase, get_norm
from model.modules.common import ConvType, NormType, conv, conv_tr
from model.modules.resnet_bl... | 8,102 | 28.358696 | 92 | py |
PointContrast | PointContrast-main/pretrain/pointcontrast/model/resnet.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import torch.nn as nn
import MinkowskiEngine as ME
from MinkowskiEngine import MinkowskiNetwork
from model.modules.common import ConvType, ... | 4,476 | 27.883871 | 94 | py |
PointContrast | PointContrast-main/pretrain/pointcontrast/model/modules/resnet_block.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import torch.nn as nn
from model.modules.common import ConvType, NormType, get_norm, conv
from MinkowskiEngine import MinkowskiReLU
class... | 3,032 | 24.923077 | 100 | py |
PointContrast | PointContrast-main/pretrain/pointcontrast/lib/ddp_trainer.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import os
import os.path as osp
import gc
import logging
import numpy as np
import json
from omegaconf import OmegaConf
import torch.nn as nn... | 15,041 | 33.108844 | 124 | py |
PointContrast | PointContrast-main/pretrain/pointcontrast/lib/data_sampler.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import torch
from torch.utils.data.sampler import Sampler
import torch.distributed as dist
import math
class InfSampler(Sampler):
def __... | 2,016 | 26.256757 | 86 | py |
PointContrast | PointContrast-main/pretrain/pointcontrast/lib/distributed.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#!/usr/bin/env python3
"""Distributed helpers."""
import pickle
import time
import functools
import logging
import torch
import torch.dist... | 11,626 | 30.255376 | 98 | py |
PointContrast | PointContrast-main/pretrain/pointcontrast/lib/criterion.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import torch
from torch import nn
class NCESoftmaxLoss(nn.Module):
def __init__(self):
super(NCESoftmaxLoss, self).__init__()
... | 509 | 24.5 | 65 | py |
PointContrast | PointContrast-main/pretrain/pointcontrast/lib/ddp_data_loaders.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import logging
import random
import torch
import torch.utils.data
import numpy as np
import glob
import os
import copy
from tqdm import tqdm... | 9,754 | 30.467742 | 96 | py |
PointContrast | PointContrast-main/downstream/semseg/ddp_main.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
# # Change dataloader multiprocess start method to anything not fork
import open3d as o3d
import numpy as np
import torch.multiprocessing as... | 8,354 | 33.241803 | 151 | py |
PointContrast | PointContrast-main/downstream/semseg/models/resnet.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import torch.nn as nn
import MinkowskiEngine as ME
from models.model import Model
from models.modules.common import ConvType, NormType, get... | 5,527 | 23.900901 | 94 | py |
PointContrast | PointContrast-main/downstream/semseg/models/resunet.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from models.resnet import ResNetBase, get_norm
from models.modules.common import ConvType, NormType, conv, conv_tr
from models.modules.resnet... | 15,108 | 26.825046 | 91 | py |
PointContrast | PointContrast-main/downstream/semseg/models/wrapper.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import random
from torch.nn import Module
from MinkowskiEngine import SparseTensor
class Wrapper(Module):
"""
Wrapper for the segmenta... | 1,129 | 30.388889 | 80 | py |
PointContrast | PointContrast-main/downstream/semseg/models/residual_block.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import torch.nn as nn
from models.common import get_norm
import MinkowskiEngine as ME
import MinkowskiEngine.MinkowskiFunctional as MEF
c... | 2,041 | 23.60241 | 87 | py |
PointContrast | PointContrast-main/downstream/semseg/models/modules/common.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import collections
from enum import Enum
import torch.nn as nn
import MinkowskiEngine as ME
class NormType(Enum):
BATCH_NORM = 0
INSTA... | 6,924 | 30.621005 | 97 | py |
PointContrast | PointContrast-main/downstream/semseg/models/modules/resnet_block.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import torch.nn as nn
from models.modules.common import ConvType, NormType, get_norm, conv
from MinkowskiEngine import MinkowskiReLU
clas... | 3,351 | 23.82963 | 100 | py |
PointContrast | PointContrast-main/downstream/semseg/lib/test.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import logging
import os
import shutil
import tempfile
import warnings
import numpy as np
import torch
import torch.nn as nn
from sklearn.me... | 6,840 | 33.725888 | 97 | py |
PointContrast | PointContrast-main/downstream/semseg/lib/dataloader.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import math
import torch
import torch.distributed as dist
from torch.utils.data.sampler import Sampler
class InfSampler(Sampler):
"""Sam... | 2,110 | 26.064103 | 86 | py |
PointContrast | PointContrast-main/downstream/semseg/lib/utils.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import json
import logging
import os
import errno
import time
import numpy as np
from omegaconf import OmegaConf
import torch
from lib.pc_u... | 15,527 | 35.111628 | 180 | py |
PointContrast | PointContrast-main/downstream/semseg/lib/dataset.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from abc import ABC
from pathlib import Path
from collections import defaultdict
import random
import numpy as np
from enum import Enum
imp... | 11,731 | 29.393782 | 136 | py |
PointContrast | PointContrast-main/downstream/semseg/lib/layers.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
from MinkowskiEngine import MinkowskiGlobalPooling, MinkowskiBroadcastAddition, MinkowskiBroadcastMultipl... | 3,086 | 32.923077 | 112 | py |
PointContrast | PointContrast-main/downstream/semseg/lib/distributed_utils.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import os
import pickle
import socket
import struct
import subprocess
import warnings
import torch
import torch.distributed as dist
def is... | 7,108 | 36.219895 | 107 | py |
PointContrast | PointContrast-main/downstream/semseg/lib/solvers.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import logging
from torch.optim import SGD, Adam
from torch.optim.lr_scheduler import LambdaLR, StepLR
class LambdaStepLR(LambdaLR):
de... | 2,804 | 32.392857 | 105 | py |
PointContrast | PointContrast-main/downstream/semseg/lib/train.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
import logging
import os.path as osp
import torch
from torch import nn
from torch.serialization import default_restore_loc... | 8,696 | 36.32618 | 150 | py |
PointContrast | PointContrast-main/downstream/semseg/lib/math_functions.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from scipy.sparse import csr_matrix
import torch
class SparseMM(torch.autograd.Function):
"""
Sparse x dense matrix multiplication with... | 2,239 | 28.473684 | 80 | py |
PointContrast | PointContrast-main/downstream/semseg/lib/transforms.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import random
import logging
import numpy as np
import scipy
import scipy.ndimage
import scipy.interpolate
import torch
# A sparse tensor ... | 11,673 | 35.826498 | 124 | py |
PointContrast | PointContrast-main/downstream/semseg/lib/datasets/stanford.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import logging
import os
import sys
import numpy as np
from collections import defaultdict
from scipy import spatial
from plyfile import PlyD... | 7,801 | 31.781513 | 102 | py |
PointContrast | PointContrast-main/downstream/votenet_det_new/ddp_main.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import torch
import hydra
import logging
import sys
import os
import numpy as np
import torch.nn as nn
import importlib
from omegaconf imp... | 6,659 | 38.176471 | 112 | py |
PointContrast | PointContrast-main/downstream/votenet_det_new/models/voting_module.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
''' Voting module: generate votes from XYZ and features of seed points.
Date: July, 2019
Author: Charles R. Qi and Or Litany
'''
import tor... | 2,930 | 39.708333 | 93 | py |
PointContrast | PointContrast-main/downstream/votenet_det_new/models/votenet.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
""" Deep hough voting network for 3D object detection in point clouds.
Author: Charles R. Qi and Or Litany
"""
import torch
import torch.nn... | 5,774 | 34.213415 | 119 | py |
PointContrast | PointContrast-main/downstream/votenet_det_new/models/dump_helper.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
import torch
import os
import sys
from lib.utils import pc_util
DUMP_CONF_THRESH = 0.5 # Dump boxes with obj prob larger ... | 7,467 | 52.726619 | 192 | py |
PointContrast | PointContrast-main/downstream/votenet_det_new/models/backbone_module.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
import sys
import os
from models.backbone.pointnet2.po... | 6,692 | 34.412698 | 129 | py |
PointContrast | PointContrast-main/downstream/votenet_det_new/models/loss_helper.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
import numpy as np
import sys
import os
from lib.utils.nn_distance import nn_distance, huber_loss
FAR_THR... | 12,116 | 47.858871 | 185 | py |
PointContrast | PointContrast-main/downstream/votenet_det_new/models/ap_helper.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
""" Helper functions and class to calculate Average Precisions for 3D object detection.
"""
import os
import sys
import numpy as np
import to... | 14,003 | 49.555957 | 177 | py |
PointContrast | PointContrast-main/downstream/votenet_det_new/models/boxnet.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
import numpy as np
import sys
import os
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
ROOT_DIR = o... | 4,250 | 35.646552 | 119 | py |
PointContrast | PointContrast-main/downstream/votenet_det_new/models/loss_helper_boxnet.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
import numpy as np
import sys
import os
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
ROOT_DIR = o... | 5,108 | 40.536585 | 123 | py |
PointContrast | PointContrast-main/downstream/votenet_det_new/models/proposal_module.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
import os
import sys
BASE_DIR = os.path.dirname(os.path... | 6,039 | 47.32 | 217 | py |
PointContrast | PointContrast-main/downstream/votenet_det_new/models/backbone/sparseconv/config.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import argparse
import torch
def str2opt(arg):
assert arg in ['SGD', 'Adam']
return arg
def str2scheduler(arg):
assert arg ... | 11,503 | 41.925373 | 100 | py |
PointContrast | PointContrast-main/downstream/votenet_det_new/models/backbone/sparseconv/voxelized_dataset.py | # coding: utf-8
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import os
import sys
import numpy as np
import torch
from torch.utils.data import Dataset
from torch.utils.data._utils.colla... | 1,991 | 29.181818 | 90 | py |
PointContrast | PointContrast-main/downstream/votenet_det_new/models/backbone/sparseconv/models/resnet.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import torch.nn as nn
import MinkowskiEngine as ME
from models.backbone.sparseconv.models.model import Model
from models.backbone.sparseco... | 5,609 | 24.27027 | 105 | py |
PointContrast | PointContrast-main/downstream/votenet_det_new/models/backbone/sparseconv/models/conditional_random_fields.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
from torch.autograd import Variable
from MinkowskiEngine import SparseTensor, MinkowskiConvolution, Mink... | 6,364 | 35.58046 | 115 | py |
PointContrast | PointContrast-main/downstream/votenet_det_new/models/backbone/sparseconv/models/resunet.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from models.backbone.sparseconv.models.resnet import ResNetBase, get_norm
from models.backbone.sparseconv.models.modules.common import ConvT... | 15,190 | 26.976059 | 105 | py |
PointContrast | PointContrast-main/downstream/votenet_det_new/models/backbone/sparseconv/models/wrapper.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import random
from torch.nn import Module
from MinkowskiEngine import SparseTensor
class Wrapper(Module):
"""
Wrapper for the segment... | 1,130 | 30.416667 | 80 | py |
PointContrast | PointContrast-main/downstream/votenet_det_new/models/backbone/sparseconv/models/modules/senet_block.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import torch.nn as nn
import MinkowskiEngine as ME
from models.modules.common import ConvType, NormType
from models.modules.resnet_block i... | 3,259 | 22.453237 | 90 | py |
PointContrast | PointContrast-main/downstream/votenet_det_new/models/backbone/sparseconv/models/modules/common.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import collections
from enum import Enum
import torch.nn as nn
import MinkowskiEngine as ME
class NormType(Enum):
BATCH_NORM = 0
INST... | 6,925 | 30.625571 | 97 | py |
PointContrast | PointContrast-main/downstream/votenet_det_new/models/backbone/sparseconv/models/modules/resnet_block.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import torch.nn as nn
from models.backbone.sparseconv.models.modules.common import ConvType, NormType, get_norm, conv
from MinkowskiEngine... | 3,379 | 24.037037 | 100 | py |
PointContrast | PointContrast-main/downstream/votenet_det_new/models/backbone/sparseconv/lib/math_functions.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from scipy.sparse import csr_matrix
import torch
class SparseMM(torch.autograd.Function):
"""
Sparse x dense matrix multiplication wit... | 2,240 | 28.486842 | 80 | py |
PointContrast | PointContrast-main/downstream/votenet_det_new/models/backbone/pointnet2/setup.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import glob
import os
from setuptools import setup
from torch.utils.cpp_extension import BuildExtension, CUDAExtension
this_dir = os.path.d... | 934 | 25.714286 | 76 | py |
PointContrast | PointContrast-main/downstream/votenet_det_new/models/backbone/pointnet2/pointnet2_utils.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
''' Modified based on: https://github.com/erikwijmans/Pointnet2_PyTorch '''
from __future__ import (
division,
absolute_import,
w... | 12,207 | 27.657277 | 144 | py |
PointContrast | PointContrast-main/downstream/votenet_det_new/models/backbone/pointnet2/pointnet2_test.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
''' Testing customized ops. '''
import torch
from torch.autograd import gradcheck
import numpy as np
import os
import sys
BASE_DIR = os.pat... | 1,011 | 28.764706 | 83 | py |
PointContrast | PointContrast-main/downstream/votenet_det_new/models/backbone/pointnet2/pointnet2_modules.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
''' Pointnet2 layers.
Modified based on: https://github.com/erikwijmans/Pointnet2_PyTorch
Extended with the following:
1. Uniform sampling in... | 17,609 | 32.930636 | 135 | py |
PointContrast | PointContrast-main/downstream/votenet_det_new/models/backbone/pointnet2/pytorch_utils.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
''' Modified based on Ref: https://github.com/erikwijmans/Pointnet2_PyTorch '''
import torch
import torch.nn as nn
from typing import List, T... | 7,501 | 24.090301 | 79 | py |
PointContrast | PointContrast-main/downstream/votenet_det_new/lib/test.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
""" Evaluation routine for 3D object detection with SUN RGB-D and ScanNet.
"""
import os
import sys
import logging
import numpy as np
from d... | 3,874 | 38.948454 | 94 | py |
PointContrast | PointContrast-main/downstream/votenet_det_new/lib/train.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
""" Training routine for 3D object detection with SUN RGB-D or ScanNet.
Sample usage:
python train.py --dataset sunrgbd --log_dir log_sunrgb... | 9,259 | 41.477064 | 124 | py |
PointContrast | PointContrast-main/downstream/votenet_det_new/lib/datasets/sunrgbd/sunrgbd_detection_dataset.py | # coding: utf-8
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
""" Dataset for 3D object detection on SUN RGB-D (with support of vote supervision).
A sunrgbd oriented bounding box is para... | 13,122 | 45.701068 | 126 | py |
PointContrast | PointContrast-main/downstream/votenet_det_new/lib/datasets/scannet/scannet_detection_dataset.py | # coding: utf-8
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
""" Dataset for object bounding box regression.
An axis aligned bounding box is parameterized by (cx,cy,cz) and (dx,dy,dz)
wh... | 10,462 | 45.502222 | 108 | py |
PointContrast | PointContrast-main/downstream/votenet_det_new/lib/utils/tf_visualizer.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
'''Code adapted from https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix'''
import os
import time
BASE_DIR = os.path.dirname(os.path.absp... | 1,874 | 36.5 | 90 | py |
PointContrast | PointContrast-main/downstream/votenet_det_new/lib/utils/distributed_utils.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import os
import pickle
import socket
import struct
import subprocess
import warnings
import torch
import torch.distributed as dist
def is... | 7,108 | 36.219895 | 107 | py |
PointContrast | PointContrast-main/downstream/votenet_det_new/lib/utils/metric_util.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
""" Utility functions for metric evaluation.
Author: Or Litany and Charles R. Qi
"""
import os
import sys
import torch
BASE_DIR = os.path.d... | 5,891 | 33.057803 | 106 | py |
PointContrast | PointContrast-main/downstream/votenet_det_new/lib/utils/nn_distance.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
""" Chamfer distance in Pytorch.
Author: Charles R. Qi
"""
import torch
import torch.nn as nn
import numpy as np
def huber_loss(error, del... | 2,924 | 29.789474 | 89 | py |
authorship-embeddings | authorship-embeddings-main/losses.py | import torch
import torch.nn.functional as F
def oneway_infonce_loss(a, b, t, smoothing=0.0, labels=None):
logits = (F.normalize(a) @ F.normalize(b.T)) * torch.exp(t).clamp(max=100)
loss = F.cross_entropy(logits, labels, label_smoothing=smoothing).mean()
with torch.no_grad():
preds = logits.ar... | 6,497 | 39.6125 | 140 | py |
authorship-embeddings | authorship-embeddings-main/run_experiment.py | ###############################################################################
# Imports #####################################################################
###############################################################################
import pandas as pd
import numpy as np
import wandb
from datetime import dateti... | 8,208 | 41.097436 | 111 | py |
authorship-embeddings | authorship-embeddings-main/modules.py | import torch
import pytorch_lightning as pl
from torch.nn.utils.rnn import pack_padded_sequence, pad_packed_sequence
import torch.nn.functional as F
class DynamicLSTM(pl.LightningModule):
def __init__(self, input_size, hidden_size=100,
num_layers=1, dropout=0., bidirectional=False):
supe... | 1,879 | 34.471698 | 91 | py |
authorship-embeddings | authorship-embeddings-main/model.py | import torch
from transformers import AdamW, get_linear_schedule_with_warmup
import pytorch_lightning as pl
import torch.nn.functional as F
from modules import DynamicLSTM
from losses import SupConLoss
class ContrastivePretrain(pl.LightningModule):
def switch_finetune(self, switch=True):
for param in se... | 7,527 | 33.691244 | 102 | py |
authorship-embeddings | authorship-embeddings-main/data.py | import torch
import numpy as np
from random import shuffle
from torch.utils.data import Dataset, DataLoader
from ast import literal_eval
from tqdm import tqdm
def join_text(list_text):
return ' '.join(list_text)
class ContrastDataset(Dataset):
def __init__(self, text_data, steps, window=512):
self.te... | 7,104 | 34 | 109 | py |
trf-sg2im | trf-sg2im-main/modules/graph_trf.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from einops import rearrange
from trainers.t_base import _init_weights
from utils.layers import build_mlp
from utils.model import MultiHeadAttentionLayer
def get_lap_pos_enc(graph):
# Implementation from graphtransformer
lap_pos_enc = graph.nd... | 7,071 | 30.713004 | 153 | py |
trf-sg2im | trf-sg2im-main/modules/gpt.py | import math
import torch
import torch.nn as nn
import torch.nn.functional as F
from einops import rearrange, repeat
from torch import einsum, nn
class GPTConfig:
""" base GPT config, params common to all GPT versions """
embd_pdrop = 0.1
resid_pdrop = 0.1
attn_pdrop = 0.1
def __init__(self, voca... | 13,129 | 41.083333 | 126 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.