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 |
|---|---|---|---|---|---|---|
nninfo | nninfo-main/nninfo/tasks/mnist_binary_task.py | import torch
import torchvision.datasets
from .task import Task
class MnistBinaryTask(Task):
task_id = "mnist_binary_dat"
@property
def finite(self):
return True
@property
def x_limits(self):
return (0, 1)
@property
def y_limits(self):
return "binary"
@prope... | 1,247 | 25 | 67 | py |
nninfo | nninfo-main/nninfo/tasks/mnist_reduced_task.py | import torch
import torchvision.datasets
from .task import Task
class ReducedMnistTask(Task):
task_id = "mnist_reduced_dat"
@property
def finite(self):
return True
@property
def x_limits(self):
return (0, 1)
@property
def y_limits(self):
return "binary"
@pro... | 987 | 21.454545 | 67 | py |
nninfo | nninfo-main/nninfo/tasks/combined_mnist_task.py | import torch
import torchvision.datasets
from .task import Task
class CombinedMnistTask(Task):
task_id = "combined_mnist_1d_dat"
@property
def finite(self):
return True
@property
def x_limits(self):
return (0, 1)
@property
def y_limits(self):
return "binary"
... | 1,181 | 25.266667 | 78 | py |
nninfo | nninfo-main/nninfo/tasks/checkerboard_task.py | import torch
import numpy as np
from .task import Task
class CheckerboardTask(Task):
task_id = "checkerboard"
@property
def finite(self):
return False
@property
def x_limits(self):
return (0, 1)
@property
def y_limits(self):
return "binary"
@property
def... | 651 | 18.757576 | 59 | py |
nninfo | nninfo-main/nninfo/tasks/task.py | import numpy as np
import torch.utils.data
import torchvision
from abc import ABC, abstractmethod
import nninfo
log = nninfo.logger.get_logger(__name__)
class Task(ABC):
def __init__(self, **kwargs):
self._kwargs = kwargs
_subclasses = {}
@classmethod
def __init_subclass__(cls, **kwargs):
... | 2,272 | 23.44086 | 75 | py |
nninfo | nninfo-main/nninfo/tasks/combined_mnist_octal_task.py | import torch
import torchvision.datasets
from .task import Task, octal_encode_label
class CombinedMnistOctalTask(Task):
task_id = "combined_mnist_octal_dat"
@property
def finite(self):
return True
@property
def x_limits(self):
return (0, 1)
@property
def y_limits(self):
... | 1,263 | 25.893617 | 78 | py |
nninfo | nninfo-main/nninfo/tasks/mnist_eight_binary_task.py | import torch
import torchvision.datasets
from .task import Task
class MnistEightBinaryTask(Task):
"""Mnist task but only with digits from 0-7
len train: 48200
len test: 48275
"""
task_id = "mnist8_binary_dat"
@property
def finite(self):
return True
@property
def x_limi... | 1,486 | 23.783333 | 67 | py |
nninfo | nninfo-main/nninfo/tasks/xor_task.py | import torch
import numpy as np
from .task import Task
class XorTask(Task):
task_id = "xor_dat"
@property
def finite(self):
return False
@property
def x_limits(self):
return (0, 1)
@property
def y_limits(self):
return "binary"
@property
def x_dim(self):
... | 583 | 17.25 | 54 | py |
nninfo | nninfo-main/nninfo/tasks/parity_task.py | import torch
import numpy as np
from .task import Task
class ParityTask(Task):
task_id = "parity"
@property
def finite(self):
return False
@property
def x_limits(self):
return (0, 1) if self._kwargs["continuous"] else "binary"
@property
def y_limits(self):
return... | 860 | 21.076923 | 87 | py |
nninfo | nninfo-main/nninfo/tasks/tishby_task.py | import torch
from ..file_io import FileManager
from .task import Task
class TishbyTask(Task):
task_id = "tishby_dat"
@property
def finite(self):
return True
@property
def x_limits(self):
return "binary"
@property
def y_limits(self):
return "binary"
@property... | 771 | 20.444444 | 85 | py |
nninfo | nninfo-main/nninfo/tasks/emnist_task.py | import torch
import torchvision.datasets
from .task import Task
class EMnist1DTask(Task):
task_id = "emnist_1d_dat"
@property
def finite(self):
return True
@property
def x_limits(self):
return (0, 1)
@property
def y_limits(self):
return "binary"
@property
... | 930 | 22.871795 | 75 | py |
nninfo | nninfo-main/nninfo/tasks/mnist_shuffled.py | import torch
import torchvision
import numpy as np
from .task import Task
class Mnist1DShuffledTask(Task):
task_id = "mnist_1d_shuffled_dat"
@property
def finite(self):
return True
@property
def x_limits(self):
return (0, 1)
@property
def y_limits(self):
retu... | 1,259 | 27.636364 | 105 | py |
nninfo | nninfo-main/nninfo/tasks/mnist1d_task.py | import torch
import torchvision.datasets
from .task import Task
class Mnist1DTask(Task):
task_id = "mnist_1d_dat"
@property
def finite(self):
return True
@property
def x_limits(self):
return (0, 1)
@property
def y_limits(self):
return "binary"
@property
... | 1,037 | 23.714286 | 67 | py |
nninfo | nninfo-main/nninfo/tasks/fashion_mnist_task.py | import torch
import torchvision.datasets
from .task import Task
class FashionMnistTask(Task):
task_id = "fashion_mnist_1d_dat"
@property
def finite(self):
return True
@property
def x_limits(self):
return (0, 1)
@property
def y_limits(self):
return "binary"
@... | 856 | 21.552632 | 76 | py |
nninfo | nninfo-main/nninfo/tasks/xor_misinfo_task.py | import torch
import numpy as np
from .task import Task
class XorTaskMissInfo(Task):
task_id = "XorTaskMissInfo_dat"
@property
def finite(self):
return False
@property
def x_limits(self):
return (0, 1)
@property
def y_limits(self):
return "binary"
@property
... | 603 | 17.875 | 54 | py |
Pro-GNN | Pro-GNN-master/save_splits.py | import time
import argparse
import numpy as np
import torch
from deeprobust.graph.defense import GCN, ProGNN
from deeprobust.graph.data import Dataset, PrePtbDataset
from deeprobust.graph.utils import preprocess, encode_onehot, get_train_val_test
# Training settings
parser = argparse.ArgumentParser()
parser.add_argume... | 3,762 | 48.513158 | 151 | py |
Pro-GNN | Pro-GNN-master/train.py | import time
import argparse
import numpy as np
import torch
from deeprobust.graph.defense import GCN, ProGNN
from deeprobust.graph.data import Dataset, PrePtbDataset
from deeprobust.graph.utils import preprocess, encode_onehot, get_train_val_test
# Training settings
parser = argparse.ArgumentParser()
parser.add_argume... | 4,854 | 46.135922 | 131 | py |
Pro-GNN | Pro-GNN-master/generate_attack.py | import torch
import numpy as np
import torch.nn.functional as F
import torch.optim as optim
from deeprobust.graph.defense import GCN
from deeprobust.graph.global_attack import MetaApprox, Metattack
from deeprobust.graph.utils import *
from deeprobust.graph.data import Dataset
import argparse
parser = argparse.Argument... | 4,117 | 38.596154 | 168 | py |
pyvinecopulib | pyvinecopulib-master/docs/conf.py | # -*- coding: utf-8 -*-
#
# pyvinecopulib documentation build configuration file
# Sphinx extension modules
from pkg_resources import get_distribution
# -- General configuration ------------------------------------------------
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.githubpages',
'sphinx.ext.mat... | 1,252 | 20.982456 | 78 | py |
keras-attention | keras-attention-master/run.py | """
Runs a simple Neural Machine Translation model
Type `python run.py -h` for help with arguments.
"""
import os
import argparse
from keras.callbacks import ModelCheckpoint
from models.NMT import simpleNMT
from data.reader import Data, Vocabulary
from utils.metrics import all_acc
from utils.examples import r... | 3,968 | 35.081818 | 82 | py |
keras-attention | keras-attention-master/models/tdd.py | """
Original code from the keras backend that
implements the _time_distributed_dense layer.
"""
import keras.backend as K
def _time_distributed_dense(x, w, b=None, dropout=None,
input_dim=None, output_dim=None,
timesteps=None, training=None):
"""Apply `y . w... | 1,824 | 35.5 | 79 | py |
keras-attention | keras-attention-master/models/custom_recurrents.py | import tensorflow as tf
from keras import backend as K
from keras import regularizers, constraints, initializers, activations
from keras.layers.recurrent import Recurrent
from keras.engine import InputSpec
from .tdd import _time_distributed_dense
tfPrint = lambda d, T: tf.Print(input_=T, data=[T, tf.shape(T)], message... | 14,525 | 44.823344 | 85 | py |
keras-attention | keras-attention-master/models/NMT.py | import numpy as np
import os
from keras.models import Model
from keras.layers import Dense, Embedding, Activation, Permute
from keras.layers import Input, Flatten, Dropout
from keras.layers.recurrent import LSTM
from keras.layers.wrappers import TimeDistributed, Bidirectional
from .custom_recurrents import AttentionDec... | 2,167 | 37.035088 | 85 | py |
keras-attention | keras-attention-master/utils/metrics.py | import keras.backend as K
def all_acc(y_true, y_pred):
"""
All Accuracy
https://github.com/rasmusbergpalm/normalization/blob/master/train.py#L10
"""
return K.mean(
K.all(
K.equal(
K.max(y_true, axis=-1),
K.cast(K.argmax(y_pred, axis=-1), K... | 372 | 22.3125 | 80 | py |
keras-attention | keras-attention-master/data/reader.py | import json
import csv
import random
import numpy as np
from keras.utils.np_utils import to_categorical
random.seed(1984)
INPUT_PADDING = 50
OUTPUT_PADDING = 100
class Vocabulary(object):
def __init__(self, vocabulary_file, padding=None):
"""
Creates a vocabulary from a file
:p... | 4,822 | 29.719745 | 84 | py |
data-compression | data-compression-main/graph/venv/Lib/site-packages/pip/_vendor/rich/console.py | import inspect
import io
import os
import platform
import sys
import threading
from abc import ABC, abstractmethod
from dataclasses import dataclass, field
from datetime import datetime
from functools import wraps
from getpass import getpass
from html import escape
from inspect import isclass
from itertools import isli... | 94,755 | 36.423381 | 197 | py |
data-compression | data-compression-main/graph/venv/Lib/site-packages/numpy/ma/tests/test_core.py | # pylint: disable-msg=W0400,W0511,W0611,W0612,W0614,R0201,E1102
"""Tests suite for MaskedArray & subclassing.
:author: Pierre Gerard-Marchant
:contact: pierregm_at_uga_dot_edu
"""
__author__ = "Pierre GF Gerard-Marchant"
import sys
import warnings
import operator
import itertools
import textwrap
import pytest
from f... | 202,009 | 36.653308 | 102 | py |
adversarial-training-pytorch | adversarial-training-pytorch-master/model.py | import math
import torch
import torch.nn as nn
import torch.nn.functional as F
class BasicBlock(nn.Module):
def __init__(self, in_planes, out_planes, stride, dropRate=0.0):
super(BasicBlock, self).__init__()
self.bn1 = nn.BatchNorm2d(in_planes)
self.relu1 = nn.ReLU(inplace=True)
se... | 3,857 | 41.866667 | 116 | py |
adversarial-training-pytorch | adversarial-training-pytorch-master/config.py | import numpy as np
import math
import torch
from torchvision import transforms
mean=np.array([0.4914, 0.4822, 0.4465])
std=np.array([0.2023, 0.1994, 0.2010])
max_val = np.array([ (1. - mean[0]) / std[0],
(1. - mean[1]) / std[1],
(1. - mean[2]) / std[2],
])... | 2,915 | 22.707317 | 85 | py |
adversarial-training-pytorch | adversarial-training-pytorch-master/attack_tester.py | import numpy as np
import torch
from torch.autograd import Variable
# from torchvision import transforms
import sys, os
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import config as cf
class AttacksTester:
def __init__(self, model, raw_data_loader, N, eps, parent_folder=None, fo... | 6,669 | 30.462264 | 88 | py |
adversarial-training-pytorch | adversarial-training-pytorch-master/train.py | import numpy as np
import torch
import torchvision
from torch import optim
# from torchvision.datasets import CIFAR10
# from torchvision.models import wide_resnet50_2
import argparse
import time
import math
import shutil
import sys, os
# from attack_tester import AttacksTester
from attacks import Attacks
from model... | 16,077 | 41.760638 | 154 | py |
adversarial-training-pytorch | adversarial-training-pytorch-master/attacks.py | import numpy as np
import torch
# from torchvision import transforms
import sys, os
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import config as cf
class Attacks:
def __init__(self, model, eps, N_train, N_test, momentum=None, is_normalized=False, retain=False):
self.adv_... | 6,600 | 37.377907 | 129 | py |
pyskl | pyskl-main/tools/test.py | # Copyright (c) OpenMMLab. All rights reserved.
# flake8: noqa: E722
import argparse
import mmcv
import os
import os.path as osp
import time
import torch
import torch.distributed as dist
from mmcv import Config
from mmcv import digit_version as dv
from mmcv import load
from mmcv.cnn import fuse_conv_bn
from mmcv.engine... | 6,370 | 33.437838 | 104 | py |
pyskl | pyskl-main/tools/train.py | # Copyright (c) OpenMMLab. All rights reserved.
# flake8: noqa: E722
import argparse
import mmcv
import os
import os.path as osp
import time
import torch
import torch.distributed as dist
from mmcv import Config
from mmcv import digit_version as dv
from mmcv.runner import get_dist_info, init_dist, set_random_seed
from m... | 5,773 | 33.993939 | 111 | py |
pyskl | pyskl-main/tools/data/custom_2d_skeleton.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import copy as cp
import decord
import mmcv
import numpy as np
import os
import os.path as osp
import torch.distributed as dist
from mmcv.runner import get_dist_info, init_dist
from tqdm import tqdm
import pyskl # noqa: F401
from pyskl.smp import mrlines... | 7,881 | 39.628866 | 113 | py |
pyskl | pyskl-main/demo/demo_gesture.py | import cv2
import mediapipe as mp
import numpy as np
import torch
from pyskl.apis import init_recognizer
from pyskl.datasets import GestureDataset
from pyskl.datasets.pipelines import Compose
from pyskl.smp import h2r
mp_drawing = mp.solutions.drawing_utils
mp_drawing_styles = mp.solutions.drawing_styles
mp_hands = m... | 5,878 | 32.787356 | 120 | py |
pyskl | pyskl-main/demo/faster_rcnn_r50_fpn_1x_coco-person.py | # model config
model = dict(
type='FasterRCNN',
pretrained='torchvision://resnet50',
backbone=dict(
type='ResNet',
depth=50,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
norm_cfg=dict(type='BN', requires_grad=False),
norm_eval=True,
... | 5,007 | 29.536585 | 77 | py |
pyskl | pyskl-main/demo/demo_skeleton.py | # Copyright (c) OpenMMLab. All rights reserved.
import argparse
import cv2
import mmcv
import numpy as np
import os
import os.path as osp
import shutil
import torch
import warnings
from scipy.optimize import linear_sum_assignment
from pyskl.apis import inference_recognizer, init_recognizer
try:
from mmdet.apis im... | 11,089 | 34.774194 | 118 | py |
pyskl | pyskl-main/pyskl/smp.py | # flake8: noqa: F401, F403
import abc
import argparse
import collections
import cv2
import json
import multiprocessing as mp
import numpy as np
import os
import os.path as osp
import pickle
import random as rd
import requests
import shutil
import string
import subprocess
import sys
import time
import warnings
from coll... | 5,556 | 29.36612 | 107 | py |
pyskl | pyskl-main/pyskl/apis/inference.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import numpy as np
import os
import os.path as osp
import re
import torch
import warnings
from mmcv.parallel import collate, scatter
from mmcv.runner import load_checkpoint
from operator import itemgetter
from pyskl.core import OutputHook
from pyskl.datasets.... | 7,053 | 37.336957 | 79 | py |
pyskl | pyskl-main/pyskl/apis/train.py | # Copyright (c) OpenMMLab. All rights reserved.
import numpy as np
import os
import os.path as osp
import time
import torch
import torch.distributed as dist
from mmcv.engine import multi_gpu_test
from mmcv.parallel import MMDistributedDataParallel
from mmcv.runner import DistSamplerSeedHook, EpochBasedRunner, Optimizer... | 8,026 | 36.685446 | 108 | py |
pyskl | pyskl-main/pyskl/core/hooks.py | # Copyright (c) OpenMMLab. All rights reserved.
import functools
import torch
import warnings
class OutputHook:
"""Output feature map of some layers.
Args:
module (nn.Module): The whole module to get layers.
outputs (tuple[str] | list[str]): Layer name to output. Default: None.
as_ten... | 2,087 | 29.705882 | 84 | py |
pyskl | pyskl-main/pyskl/models/cnns/c3d.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch.nn as nn
from mmcv.cnn import ConvModule, kaiming_init
from mmcv.runner import load_checkpoint
from ...utils import cache_checkpoint, get_root_logger
from ..builder import BACKBONES
@BACKBONES.register_module()
class C3D(nn.Module):
"""C3D backbone, wi... | 3,631 | 35.32 | 110 | py |
pyskl | pyskl-main/pyskl/models/cnns/resnet.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch.nn as nn
from mmcv.cnn import ConvModule, constant_init, kaiming_init
from mmcv.runner import _load_checkpoint, load_checkpoint
from mmcv.utils import _BatchNorm
from ...utils import cache_checkpoint, get_root_logger
from ..builder import BACKBONES
class B... | 17,151 | 34.807933 | 118 | py |
pyskl | pyskl-main/pyskl/models/cnns/resnet3d.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch.nn as nn
import warnings
from mmcv.cnn import ConvModule, build_activation_layer, constant_init, kaiming_init
from mmcv.runner import _load_checkpoint, load_checkpoint
from mmcv.utils import _BatchNorm
from torch.nn.modules.utils import _ntuple, _triple
from... | 25,350 | 39.367834 | 119 | py |
pyskl | pyskl-main/pyskl/models/cnns/resnet3d_slowfast.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
import torch.nn as nn
import warnings
from mmcv.cnn import ConvModule, kaiming_init
from mmcv.runner import _load_checkpoint, load_checkpoint
from mmcv.utils import print_log
from ...utils import cache_checkpoint, get_root_logger
from ..builder import BACKBO... | 17,261 | 42.047382 | 118 | py |
pyskl | pyskl-main/pyskl/models/cnns/potion.py | from mmcv.cnn import ConvModule, constant_init, kaiming_init
from torch import nn
from ..builder import BACKBONES
@BACKBONES.register_module()
class PoTion(nn.Module):
def __init__(self,
in_channels,
channels=[128, 256, 512],
num_layers=[2, 2, 2],
... | 2,528 | 30.222222 | 74 | py |
pyskl | pyskl-main/pyskl/models/cnns/rgbposeconv3d.py | import torch
import torch.nn as nn
from mmcv.cnn import constant_init, kaiming_init
from mmcv.runner import load_checkpoint
from mmcv.utils import _BatchNorm, print_log
from ...utils import get_root_logger
from ..builder import BACKBONES
from .resnet3d_slowfast import ResNet3dPathway
@BACKBONES.register_module()
cla... | 6,748 | 36.494444 | 79 | py |
pyskl | pyskl-main/pyskl/models/cnns/x3d.py | # Copyright (c) OpenMMLab. All rights reserved.
import math
import torch.nn as nn
from mmcv.cnn import ConvModule, Swish, build_activation_layer, constant_init, kaiming_init
from mmcv.runner import load_checkpoint
from mmcv.utils import _BatchNorm
from ...utils import cache_checkpoint, get_root_logger
from ..builder i... | 18,289 | 35.361829 | 91 | py |
pyskl | pyskl-main/pyskl/models/recognizers/base.py | # Copyright (c) OpenMMLab. All rights reserved.
import functools
import torch
import torch.distributed as dist
import torch.nn as nn
import torch.nn.functional as F
from abc import ABCMeta, abstractmethod
from collections import OrderedDict
from .. import builder
def rgetattr(obj, attr, *args):
def _getattr(obj,... | 7,044 | 34.943878 | 116 | py |
pyskl | pyskl-main/pyskl/models/recognizers/recognizer3d.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
from torch import nn
from ..builder import RECOGNIZERS
from .base import BaseRecognizer
@RECOGNIZERS.register_module()
class Recognizer3D(BaseRecognizer):
"""3D recognizer model framework."""
def forward_train(self, imgs, label, **kwargs):
... | 3,244 | 36.732558 | 91 | py |
pyskl | pyskl-main/pyskl/models/recognizers/recognizer2d.py | # Copyright (c) OpenMMLab. All rights reserved.
from torch import nn
from ..builder import RECOGNIZERS
from .base import BaseRecognizer
@RECOGNIZERS.register_module()
class Recognizer2D(BaseRecognizer):
"""2D recognizer model framework."""
def forward_train(self, imgs, label, **kwargs):
"""Defines t... | 2,006 | 33.016949 | 90 | py |
pyskl | pyskl-main/pyskl/models/recognizers/recognizergcn.py | import numpy as np
import torch
from ..builder import RECOGNIZERS
from .base import BaseRecognizer
@RECOGNIZERS.register_module()
class RecognizerGCN(BaseRecognizer):
"""GCN-based recognizer for skeleton-based action recognition. """
def forward_train(self, keypoint, label, **kwargs):
"""Defines the... | 3,405 | 34.113402 | 78 | py |
pyskl | pyskl-main/pyskl/models/gcns/sgn.py | import math
import torch
from mmcv.cnn import ConvModule
from torch import nn
from .utils import unit_sgn
class SGN(nn.Module):
def __init__(self,
in_channels=3,
base_channels=64,
num_joints=25,
T=30,
bias=True):
super(... | 4,097 | 39.176471 | 114 | py |
pyskl | pyskl-main/pyskl/models/gcns/aagcn.py | import copy as cp
import torch
import torch.nn as nn
from mmcv.runner import load_checkpoint
from ...utils import Graph, cache_checkpoint
from ..builder import BACKBONES
from .utils import bn_init, mstcn, unit_aagcn, unit_tcn
class AAGCNBlock(nn.Module):
def __init__(self, in_channels, out_channels, A, stride=1,... | 4,741 | 35.198473 | 113 | py |
pyskl | pyskl-main/pyskl/models/gcns/msg3d.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from ...utils.graph import Graph
from ..builder import BACKBONES
from .utils import MSGCN, MSTCN, MW_MSG3DBlock
@BACKBONES.register_module()
class MSG3D(nn.Module):
def __init__(self,
graph_cfg,
in_channels=3,
... | 2,665 | 32.746835 | 83 | py |
pyskl | pyskl-main/pyskl/models/gcns/dgstgcn.py | import copy as cp
import torch
import torch.nn as nn
from mmcv.runner import load_checkpoint
from ...utils import Graph, cache_checkpoint
from ..builder import BACKBONES
from .utils import dggcn, dgmstcn, unit_tcn
EPS = 1e-4
class DGBlock(nn.Module):
def __init__(self, in_channels, out_channels, A, stride=1, r... | 4,689 | 34 | 105 | py |
pyskl | pyskl-main/pyskl/models/gcns/stgcn.py | import copy as cp
import torch
import torch.nn as nn
from mmcv.runner import load_checkpoint
from ...utils import Graph, cache_checkpoint
from ..builder import BACKBONES
from .utils import mstcn, unit_gcn, unit_tcn
EPS = 1e-4
class STGCNBlock(nn.Module):
def __init__(self,
in_channels,
... | 4,823 | 33.956522 | 108 | py |
pyskl | pyskl-main/pyskl/models/gcns/ctrgcn.py | import torch
import torch.nn as nn
from ...utils import Graph
from ..builder import BACKBONES
from .utils import MSTCN, unit_ctrgcn, unit_tcn
class CTRGCNBlock(nn.Module):
def __init__(self,
in_channels,
out_channels,
A,
stride=1,
... | 3,059 | 31.553191 | 104 | py |
pyskl | pyskl-main/pyskl/models/gcns/utils/msg3d_utils.py | import numpy as np
import torch
import torch.nn as nn
from mmcv.cnn import build_activation_layer
from mmcv.utils import _BatchNorm
from ....utils.graph import k_adjacency, normalize_digraph
from .init_func import bn_init, conv_init
from .tcn import unit_tcn
class MLP(nn.Module):
def __init__(self, in_channels, ... | 10,608 | 32.361635 | 110 | py |
pyskl | pyskl-main/pyskl/models/gcns/utils/gcn.py | import torch
import torch.nn as nn
from mmcv.cnn import build_activation_layer, build_norm_layer
from .init_func import bn_init, conv_branch_init, conv_init
EPS = 1e-4
class unit_gcn(nn.Module):
def __init__(self,
in_channels,
out_channels,
A,
... | 15,907 | 35.072562 | 102 | py |
pyskl | pyskl-main/pyskl/models/gcns/utils/init_func.py | import math
import torch.nn as nn
def conv_branch_init(conv, branches):
weight = conv.weight
n = weight.size(0)
k1 = weight.size(1)
k2 = weight.size(2)
nn.init.normal_(weight, 0, math.sqrt(2. / (n * k1 * k2 * branches)))
nn.init.constant_(conv.bias, 0)
def conv_init(conv):
nn.init.kaimin... | 495 | 21.545455 | 72 | py |
pyskl | pyskl-main/pyskl/models/gcns/utils/tcn.py | import torch
import torch.nn as nn
from mmcv.cnn import build_norm_layer
from .init_func import bn_init, conv_init
class unit_tcn(nn.Module):
def __init__(self, in_channels, out_channels, kernel_size=9, stride=1, dilation=1, norm='BN', dropout=0):
super().__init__()
self.in_channels = in_chann... | 7,254 | 34.915842 | 109 | py |
pyskl | pyskl-main/pyskl/models/losses/base.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch.nn as nn
from abc import ABCMeta, abstractmethod
class BaseWeightedLoss(nn.Module, metaclass=ABCMeta):
"""Base class for loss.
All subclass should overwrite the ``_forward()`` method which returns the
normal loss without loss weights.
Args... | 1,228 | 26.311111 | 77 | py |
pyskl | pyskl-main/pyskl/models/losses/cross_entropy_loss.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
import torch.nn.functional as F
from ..builder import LOSSES
from .base import BaseWeightedLoss
@LOSSES.register_module()
class CrossEntropyLoss(BaseWeightedLoss):
"""Cross Entropy Loss.
Support two kinds of labels and their corresponding loss typ... | 4,877 | 38.983607 | 132 | py |
pyskl | pyskl-main/pyskl/models/heads/base.py | # Copyright (c) OpenMMLab. All rights reserved.
import torch
import torch.nn as nn
from abc import ABCMeta, abstractmethod
from ...core import top_k_accuracy
from ..builder import build_loss
class BaseHead(nn.Module, metaclass=ABCMeta):
"""Base class for head.
All Head should subclass it.
All subclass s... | 3,251 | 35.954545 | 100 | py |
pyskl | pyskl-main/pyskl/models/heads/simple_head.py | import torch
import torch.nn as nn
from mmcv.cnn import normal_init
from ..builder import HEADS
from .base import BaseHead
@HEADS.register_module()
class SimpleHead(BaseHead):
""" A simple classification head.
Args:
num_classes (int): Number of classes to be classified.
in_channels (int): Nu... | 4,742 | 29.210191 | 89 | py |
pyskl | pyskl-main/pyskl/models/heads/rgbpose_head.py | import torch.nn as nn
from mmcv.cnn import normal_init
from ..builder import HEADS
from .base import BaseHead
@HEADS.register_module()
class RGBPoseHead(BaseHead):
"""The classification head for Slowfast.
Args:
num_classes (int): Number of classes to be classified.
in_channels (tuple[int]): ... | 2,696 | 32.7125 | 90 | py |
pyskl | pyskl-main/pyskl/datasets/base.py | # Copyright (c) OpenMMLab. All rights reserved.
# flake8: noqa: E722
import copy
import mmcv
import numpy as np
import os.path as osp
import torch
import warnings
from abc import ABCMeta, abstractmethod
from collections import OrderedDict, defaultdict
from mmcv.utils import print_log
from torch.utils.data import Datase... | 13,434 | 40.594427 | 119 | py |
pyskl | pyskl-main/pyskl/datasets/builder.py | # Copyright (c) OpenMMLab. All rights reserved.
import numpy as np
import platform
import random
import torch
from functools import partial
from mmcv.parallel import collate
from mmcv.runner import get_dist_info
from mmcv.utils import Registry, build_from_cfg, digit_version
from torch.utils.data import DataLoader
from... | 4,169 | 32.629032 | 79 | py |
pyskl | pyskl-main/pyskl/datasets/samplers/distributed_sampler.py | # Copyright (c) OpenMMLab. All rights reserved.
import math
import torch
from collections import defaultdict
from torch.utils.data import DistributedSampler as _DistributedSampler
class DistributedSampler(_DistributedSampler):
"""DistributedSampler inheriting from
``torch.utils.data.DistributedSampler``.
... | 4,212 | 36.616071 | 119 | py |
pyskl | pyskl-main/pyskl/datasets/pipelines/formatting.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import numpy as np
import torch
from collections.abc import Sequence
from mmcv.parallel import DataContainer as DC
from ..builder import PIPELINES
def to_tensor(data):
"""Convert objects of various python types to :obj:`torch.Tensor`.
Supported typ... | 9,225 | 35.904 | 79 | py |
pyskl | pyskl-main/pyskl/datasets/pipelines/multi_modality.py | import numpy as np
from torch.nn.modules.utils import _pair
from ..builder import PIPELINES
from .loading import DecordDecode, DecordInit
from .pose_related import PoseDecode
from .sampling import UniformSampleFrames
EPS = 1e-4
@PIPELINES.register_module()
class MMPad:
def __init__(self, hw_ratio=None, padding... | 8,401 | 35.530435 | 104 | py |
pyskl | pyskl-main/pyskl/datasets/pipelines/augmentations.py | # Copyright (c) OpenMMLab. All rights reserved.
import mmcv
import numpy as np
import random
import warnings
from collections.abc import Sequence
from torch.nn.modules.utils import _pair
from ..builder import PIPELINES
def _combine_quadruple(a, b):
return (a[0] + a[2] * b[0], a[1] + a[3] * b[1], a[2] * b[2], a[3... | 33,786 | 36.457871 | 92 | py |
pyskl | pyskl-main/pyskl/utils/misc.py | # Copyright (c) OpenMMLab. All rights reserved.
# flake8: noqa: E722
import hashlib
import logging
import multiprocessing as mp
import numpy as np
import os
import os.path as osp
import socket
import warnings
from mmcv import load
from mmcv.runner import get_dist_info
from mmcv.utils import get_logger
from ..smp impor... | 4,385 | 32.480916 | 98 | py |
pyskl | pyskl-main/pyskl/utils/graph.py | import numpy as np
import torch
def k_adjacency(A, k, with_self=False, self_factor=1):
# A is a 2D square array
if isinstance(A, torch.Tensor):
A = A.data.cpu().numpy()
assert isinstance(A, np.ndarray)
Iden = np.eye(len(A), dtype=A.dtype)
if k == 0:
return Iden
Ak = np.minimum(... | 5,855 | 32.462857 | 116 | py |
radical.entk | radical.entk-master/docs/source/conf.py | # Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Path setup --------------------------------------------------------------
# If ex... | 3,136 | 33.472527 | 79 | py |
SRNFmatch_code | SRNFmatch_code-master/src/matching.py | # Load Packages
from energy import *
import numpy as np
import scipy
from scipy.optimize import minimize,fmin_l_bfgs_b
from torch.autograd import grad
#import pymesh
import input_output
use_cuda = 1
torchdeviceId = torch.device('cuda:0') if use_cuda else 'cpu'
torchdtype = torch.float32
def StandardMatching(source,ta... | 17,428 | 40.106132 | 328 | py |
SRNFmatch_code | SRNFmatch_code-master/src/energy.py | import torch
from pykeops.torch import Kernel, kernel_product, Genred
from pykeops.torch.kernel_product.formula import *
def Comp_normal(F, V):
V0, V1, V2 = V.index_select(0, F[:, 0]), V.index_select(0, F[:, 1]), V.index_select(0, F[:, 2])
N = .5 * torch.cross(V1 - V0, V2 - V0)
return N
def enr_match... | 7,134 | 37.989071 | 161 | py |
qtbase-dev | qtbase-dev/util/cmake/helper.py | # Copyright (C) 2021 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
import re
import typing
class LibraryMapping:
def __init__(
self,
soName: str,
packageName: typing.Optional[str],
targetName: typing.Optional[str]... | 35,472 | 39.773563 | 100 | py |
qtbase-dev | qtbase-dev/util/cmake/tests/test_parsing.py | #!/usr/bin/env python3
# Copyright (C) 2018 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
import os
from pro2cmake import map_condition
from qmake_parser import QmakeParser
from condition_simplifier import simplify_condition
_tests_path = os.path.di... | 10,345 | 29.075581 | 107 | py |
qtbase-dev | qtbase-dev/util/cmake/tests/test_scope_handling.py | #!/usr/bin/env python3
# Copyright (C) 2021 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
from pro2cmake import Scope, SetOperation, merge_scopes, recursive_evaluate_scope
import pytest
import typing
ScopeList = typing.List[Scope]
def _map_to_opera... | 10,845 | 33 | 117 | py |
binet | binet-master/evaluate.py | # imports
import os
import torch
import numpy as np
import img_tools as im_t
import matplotlib.pyplot as plt
import networks.functional as f
from sklearn.metrics import auc
from image_codec import ImageCodec
from torchvision.utils import make_grid
from img_tools import EvaluationImageDataLoaders, InvNormalization
# -... | 18,346 | 28.591935 | 121 | py |
binet | binet-master/train.py | """
Python Training Script
used to train Image Compression Models
cmd:
python train -sys [SYSTEM] -e [EPOCHS] -lr [LEARN_RATE] -g [GAMMA] -l [LOG_DIR] -td [TRAIN_DIR]
-sv [SAVE_LOC] -ps [PATCH_SIZE] -bs [BATCH_SIZE] --itrs [ITERATIONS] -bn [BITS]
... | 8,286 | 21.580381 | 130 | py |
binet | binet-master/functions/binarizer.py | # imports
from torch.autograd import Function
"""
Autograd Function : binz
forward and backward methods for binarization function
Ref (math) : https://arxiv.org/pdf/1511.06085.pdf Stochastic Binarization
Ref (code) : https://github.com/1zb/pytorch-image-comp-rnn/blob/master/functions/sign.py
"""... | 977 | 26.166667 | 92 | py |
binet | binet-master/networks/functional.py | # imports
import math
import torch
import torch.nn as nn
from torch.nn.modules.utils import _pair
# ----------------------------------------------------------------------------------------------------------------------
# Functions used by Inpainting Network Modules
# --------------------------------------------------... | 4,689 | 22.928571 | 120 | py |
binet | binet-master/networks/binet_osr/binet_osr.py | # imports
import torch
import warnings
import torch.nn as nn
import networks.functional as f
import torch.nn.functional as F
from layers import ConvBinarizer
from torch.nn.modules.utils import _pair
from networks.conv_gru import ConvRnnEncoder, ConvRnnDecoder
"""
BINetOSR
Full context binary inpainting assimilat... | 6,493 | 23.50566 | 96 | py |
binet | binet-master/networks/masked_binet/masked_binet.py | # imports
import torch
import warnings
import torch.nn as nn
import networks.functional as f
from layers import ConvBinarizer
from torch.nn.modules.utils import _pair
from networks.conv_ar import ConvEncoder, ConvDecoder
"""
MaskedBINet
Convolutional BINet with masked bit region.
Model is used for the experi... | 2,817 | 20.844961 | 91 | py |
binet | binet-master/networks/conv_gru/conv_rnn_encoder.py | # imports
import torch.nn as nn
from layers import ConvGruCell
"""
Recurrent Convolutional Encoder Network
Args:
p_s (int) : input patch size
"""
class ConvRnnEncoder(nn.Module):
def __init__(self):
super(ConvRnnEncoder, self).__init__()
self.conv = nn.Sequential(
nn.C... | 2,010 | 21.595506 | 57 | py |
binet | binet-master/networks/conv_gru/conv_rnn_deocder.py | # imports
import torch.nn as nn
from layers import ConvGruCell
"""
Recurrent Convolutional Decoder Network
Args:
p_s (int) : patch size
bnd (int) : bottle-neck depth
"""
class ConvRnnDecoder(nn.Module):
def __init__(self, bnd):
super(ConvRnnDecoder, self).__init__()
# bott... | 2,992 | 21.503759 | 57 | py |
binet | binet-master/networks/conv_gru/conv_rnn_auto.py | # imports
import torch
import warnings
import torch.nn as nn
from numbers import Number
import networks.functional as f
from layers import ConvBinarizer
from .conv_rnn_encoder import ConvRnnEncoder
from .conv_rnn_deocder import ConvRnnDecoder
"""
Implementation of Google's Recurrent Convolutional Neural Network Autoe... | 3,091 | 23.736 | 77 | py |
binet | binet-master/networks/conv_ar/conv_decoder.py | # import
import torch.nn as nn
"""
Convolutional Decoder Network
Args:
bnD (int) : bottle-neck layer depth
"""
class ConvDecoder(nn.Module):
def __init__(self, bnd):
super(ConvDecoder, self).__init__()
self.bnd = bnd
self.dec = nn.Sequential(
nn.Conv2d(
... | 1,454 | 21.384615 | 43 | py |
binet | binet-master/networks/conv_ar/conv_ar.py | # imports
import torch
import torch.nn as nn
from numbers import Number
import networks.functional as f
from layers import ConvBinarizer
from networks.conv_ar.conv_encoder import ConvEncoder
from networks.conv_ar.conv_decoder import ConvDecoder
"""
Class Convolutional Autoencoder (Additive Reconstruction):
Metho... | 3,725 | 25.055944 | 69 | py |
binet | binet-master/networks/conv_ar/conv_encoder.py | # imports
import torch.nn as nn
"""
Convolutional Encoder Network
"""
class ConvEncoder(nn.Module):
def __init__(self):
super(ConvEncoder, self).__init__()
self.enc = nn.Sequential(
nn.Conv2d(
in_channels=3,
out_channels=64,
kernel_s... | 1,240 | 18.390625 | 43 | py |
binet | binet-master/networks/binet_ar/binet_ar.py | # imports
import torch
import warnings
import torch.nn as nn
import networks.functional as f
import torch.nn.functional as F
from layers import ConvBinarizer
from torch.nn.modules.utils import _pair
from networks.conv_ar import ConvAR, ConvEncoder, ConvDecoder
"""
BINetAR
Convolutional BINet using Additive Recon... | 5,173 | 21.398268 | 86 | py |
binet | binet-master/networks/seq_inp_net/seq_inp_net.py | # imports
import os
import torch
import warnings
import torch.nn as nn
from torch.nn.modules.utils import _pair
from networks.conv_ar import ConvAR
"""
Sequential Inpainting Network
used to compare binary inpainting to sequential inpainting from decompressed patches
Args:
p_s (int) : patch size
... | 4,322 | 23.016667 | 88 | py |
binet | binet-master/image_codec/image_codec.py | # imports
import os
import numpy as np
from PIL import Image
from io import BytesIO
from skimage import measure
import torchvision.transforms.functional as F
from img_tools import ImageDataset, disp_images_widget, disp_prog_imgs
"""
ImageCodec
Uses:
Calculates Metric vs Bpp values for all images in img_di... | 6,137 | 24.789916 | 86 | py |
binet | binet-master/img_tools/ImgDataLoaders.py | # imports
import os
import torch
import numbers
import img_tools.ImgTools as im_t
import torchvision.transforms as tf
import img_tools.ImgTransforms as ctf
from torch.utils.data import DataLoader
from img_tools.ImgDataset import ImageDataset
# --------------------------------------------------------------------------... | 8,215 | 24.04878 | 120 | py |
binet | binet-master/img_tools/ImgDataset.py | import os
import glob
from PIL import Image
from torch.utils.data import Dataset
"""
Class: ImageDataset
Extends the torch Dataset class. Facilitates the creation of an iterable
dataset from an image folder.
Args:
rootDir (string) : path to directory containing images
t... | 1,444 | 24.350877 | 91 | py |
binet | binet-master/img_tools/ImgTransforms.py | # imports
import random
import numbers
from PIL import ImageOps
import torchvision.transforms as tf
"""
Image2Grids
crops a given PIL Image into grid blocks made up of patches
Args:
size (int) : patch size cropped from image
n_p (int) : number of patches per grid row & col
... | 9,835 | 23.406948 | 119 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.