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 |
|---|---|---|---|---|---|---|
AdversariallyRobustTraining | AdversariallyRobustTraining-master/DeepFool.py | import numpy as np
from torch.autograd import Variable
import torch as torch
import copy
import math
from torch.autograd.gradcheck import zero_gradients
def deepfool(image, net, num_classes=10, overshoot=0.02, max_iter=50):
"""
:param image: Image of size HxWx3
:param net: network (input: images, ou... | 2,992 | 30.177083 | 142 | py |
AdversariallyRobustTraining | AdversariallyRobustTraining-master/DatasetCIFAR10.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu May 28 16:08:05 2020
@author: ngopc
"""
import numpy as np
import torchvision
import torchvision.transforms as transforms
from DatasetTemplate import DatasetTemplate
from AutoAugment import CIFAR10Policy
class DatasetCIFAR10(DatasetTemplate):
def ... | 3,630 | 36.43299 | 111 | py |
AdversariallyRobustTraining | AdversariallyRobustTraining-master/LossFunction.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Utility class containing the loss functions described in the paper.
import torch
import torch.nn.functional as F
from torch.nn.modules.loss import _Loss
class CELoss(_Loss):
"""Creates a criterion that does Crossentropy Loss. This is a wrapper function
which e... | 2,778 | 33.308642 | 97 | py |
AdversariallyRobustTraining | AdversariallyRobustTraining-master/DataHandler.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import torch
from torch.utils.data import Dataset
from PIL import Image
from tqdm import tqdm
import matplotlib.pyplot as plt
import numpy as np
class DataHandler:
def __init__(self, dataset_class, device):
self.transform_train = dataset_class.transform_train... | 2,569 | 28.883721 | 176 | py |
AdversariallyRobustTraining | AdversariallyRobustTraining-master/getTestAcc.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Gets the accuracy of the model on the test split of the dataset. No adversarial attack is performed.
import argparse
import numpy as np
import os
import pandas as pd
import pickle
import torch
import math
from DataHandler import DataHandler
from Seed import getSeed
fr... | 6,050 | 48.195122 | 211 | py |
AdversariallyRobustTraining | AdversariallyRobustTraining-master/Logging.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Utility class that handles printing to the console and logging results of training.
import os
import json
import datetime
import torch
from torch.utils.tensorboard import SummaryWriter
class Logging:
def __init__(self, result_dict):
# If not resuming trai... | 3,007 | 40.777778 | 297 | py |
AdversariallyRobustTraining | AdversariallyRobustTraining-master/getScheduler.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 3 18:04:44 2020
@author: amadeusaw
"""
import torch.optim.lr_scheduler as scheduler1
import Scheduler as scheduler2
class lr_scheduler:
def StepLR(optimizer, step_size, gamma=0.1, last_epoch=-1):
return scheduler1.StepLR(optimizer, ste... | 975 | 47.8 | 223 | py |
AdversariallyRobustTraining | AdversariallyRobustTraining-master/Optimizers.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Utility file that contains some optimizers for training.
import torch
# This is the optimizer class built into pytorch
from torch import optim as optim1
# This is the third party optimizer class that came from pip install torch_optimizer
#import torch_optimizer as opti... | 1,996 | 48.925 | 123 | py |
AdversariallyRobustTraining | AdversariallyRobustTraining-master/LoadModel.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Utility class to handle loading of different model architectures. All models are defined in /models/
from torchvision.models import resnet18, resnet34, resnet50
from models.BasicModel import BasicModel
from models.ResNet import ResNet9, ResNet9Mod, ResNet18, ResNet34, ... | 2,320 | 50.577778 | 120 | py |
AdversariallyRobustTraining | AdversariallyRobustTraining-master/FoolboxAttack.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 2 18:43:53 2020
@author: ngopc
"""
import numpy as np
import torch
import torchvision
import torch.nn as nn
from torchvision import transforms
import math
import json
#from FGSM import fgsm
import foolbox.attacks as fa
from foolbox import PyTorc... | 12,115 | 35.826748 | 113 | py |
AdversariallyRobustTraining | AdversariallyRobustTraining-master/DatasetImagenette.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Utility class to prepare the train, validation and test splits of the Imagenette dataset.
import os
import torch
import numpy as np
import torchvision.transforms as transforms
from AutoAugment import ImageNetPolicy
from DatasetTemplate import DatasetTemplate
from PIL ... | 8,971 | 40.925234 | 129 | py |
AdversariallyRobustTraining | AdversariallyRobustTraining-master/DatasetTemplate.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 3 11:03:05 2020
@author: ngopc
"""
import numpy as np
import torchvision.transforms as transforms
from LoadModel import loadModel
class DatasetTemplate:
#You need to override this __init__ method
def __init__(self):
self.param = {... | 2,952 | 45.140625 | 121 | py |
AdversariallyRobustTraining | AdversariallyRobustTraining-master/DatasetMNIST.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import numpy as np
import torchvision
import torchvision.transforms as transforms
from DatasetTemplate import DatasetTemplate
class DatasetMNIST(DatasetTemplate):
def __init__(self, param):
DatasetTemplate.__init__(self)
self.param = param
se... | 3,328 | 36.829545 | 125 | py |
AdversariallyRobustTraining | AdversariallyRobustTraining-master/Scheduler.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 3 17:01:03 2020
@author: amadeusaw
"""
import math
#import warnings
#from torch.optim.lr_scheduler import _LRScheduler
class LinearCosineLR():
"""Sets the learning rate of each parameter group to the initial lr
for a given amount of time ... | 2,273 | 35.677419 | 103 | py |
AdversariallyRobustTraining | AdversariallyRobustTraining-master/getRho.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Gets the adversarial ratio which is essentially the percentage of the image that needs to be perturbed before the adversarial attack is considered succesful
# The higher this ratio, the more robust the model is
# In this case, the attack used in the paper was DeepFool
... | 7,289 | 48.256757 | 211 | py |
AdversariallyRobustTraining | AdversariallyRobustTraining-master/jacobian/jacobian.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.
PyTorch implementation of Jacobian regularization described in [1].
[1] Judy Hoffman, Daniel A. Roberts, and Sho Yaida,
... | 2,967 | 33.511628 | 76 | py |
AdversariallyRobustTraining | AdversariallyRobustTraining-master/models/ResNet.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Utility class that implements variants of the ResNet.
# Reference:
# [1] Kaiming He, Xiangyu Zhang, Shaoqing Ren, Jian Sun
# Deep Residual Learning for Image Recognition. arXiv:1512.03385
import torch
import torch.nn as nn
import torch.nn.functional as F
import sy... | 11,336 | 33.354545 | 126 | py |
AdversariallyRobustTraining | AdversariallyRobustTraining-master/models/XResNet.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Utility class that implements XResNet variants.
import torch
import torch.nn as nn
from ImagenetteUtils.Downsample import Downsample
from ImagenetteUtils.Operations import conv, bn, act, conv_2d, selfattention, conv_2d_v2
import sys
import os
sys.path.insert(1, os.path.... | 13,576 | 35.497312 | 136 | py |
AdversariallyRobustTraining | AdversariallyRobustTraining-master/models/WideResNetModified.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Utility class that implements a modified version of the WideResNet.
import torch.nn as nn
import torch.nn.init as init
import torch.nn.functional as F
import numpy as np
def conv3x3(in_planes, out_planes, stride=1):
return nn.Conv2d(in_planes, out_planes, kernel_s... | 3,495 | 33.96 | 98 | py |
AdversariallyRobustTraining | AdversariallyRobustTraining-master/models/WideResNetOriginal.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Utility class that implements the original WideResNet. Code taken wholesale from https://github.com/meliketoy/wide-resnet.pytorch/blob/master/networks/wide_resnet.py
import torch
import torch.nn as nn
import torch.nn.init as init
import torch.nn.functional as F
from t... | 3,313 | 34.255319 | 168 | py |
AdversariallyRobustTraining | AdversariallyRobustTraining-master/models/BasicModel.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Utility class that implements the basic model used for the MNIST dataset in this paper.
import torch
import torch.nn as nn
import torch.nn.functional as F
import sys
import os
sys.path.insert(1, os.path.realpath(os.path.pardir))
from NoiseGenerator import NeighborGenera... | 3,414 | 35.72043 | 126 | py |
AdversariallyRobustTraining | AdversariallyRobustTraining-master/ImagenetteUtils/Downsample.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Utility class unmodified from https://github.com/adobe/antialiased-cnns/blob/master/models_lpf/downsample.py
import torch
import torch.nn.parallel
import numpy as np
import torch.nn as nn
import torch.nn.functional as F
class Downsample(nn.Module):
def __init__(se... | 4,318 | 36.556522 | 143 | py |
AdversariallyRobustTraining | AdversariallyRobustTraining-master/ImagenetteUtils/Activations.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Utility class of advanced activation functions, unmodified from Geffnet library
import torch
from torch import nn as nn
from torch.nn import functional as F
__all__ = ['swish_jit', 'SwishJit', 'mish_jit', 'MishJit']
@torch.jit.script
def swish_jit_fwd(x):
return ... | 2,139 | 26.088608 | 83 | py |
AdversariallyRobustTraining | AdversariallyRobustTraining-master/ImagenetteUtils/PrepImagenette.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Utility file to ensure that the Imagenette dataset follows certain guidelines to make dataset preparation faster.
# This code assumes that the Imagenette dataset has been downloaded from https://github.com/fastai/imagenette and placed the data directory.
import os
impo... | 2,610 | 29.360465 | 140 | py |
AdversariallyRobustTraining | AdversariallyRobustTraining-master/ImagenetteUtils/SelfAttention.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import torch
from torch.nn.utils import spectral_norm
import torch.nn as nn
# Unmodified from SelfAttention layer at https://github.com/sdoria/SimpleSelfAttention/blob/master/xresnet.py
def conv1d(ni:int, no:int, ks:int=1, stride:int=1, padding:int=0, bias:bool=False):
... | 1,770 | 34.42 | 109 | py |
AdversariallyRobustTraining | AdversariallyRobustTraining-master/ImagenetteUtils/Operations.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import torch.nn as nn
from .Activations import SwishJit, MishJit
from .Downsample import Downsample
class noop(nn.Module):
def __init__(self):
super(noop, self).__init__()
def forward(self, x):
return x
class SE(nn.Module):
def __in... | 2,492 | 31.802632 | 123 | py |
SS-Conv | SS-Conv-main/Common_utils/ss_conv_modules.py | # --------------------------------------------------------
# Sparse Steerable Convolutions
# Sparse steerable convolutional modules
# Written by Jiehong Lin
# --------------------------------------------------------
from functools import partial
import torch
import torch.nn as nn
import torch.nn.functional as F
impo... | 7,534 | 28.782609 | 124 | py |
SS-Conv | SS-Conv-main/Common_utils/metric_utils.py | # --------------------------------------------------------
# Sparse Steerable Convolutions
# Common metric utils
# Written by Jiehong Lin
# --------------------------------------------------------
import torch
import torch.nn as nn
def L2_Distance(p1, p2):
'''
p1: float B*N*3
p2: float B*N*3
return ... | 651 | 20.032258 | 62 | py |
SS-Conv | SS-Conv-main/Common_utils/ss_conv_backbones.py | # --------------------------------------------------------
# Sparse Steerable Convolutions.
# Sparse steerable convolutional backbones
# Written by Jiehong Lin
# --------------------------------------------------------
import torch
import torch.nn as nn
import torch.nn.functional as F
import ss_conv
from ss_conv.poo... | 6,228 | 30.780612 | 77 | py |
SS-Conv | SS-Conv-main/Common_utils/rotation_utils.py | # --------------------------------------------------------
# Sparse Steerable Convolutions
# Common utils w.r.t rotation
# Written by Jiehong Lin
# Modified from https://github.com/tscohen/se3cnn
# --------------------------------------------------------
import torch
import os
import numpy as np
dir_path = os.path.... | 13,798 | 28.803456 | 126 | py |
SS-Conv | SS-Conv-main/Common_utils/train_utils.py | # --------------------------------------------------------
# Sparse Steerable Convolutions
# Common utils for network training
# Written by Jiehong Lin
# --------------------------------------------------------
import os
import logging
from pickletools import optimize
import time
import torch
import gorilla
from tens... | 7,508 | 35.629268 | 167 | py |
SS-Conv | SS-Conv-main/REAL275/test.py | # --------------------------------------------------------
# Sparse Steerable Convolutions
# Evaluation on LinMOD dataset for 6D pose estimation
# Written by Jiehong Lin
# --------------------------------------------------------
import os
import sys
import numpy as np
import random
import argparse
from tqdm import tq... | 5,733 | 33.335329 | 111 | py |
SS-Conv | SS-Conv-main/REAL275/model_lite.py | # --------------------------------------------------------
# Sparse Steerable Convolutions
# Model based on Plain24 for category-level 6D pose estimation
# Written by Jiehong Lin
# --------------------------------------------------------
import numpy as np
import torch
import torch.nn as nn
import ss_conv
from ss_c... | 12,211 | 34.707602 | 104 | py |
SS-Conv | SS-Conv-main/REAL275/real275.py | # --------------------------------------------------------
# Sparse Steerable Convolutions
# Dataloder of REAL275 dataset
# Written by Jiehong Lin
# --------------------------------------------------------
import os
import math
import cv2
import numpy as np
import glob
import _pickle as cPickle
import torch
from tor... | 13,340 | 37.781977 | 181 | py |
SS-Conv | SS-Conv-main/REAL275/model.py | # --------------------------------------------------------
# Sparse Steerable Convolutions
# Model based on Plain24 for category-level 6D pose estimation
# Written by Jiehong Lin
# --------------------------------------------------------
import numpy as np
import torch
import torch.nn as nn
import ss_conv
from ss_c... | 12,251 | 34.824561 | 104 | py |
SS-Conv | SS-Conv-main/REAL275/train.py | # --------------------------------------------------------
# Sparse Steerable Convolutions
# Training on REAL275 dataset for category-level 6D pose estimation
# Written by Jiehong Lin
# --------------------------------------------------------
import os
import sys
import numpy as np
import random
import argparse
impor... | 3,639 | 32.090909 | 150 | py |
SS-Conv | SS-Conv-main/LineMOD/test.py | # --------------------------------------------------------
# Sparse Steerable Convolutions
# Evaluation on LinMOD dataset for 6D pose estimation
# Written by Jiehong Lin
# --------------------------------------------------------
import os
import sys
import numpy as np
import random
import argparse
from tqdm import tq... | 6,052 | 35.029762 | 155 | py |
SS-Conv | SS-Conv-main/LineMOD/model.py | # --------------------------------------------------------
# Sparse Steerable Convolutions
# Model based on Plain24 for 6D pose estimation
# Written by Jiehong Lin
# --------------------------------------------------------
import numpy as np
import torch
import torch.nn as nn
import ss_conv
from ss_conv.pool import ... | 9,218 | 34.457692 | 102 | py |
SS-Conv | SS-Conv-main/LineMOD/tiny_model.py | # --------------------------------------------------------
# Sparse Steerable Convolutions
# A tiny model based on Plain12 for 6D pose estimation
# Written by Jiehong Lin
# --------------------------------------------------------
import torch
import torch.nn as nn
import ss_conv
from ss_conv.pool import GlobalAvgPoo... | 4,098 | 33.158333 | 86 | py |
SS-Conv | SS-Conv-main/LineMOD/linemod.py | # --------------------------------------------------------
# Sparse Steerable Convolutions
# Dataloder of LineMOD dataset
# Modified from https://github.com/j96w/DenseFusion by Jiehong Lin
# --------------------------------------------------------
import os
import numpy as np
import numpy.ma as ma
import math
import ... | 11,098 | 36.880546 | 179 | py |
SS-Conv | SS-Conv-main/LineMOD/train.py | # --------------------------------------------------------
# Sparse Steerable Convolutions
# Training on LinMOD dataset for 6D pose estimation
# Written by Jiehong Lin
# --------------------------------------------------------
import os
import sys
import numpy as np
import random
import argparse
import logging
import... | 3,661 | 31.990991 | 150 | py |
SS-Conv | SS-Conv-main/SS_Conv_lib/setup.py | import os
from glob import glob
from setuptools import setup, find_packages
from distutils.sysconfig import get_python_inc
from torch.utils.cpp_extension import BuildExtension, CUDAExtension
_ext_sources = []
_include_dirs= [os.path.dirname(get_python_inc(plat_specific=1)), ]
root_source = 'src'
for op in os.listdir(... | 1,238 | 32.486486 | 111 | py |
SS-Conv | SS-Conv-main/SS_Conv_lib/ss_conv/activation.py | # --------------------------------------------------------
# Sparse Steerable Convolution Lib.
# Sparse SE(3)-equivariant activation
# Written by Hongyang Li and Jiehong Lin
# Modified From https://github.com/tscohen/se3cnn
# --------------------------------------------------------
import torch
import torch.nn as nn... | 5,051 | 30.185185 | 113 | py |
SS-Conv | SS-Conv-main/SS_Conv_lib/ss_conv/batchnorm.py | # --------------------------------------------------------
# Sparse Steerable Convolution Lib.
# Sparse SE(3)-equivariant batch norm
# Written by Hongyang Li and Jiehong Lin
# Modified From https://github.com/tscohen/se3cnn
# --------------------------------------------------------
import torch
import torch.nn as nn... | 4,810 | 33.862319 | 118 | py |
SS-Conv | SS-Conv-main/SS_Conv_lib/ss_conv/convolution.py | # --------------------------------------------------------
# Sparse Steerable Convolution Lib.
# Sparse steerable convolutional operation
# Written by Jiehong Lin and Hongyang Li
# --------------------------------------------------------
import math
import torch
import torch.nn as nn
from torch.nn.parameter import Pa... | 2,528 | 31.844156 | 122 | py |
SS-Conv | SS-Conv-main/SS_Conv_lib/ss_conv/dropout.py | # ----------------------------------------------------------------
# Sparse Steerable Convolutions
# Dropout for sparse tensors
# Modified from https://github.com/tscohen/se3cnn
# by Jiehong Lin and Hongyang Li
# ----------------------------------------------------------------
import torch
import torch.nn as nn
c... | 1,247 | 26.130435 | 90 | py |
SS-Conv | SS-Conv-main/SS_Conv_lib/ss_conv/pool.py | # --------------------------------------------------------
# Sparse Steerable Convolution Lib.
# Local & global pooling operations
# Written by Jiehong Lin and Hongyang Li
# --------------------------------------------------------
import torch
import torch.nn as nn
from ss_conv.sp_ops.tensor import SparseTensor
from... | 2,476 | 25.923913 | 74 | py |
SS-Conv | SS-Conv-main/SS_Conv_lib/ss_conv/sp_ops/functional.py | # --------------------------------------------------------
# Sparse Steerable Convolution Lib.
# Functions on Sparse Tensors
# Written by Hongyang Li and Jiehong Lin
# Modified from https://github.com/traveller59/spconv/tree/v1.1
# and https://github.com/dvlab-research/PointGroup
# ------------------------------------... | 15,202 | 32.486784 | 140 | py |
SS-Conv | SS-Conv-main/SS_Conv_lib/ss_conv/sp_ops/voxelize.py | # --------------------------------------------------------
# Sparse Steerable Convolution Lib.
# Functions on Sparse Tensors
# Written by Hongyang Li and Jiehong Lin
# Modified from https://github.com/traveller59/spconv/tree/v1.1
# and https://github.com/dvlab-research/PointGroup
# ------------------------------------... | 7,444 | 39.243243 | 120 | py |
SS-Conv | SS-Conv-main/SS_Conv_lib/ss_conv/sp_ops/ops.py | # --------------------------------------------------------
# Sparse Steerable Convolution Lib.
# Operations on Sparse Tensors
# Written by Hongyang Li and Jiehong Lin
# Modified from https://github.com/traveller59/spconv/tree/v1.1
# and https://github.com/dvlab-research/PointGroup
# -----------------------------------... | 7,836 | 38.781726 | 108 | py |
SS-Conv | SS-Conv-main/SS_Conv_lib/ss_conv/sp_ops/conv.py | # --------------------------------------------------------
# Sparse Steerable Convolution Lib.
# Convolutions on Sparse Tensors
# Written by Jiehong Lin
# Modified from https://github.com/traveller59/spconv/tree/v1.1
# --------------------------------------------------------
import numpy as np
import math
import torc... | 6,102 | 36.67284 | 131 | py |
SS-Conv | SS-Conv-main/SS_Conv_lib/ss_conv/sp_ops/pool.py | # --------------------------------------------------------
# Sparse Steerable Convolution Lib.
# Functions on Sparse Tensors
# Written by Hongyang Li and Jiehong Lin
# Modified from https://github.com/traveller59/spconv/tree/v1.1
# --------------------------------------------------------
import torch
import torch.nn a... | 4,352 | 36.852174 | 90 | py |
SS-Conv | SS-Conv-main/SS_Conv_lib/ss_conv/sp_ops/tensor.py | # Modified from https://github.com/traveller59/spconv/tree/v1.1
import numpy as np
import torch
def scatter_nd(indices, updates, shape):
"""pytorch edition of tensorflow scatter_nd.
this function don't contain except handle code. so use this carefully
when indice repeats, don't support repeat add which is... | 2,409 | 33.428571 | 94 | py |
SS-Conv | SS-Conv-main/SS_Conv_lib/ss_conv/utils/utils.py | # Modified From https://github.com/tscohen/se3cnn
# Written by Jiehong Lin and Hongyang Li
import torch
def Rs2dim(Rs):
dim = 0
for m,l in Rs:
dim += (l*2 + 1)*m
return dim
def calculate_fan_in(channel_in, kernel_size):
# channel_in: int
# chennel_out: int
# kenerl_size: torch.tenso... | 736 | 21.333333 | 55 | py |
SS-Conv | SS-Conv-main/SS_Conv_lib/ss_conv/utils/SO3.py | # pylint: disable=C,E1101,E1102
'''
Some functions related to SO3 and his usual representations
Using ZYZ Euler angles parametrisation
Modified From https://github.com/tscohen/se3cnn
'''
import torch
import math
from .utils import torch_default_dtype
from .cache_file import cached_dirpklgz
def rot_z(gamma):
''... | 13,956 | 31.762911 | 128 | py |
SS-Conv | SS-Conv-main/SS_Conv_lib/ss_conv/utils/kernel.py | # pylint: disable=C,R,E1101,E1102
# Modified From https://github.com/tscohen/se3cnn
import torch
from .SO3 import irr_repr, spherical_harmonics_xyz, basis_transformation_Q_J, rot
from .cache_file import cached_dirpklgz
import math
@cached_dirpklgz("cache/sh_cube")
def _sample_sh_cube(size, J, version=3): # pylint:... | 14,240 | 40.278261 | 164 | py |
rl-baselines3-zoo | rl-baselines3-zoo-master/rl_zoo3/push_to_hub.py | import argparse
import glob
import os
import shutil
import zipfile
from copy import deepcopy
from pathlib import Path
from pprint import pformat
from typing import Any, Dict, Optional, Tuple
import torch as th
import yaml
from huggingface_hub import HfApi, Repository
from huggingface_hub.repocard import metadata_save
... | 15,761 | 35.741259 | 126 | py |
rl-baselines3-zoo | rl-baselines3-zoo-master/rl_zoo3/utils.py | import argparse
import glob
import importlib
import os
from copy import deepcopy
from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union
import gym as gym26
import gymnasium as gym
import stable_baselines3 as sb3 # noqa: F401
import torch as th # noqa: F401
import yaml
from gymnasium import spaces... | 17,652 | 33.613725 | 122 | py |
rl-baselines3-zoo | rl-baselines3-zoo-master/rl_zoo3/exp_manager.py | import argparse
import importlib
import os
import pickle as pkl
import time
import warnings
from collections import OrderedDict
from pathlib import Path
from pprint import pprint
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
import gym as gym26
import gymnasium as gym
import numpy as np
import o... | 36,242 | 38.609836 | 124 | py |
rl-baselines3-zoo | rl-baselines3-zoo-master/rl_zoo3/hyperparams_opt.py | from typing import Any, Dict
import numpy as np
import optuna
from stable_baselines3.common.noise import NormalActionNoise, OrnsteinUhlenbeckActionNoise
from torch import nn as nn
from rl_zoo3 import linear_schedule
def sample_ppo_params(trial: optuna.Trial) -> Dict[str, Any]:
"""
Sampler for PPO hyperparam... | 20,864 | 38.146341 | 118 | py |
rl-baselines3-zoo | rl-baselines3-zoo-master/rl_zoo3/train.py | import argparse
import difflib
import importlib
import os
import time
import uuid
import gym as gym26
import gymnasium as gym
import numpy as np
import stable_baselines3 as sb3
import torch as th
from stable_baselines3.common.utils import set_random_seed
# Register custom envs
import rl_zoo3.import_envs # noqa: F401... | 11,132 | 39.483636 | 127 | py |
rl-baselines3-zoo | rl-baselines3-zoo-master/rl_zoo3/enjoy.py | import argparse
import importlib
import os
import sys
import numpy as np
import torch as th
import yaml
from huggingface_sb3 import EnvironmentName
from stable_baselines3.common.callbacks import tqdm
from stable_baselines3.common.utils import set_random_seed
import rl_zoo3.import_envs # noqa: F401 pylint: disable=un... | 10,854 | 37.767857 | 126 | py |
rl-baselines3-zoo | rl-baselines3-zoo-master/hyperparams/python/ppo_config_example.py | """This file just serves as an example on how to configure the zoo
using python scripts instead of yaml files."""
import torch
hyperparams = {
"MountainCarContinuous-v0": dict(
env_wrapper=[{"gymnasium.wrappers.TimeLimit": {"max_episode_steps": 100}}],
normalize=True,
n_envs=1,
n_ti... | 773 | 24.8 | 83 | py |
rl-baselines3-zoo | rl-baselines3-zoo-master/scripts/create_mujoco_jobs.py | import os
import subprocess
import time
import numpy as np
ALGOS = ["sac", "td3", "tqc"]
# "Humanoid-v3",
ENVS = ["HalfCheetah-v3", "Ant-v3", "Hopper-v3", "Walker2d-v3", "Swimmer-v3"]
N_SEEDS = 1
EVAL_FREQ = 25000
N_EVAL_EPISODES = 20
N_EVAL_ENVS = 5
np.random.seed(8)
SEEDS = np.random.randint(2**20, size=(N_SEEDS,))... | 1,412 | 24.232143 | 100 | py |
rl-baselines3-zoo | rl-baselines3-zoo-master/scripts/create_cluster_jobs.py | """
Send multiple jobs to the cluster.
"""
import os
import subprocess
import time
from typing import List
import numpy as np
ALGOS = ["sac"]
ENVS = ["HalfCheetahBulletEnv-v0"]
N_SEEDS = 5
N_EVAL_EPISODES = 10
LOG_STD_INIT = [-6, -5, -4, -3, -2, -1, 0, 1]
os.makedirs(os.path.join("logs", "slurm"), exist_ok=True)
fo... | 1,238 | 27.813953 | 104 | py |
rl-baselines3-zoo | rl-baselines3-zoo-master/docs/conf.py | #
# Configuration file for the Sphinx documentation builder.
#
# This file does only contain a selection of the most common options. For a
# full list see the documentation:
# http://www.sphinx-doc.org/en/master/config
# -- Path setup --------------------------------------------------------------
# If extensions (or ... | 6,998 | 29.298701 | 110 | py |
ReCOGS | ReCOGS-main/run_cogs.py | from utils.train_utils import *
from datetime import date
import json
if __name__ == '__main__':
is_notebook = False
try:
cmd = argparse.ArgumentParser('The testing components of')
cmd.add_argument('--gpu', default=-1, type=int, help='use id of gpu, -1 if cpu.')
cmd.add_argument('--trai... | 19,519 | 43.063205 | 122 | py |
ReCOGS | ReCOGS-main/utils/second_looks_utils.py | from __future__ import absolute_import, division, print_function
import pandas as pd
import re, random, copy
import pandas as pd
import re, random, copy
import collections
import unicodedata
import torch
import six
from torch.utils.data import Dataset
import random
import numpy as np
import json
np_re = re.compile(... | 3,451 | 25.553846 | 113 | py |
ReCOGS | ReCOGS-main/utils/train_utils.py | import random
import torch
from transformers import AutoConfig, AutoTokenizer, AdamW, get_linear_schedule_with_warmup
import argparse
import sys
from torch.utils.data import DataLoader, SequentialSampler
from torch.utils.data.distributed import DistributedSampler
from tqdm import tqdm, trange
import numpy as np
import ... | 17,385 | 34.052419 | 105 | py |
ReCOGS | ReCOGS-main/utils/cogs_utils.py | from __future__ import absolute_import, division, print_function
import collections
import unicodedata
import torch
import six
from torch.utils.data import Dataset
import random
import numpy as np
def glove2dict(src_filename):
"""
GloVe vectors file reader.
Parameters
----------
src_filename : str... | 7,100 | 33.470874 | 85 | py |
ReCOGS | ReCOGS-main/model/encoder_decoder_hf.py | # coding=utf-8
# Copyright 2018 The HuggingFace Inc. team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable... | 49,415 | 55.090806 | 198 | py |
ReCOGS | ReCOGS-main/model/utils.py | import numpy as np
import torch
from torch import nn
import torch.nn.functional as F
class AverageMeter(object):
def __init__(self):
self.reset()
def reset(self):
self.val = 0
self.avg = 0
self.sum = 0
self.count = 0
def update(self, val, n=1):
self.val =... | 3,786 | 27.689394 | 120 | py |
ReCOGS | ReCOGS-main/model/encoder_decoder_lstm.py | '''
Reference:
https://github.com/marumalo/pytorch-seq2seq/blob/master/model.py
'''
# -*- coding: utf-8 -*-
import random
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn import CrossEntropyLoss
from transformers.modeling_outputs import BaseModelOutput, Seq2SeqLMOutput
from transforme... | 8,424 | 40.502463 | 108 | py |
AISFormer | AISFormer-master/setup.py | #!/usr/bin/env python
# Copyright (c) Facebook, Inc. and its affiliates.
import glob
import os
import shutil
from os import path
from setuptools import find_packages, setup
from typing import List
import torch
from torch.utils.cpp_extension import CUDA_HOME, CppExtension, CUDAExtension
torch_ver = [int(x) for x in to... | 7,828 | 36.280952 | 97 | py |
AISFormer | AISFormer-master/tools/train_net_ema.py | #!/usr/bin/env python
# Copyright (c) Facebook, Inc. and its affiliates.
"""
A main training script.
This scripts reads a given config file and runs the training or evaluation.
It is an entry point that is made to train standard models in detectron2.
In order to let one script support training of many models,
this sc... | 10,998 | 35.42053 | 102 | py |
AISFormer | AISFormer-master/tools/benchmark.py | #!/usr/bin/env python
# Copyright (c) Facebook, Inc. and its affiliates.
"""
A script to benchmark builtin models.
Note: this script has an extra dependency of psutil.
"""
import itertools
import logging
import psutil
import torch
import tqdm
from fvcore.common.timer import Timer
from torch.nn.parallel import Distrib... | 6,377 | 31.212121 | 100 | py |
AISFormer | AISFormer-master/tools/visualize_data.py | #!/usr/bin/env python
# Copyright (c) Facebook, Inc. and its affiliates.
import argparse
import os
from itertools import chain
import cv2
import tqdm
from detectron2.config import get_cfg
from detectron2.data import DatasetCatalog, MetadataCatalog, build_detection_train_loader
from detectron2.data import detection_uti... | 3,565 | 36.536842 | 94 | py |
AISFormer | AISFormer-master/tools/lightning_train_net.py | #!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates.
# Lightning Trainer should be considered beta at this point
# We have confirmed that training and validation run correctly and produce correct results
# Depending on how you launch the trainer, there are issues with processes terminating correctl... | 8,752 | 35.470833 | 97 | py |
AISFormer | AISFormer-master/tools/visualize_emb_atn.py | import torch.nn as nn
import os
from detetron2.modeling.roi_heads.aistr.aistr_enfeat import AISTREncodeFeat
from tools.add_config import add_config
from detectron2.config import get_cfg
from detectron2.layers import ShapeSpec
def main():
model_path = ""
cfg = get_cfg()
add_config(cfg)
cfg.merge_from_fi... | 2,032 | 26.106667 | 82 | py |
AISFormer | AISFormer-master/tools/plain_train_net.py | #!/usr/bin/env python
# Copyright (c) Facebook, Inc. and its affiliates.
"""
Detectron2 training script with a plain training loop.
This script reads a given config file and runs the training or evaluation.
It is an entry point that is able to train standard models in detectron2.
In order to let one script support tr... | 7,894 | 35.215596 | 99 | py |
AISFormer | AISFormer-master/tools/convert-torchvision-to-d2.py | #!/usr/bin/env python
# Copyright (c) Facebook, Inc. and its affiliates.
import pickle as pkl
import sys
import torch
"""
Usage:
# download one of the ResNet{18,34,50,101,152} models from torchvision:
wget https://download.pytorch.org/models/resnet50-19c8e357.pth -O r50.pth
# run the conversion
./convert-torc... | 1,608 | 27.22807 | 87 | py |
AISFormer | AISFormer-master/tools/visualize_GT_new.py | from pycocotools.coco import COCO
import pycocotools.mask as maskUtils
import imantics
from PIL import Image, ImageDraw
import numpy as np
import matplotlib.pyplot as plt
import cv2
from tools.vis_gt import IMG_DIR
from skimage.transform import resize
from detectron2.utils.visualizer import ColorMode, Visualizer
from d... | 4,346 | 30.729927 | 105 | py |
AISFormer | AISFormer-master/tools/visualize_single_intro.py | from pycocotools.coco import COCO
import pycocotools.mask as maskUtils
import imantics
from PIL import Image, ImageDraw
import numpy as np
import matplotlib.pyplot as plt
import cv2
from tools.vis_gt import IMG_DIR
from skimage.transform import resize
from detectron2.utils.visualizer import ColorMode, Visualizer
from d... | 4,681 | 32.442857 | 135 | py |
AISFormer | AISFormer-master/tools/deploy/export_model.py | #!/usr/bin/env python
# Copyright (c) Facebook, Inc. and its affiliates.
import argparse
import os
from typing import Dict, List, Tuple
import torch
from torch import Tensor, nn
import detectron2.data.transforms as T
from detectron2.checkpoint import DetectionCheckpointer
from detectron2.config import get_cfg
from det... | 9,243 | 38.169492 | 97 | py |
AISFormer | AISFormer-master/detectron2/model_zoo/model_zoo.py | # Copyright (c) Facebook, Inc. and its affiliates.
import os
from typing import Optional
import pkg_resources
import torch
from detectron2.checkpoint import DetectionCheckpointer
from detectron2.config import CfgNode, LazyConfig, get_cfg, instantiate
from detectron2.modeling import build_model
class _ModelZooUrls(ob... | 11,263 | 51.635514 | 113 | py |
AISFormer | AISFormer-master/detectron2/solver/lr_scheduler.py | # Copyright (c) Facebook, Inc. and its affiliates.
import logging
import math
from bisect import bisect_right
from typing import List
import torch
from fvcore.common.param_scheduler import (
CompositeParamScheduler,
ConstantParamScheduler,
LinearParamScheduler,
ParamScheduler,
)
logger = logging.getLog... | 8,648 | 35.188285 | 100 | py |
AISFormer | AISFormer-master/detectron2/solver/build.py | # Copyright (c) Facebook, Inc. and its affiliates.
import copy
import itertools
import logging
from collections import defaultdict
from enum import Enum
from typing import Any, Callable, Dict, Iterable, List, Optional, Set, Type, Union
import torch
from fvcore.common.param_scheduler import CosineParamScheduler, MultiSt... | 11,127 | 37.638889 | 92 | py |
AISFormer | AISFormer-master/detectron2/evaluation/amodal_visible_evaluation.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
import contextlib
import copy
import io
import itertools
import json
import logging
import numpy as np
import os
import pickle
from PIL import Image
from collections import OrderedDict
import pycocotools.mask as mask_util
import torch
from fvcore.co... | 39,547 | 45.200935 | 168 | py |
AISFormer | AISFormer-master/detectron2/evaluation/lvis_evaluation.py | # Copyright (c) Facebook, Inc. and its affiliates.
import copy
import itertools
import json
import logging
import os
import pickle
from collections import OrderedDict
import torch
import detectron2.utils.comm as comm
from detectron2.config import CfgNode
from detectron2.data import MetadataCatalog
from detectron2.stru... | 15,018 | 38.419948 | 150 | py |
AISFormer | AISFormer-master/detectron2/evaluation/cityscapes_evaluation.py | # Copyright (c) Facebook, Inc. and its affiliates.
import glob
import logging
import numpy as np
import os
import tempfile
from collections import OrderedDict
import torch
from PIL import Image
from detectron2.data import MetadataCatalog
from detectron2.utils import comm
from detectron2.utils.file_io import PathManage... | 8,369 | 41.272727 | 139 | py |
AISFormer | AISFormer-master/detectron2/evaluation/evaluator.py | # Copyright (c) Facebook, Inc. and its affiliates.
import datetime
import logging
import time
from collections import OrderedDict, abc
from contextlib import ExitStack, contextmanager
from typing import List, Union
import torch
from torch import nn
from detectron2.utils.comm import get_world_size, is_main_process
from... | 8,156 | 35.253333 | 99 | py |
AISFormer | AISFormer-master/detectron2/evaluation/sem_seg_evaluation.py | # Copyright (c) Facebook, Inc. and its affiliates.
import itertools
import json
import logging
import numpy as np
import os
from collections import OrderedDict
import PIL.Image as Image
import pycocotools.mask as mask_util
import torch
from detectron2.data import DatasetCatalog, MetadataCatalog
from detectron2.utils.c... | 7,638 | 40.291892 | 100 | py |
AISFormer | AISFormer-master/detectron2/evaluation/pascal_voc_evaluation.py | # -*- coding: utf-8 -*-
# Copyright (c) Facebook, Inc. and its affiliates.
import logging
import numpy as np
import os
import tempfile
import xml.etree.ElementTree as ET
from collections import OrderedDict, defaultdict
from functools import lru_cache
import torch
from detectron2.data import MetadataCatalog
from detec... | 10,862 | 35.089701 | 99 | py |
AISFormer | AISFormer-master/detectron2/evaluation/rotated_coco_evaluation.py | # Copyright (c) Facebook, Inc. and its affiliates.
import itertools
import json
import numpy as np
import os
import torch
from pycocotools.cocoeval import COCOeval, maskUtils
from detectron2.structures import BoxMode, RotatedBoxes, pairwise_iou_rotated
from detectron2.utils.file_io import PathManager
from .coco_evalu... | 7,608 | 35.581731 | 94 | py |
AISFormer | AISFormer-master/detectron2/evaluation/coco_evaluation.py | # Copyright (c) Facebook, Inc. and its affiliates.
import contextlib
import copy
import io
import itertools
import json
import logging
import numpy as np
import os
import pickle
from collections import OrderedDict
import pycocotools.mask as mask_util
import torch
from pycocotools.coco import COCO
from pycocotools.cocoe... | 30,423 | 41.080221 | 168 | py |
AISFormer | AISFormer-master/detectron2/checkpoint/c2_model_loading.py | # Copyright (c) Facebook, Inc. and its affiliates.
import copy
import logging
import re
from typing import Dict, List
import torch
from tabulate import tabulate
def convert_basic_c2_names(original_keys):
"""
Apply some basic name conversion to names in C2 weights.
It only deals with typical backbone model... | 17,770 | 42.556373 | 99 | py |
AISFormer | AISFormer-master/detectron2/checkpoint/detection_checkpoint.py | # Copyright (c) Facebook, Inc. and its affiliates.
import logging
import os
import pickle
import torch
from fvcore.common.checkpoint import Checkpointer
from torch.nn.parallel import DistributedDataParallel
import detectron2.utils.comm as comm
from detectron2.utils.file_io import PathManager
from .c2_model_loading im... | 5,213 | 42.090909 | 98 | py |
AISFormer | AISFormer-master/detectron2/layers/nms.py | # -*- coding: utf-8 -*-
# Copyright (c) Facebook, Inc. and its affiliates.
import torch
from torchvision.ops import boxes as box_ops
from torchvision.ops import nms # noqa . for compatibility
def batched_nms(
boxes: torch.Tensor, scores: torch.Tensor, idxs: torch.Tensor, iou_threshold: float
):
"""
Same... | 6,490 | 45.364286 | 98 | py |
AISFormer | AISFormer-master/detectron2/layers/batch_norm.py | # Copyright (c) Facebook, Inc. and its affiliates.
import torch
import torch.distributed as dist
from fvcore.nn.distributed import differentiable_all_reduce
from torch import nn
from torch.nn import functional as F
from detectron2.utils import comm, env
from .wrappers import BatchNorm2d
class FrozenBatchNorm2d(nn.M... | 11,155 | 39.274368 | 99 | py |
AISFormer | AISFormer-master/detectron2/layers/deform_conv.py | # Copyright (c) Facebook, Inc. and its affiliates.
import math
from functools import lru_cache
import torch
from torch import nn
from torch.autograd import Function
from torch.autograd.function import once_differentiable
from torch.nn.modules.utils import _pair
from torchvision.ops import deform_conv2d
from detectron2... | 16,978 | 31.968932 | 99 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.