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 |
|---|---|---|---|---|---|---|
STTS | STTS-main/MViT/slowfast/utils/weight_init_helper.py | #!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
"""Utility function for weight initialization"""
import torch.nn as nn
from fvcore.nn.weight_init import c2_msra_fill
def init_weights(model, fc_init_std=0.01, zero_init_final_bn=True):
"""
Performs ResNet style w... | 1,563 | 33.755556 | 76 | py |
STTS | STTS-main/MViT/slowfast/utils/multiprocessing.py | #!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
"""Multiprocessing helpers."""
import torch
def run(
local_rank,
num_proc,
func,
init_method,
shard_id,
num_shards,
backend,
cfg,
output_queue=None,
):
"""
Runs a function from ... | 2,105 | 32.428571 | 80 | py |
STTS | STTS-main/MViT/slowfast/utils/bn_helper.py | #!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
"""bn helper."""
import itertools
import torch
@torch.no_grad()
def compute_and_update_bn_stats(model, data_loader, num_batches=200):
"""
Compute and update the batch norm stats to make it more precise. During
... | 2,858 | 35.653846 | 80 | py |
STTS | STTS-main/MViT/slowfast/utils/meters.py | #!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
"""Meters."""
import datetime
import numpy as np
import os
from collections import defaultdict, deque
import torch
from fvcore.common.timer import Timer
from sklearn.metrics import average_precision_score
import slowfast.d... | 27,039 | 31.228844 | 80 | py |
STTS | STTS-main/VideoSwin/tools/test.py | import argparse
import os
import os.path as osp
import warnings
import mmcv
import torch
from mmcv import Config, DictAction
from mmcv.cnn import fuse_conv_bn
from mmcv.fileio.io import file_handlers
from mmcv.parallel import MMDataParallel, MMDistributedDataParallel
from mmcv.runner import get_dist_info, init_dist, l... | 13,558 | 35.645946 | 80 | py |
STTS | STTS-main/VideoSwin/tools/train.py | import argparse
import copy
import os
import os.path as osp
import time
import warnings
import mmcv
import torch
from mmcv import Config, DictAction
from mmcv.runner import get_dist_info, init_dist, set_random_seed, load_checkpoint
from mmcv.utils import get_git_hash
from mmaction import __version__
from mmaction.api... | 7,620 | 34.119816 | 86 | py |
STTS | STTS-main/VideoSwin/tools/deployment/publish_model.py | import argparse
import subprocess
import torch
def parse_args():
parser = argparse.ArgumentParser(
description='Process a checkpoint to be published')
parser.add_argument('in_file', help='input checkpoint filename')
parser.add_argument('out_file', help='output checkpoint filename')
args = par... | 1,125 | 27.15 | 77 | py |
STTS | STTS-main/VideoSwin/tools/deployment/pytorch2onnx.py | import argparse
import mmcv
import numpy as np
import torch
from mmcv.runner import load_checkpoint
from mmaction.models import build_model
try:
import onnx
import onnxruntime as rt
except ImportError as e:
raise ImportError(f'Please install onnx and onnxruntime first. {e}')
try:
from mmcv.onnx.symb... | 5,940 | 33.947059 | 78 | py |
STTS | STTS-main/VideoSwin/tools/misc/clip_feature_extraction.py | import argparse
import os
import os.path as osp
import warnings
from datetime import datetime
import mmcv
import numpy as np
import torch
import torch.distributed as dist
from mmcv import Config, DictAction
from mmcv.cnn import fuse_conv_bn
from mmcv.fileio.io import file_handlers
from mmcv.parallel import MMDataParal... | 7,541 | 31.934498 | 78 | py |
STTS | STTS-main/VideoSwin/tools/misc/bsn_proposal_generation.py | import argparse
import os
import os.path as osp
import mmcv
import numpy as np
import torch.multiprocessing as mp
from mmaction.localization import (generate_bsp_feature,
generate_candidate_proposals)
def load_video_infos(ann_file):
"""Load the video annotations.
Args:
... | 6,626 | 32.469697 | 79 | py |
STTS | STTS-main/VideoSwin/tools/analysis/benchmark.py | import argparse
import time
import torch
from mmcv import Config
from mmcv.cnn import fuse_conv_bn
from mmcv.parallel import MMDataParallel
from mmcv.runner.fp16_utils import wrap_fp16_model
from mmaction.datasets import build_dataloader, build_dataset
from mmaction.models import build_model
def parse_args():
p... | 2,638 | 27.376344 | 79 | py |
STTS | STTS-main/VideoSwin/tools/data/build_audio_features.py | import argparse
import glob
import os
import os.path as osp
import sys
from multiprocessing import Pool
import mmcv
import numpy as np
from scipy.io import wavfile
try:
import librosa
import lws
except ImportError:
print('Please import librosa, lws first.')
sys.path.append('..')
SILENCE_THRESHOLD = 2
FM... | 10,532 | 32.438095 | 79 | py |
STTS | STTS-main/VideoSwin/tools/data/activitynet/tsn_feature_extraction.py | import argparse
import os
import os.path as osp
import pickle
import mmcv
import numpy as np
import torch
from mmaction.datasets.pipelines import Compose
from mmaction.models import build_model
def parse_args():
parser = argparse.ArgumentParser(description='Extract TSN Feature')
parser.add_argument('--data-... | 5,206 | 33.946309 | 78 | py |
STTS | STTS-main/VideoSwin/mmcv_custom/runner/checkpoint.py | # Copyright (c) Open-MMLab. All rights reserved.
import apex
import os.path as osp
import time
from tempfile import TemporaryDirectory
import torch
from torch.optim import Optimizer
import mmcv
from mmcv.parallel import is_module_wrapper
from mmcv.runner.checkpoint import weights_to_cpu, get_state_dict
def save_chec... | 2,843 | 34.111111 | 77 | py |
STTS | STTS-main/VideoSwin/mmcv_custom/runner/epoch_based_runner.py | # Copyright (c) Open-MMLab. All rights reserved.
import os.path as osp
import platform
import shutil
import time
import warnings
import torch
import mmcv
from .checkpoint import save_checkpoint
import apex
from torch.optim import Optimizer
import os
class EpochBasedRunnerAmp(mmcv.runner.EpochBasedRunner):
def _... | 9,764 | 38.216867 | 91 | py |
STTS | STTS-main/VideoSwin/mmaction/apis/inference.py | import os
import os.path as osp
import re
from operator import itemgetter
import mmcv
import torch
from mmcv.parallel import collate, scatter
from mmcv.runner import load_checkpoint
from mmaction.core import OutputHook
from mmaction.datasets.pipelines import Compose
from mmaction.models import build_recognizer
def ... | 5,977 | 37.076433 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/apis/test.py | import os.path as osp
import pickle
import shutil
import tempfile
# TODO import test functions from mmcv and delete them from mmaction2
import warnings
import mmcv
import torch
import torch.distributed as dist
from mmcv.runner import get_dist_info
try:
from mmcv.engine import (single_gpu_test, multi_gpu_test,
... | 7,577 | 35.965854 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/apis/train.py | import copy as cp
import os.path as osp
import torch
from mmcv.parallel import MMDataParallel, MMDistributedDataParallel
from mmcv.runner import (DistSamplerSeedHook, EpochBasedRunner, OptimizerHook,
build_optimizer, get_dist_info)
from mmcv.runner.hooks import Fp16OptimizerHook
from ..core i... | 10,658 | 39.222642 | 107 | py |
STTS | STTS-main/VideoSwin/mmaction/core/evaluation/eval_hooks.py | import os
import os.path as osp
import warnings
from math import inf
import torch.distributed as dist
from torch.nn.modules.batchnorm import _BatchNorm
from torch.utils.data import DataLoader
try:
from mmcv.runner import EvalHook as BasicEvalHook
from mmcv.runner import DistEvalHook as BasicDistEvalHook
... | 16,695 | 41.700767 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/core/bbox/bbox_target.py | import torch
import torch.nn.functional as F
def bbox_target(pos_bboxes_list, neg_bboxes_list, gt_labels, cfg):
"""Generate classification targets for bboxes.
Args:
pos_bboxes_list (list[Tensor]): Positive bboxes list.
neg_bboxes_list (list[Tensor]): Negative bboxes list.
gt_labels (l... | 1,334 | 30.785714 | 73 | py |
STTS | STTS-main/VideoSwin/mmaction/core/bbox/assigners/max_iou_assigner_ava.py | import torch
from mmaction.utils import import_module_error_class
try:
from mmdet.core.bbox import AssignResult, MaxIoUAssigner
from mmdet.core.bbox.builder import BBOX_ASSIGNERS
mmdet_imported = True
except (ImportError, ModuleNotFoundError):
mmdet_imported = False
if mmdet_imported:
@BBOX_ASSI... | 6,032 | 42.402878 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/core/runner/omnisource_runner.py | # Copyright (c) Open-MMLab. All rights reserved.
import time
import warnings
import mmcv
from mmcv.runner import EpochBasedRunner, Hook
from mmcv.runner.utils import get_host_info
def cycle(iterable):
iterator = iter(iterable)
while True:
try:
yield next(iterator)
except StopItera... | 6,589 | 39.429448 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/core/hooks/output.py | import functools
import warnings
import torch
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_tensor (bool): Determine to return a tensor or a n... | 2,040 | 29.014706 | 84 | py |
STTS | STTS-main/VideoSwin/mmaction/core/optimizer/topk_optimizer_constructor.py | import torch
from mmcv.runner import OPTIMIZER_BUILDERS, DefaultOptimizerConstructor
from mmcv.utils import SyncBatchNorm, _BatchNorm, _ConvNd
@OPTIMIZER_BUILDERS.register_module()
class TopkOptimizerConstructor(DefaultOptimizerConstructor):
"""Optimizer constructor in TSM model.
This constructor builds opti... | 2,226 | 32.238806 | 77 | py |
STTS | STTS-main/VideoSwin/mmaction/core/optimizer/tsm_optimizer_constructor.py | import torch
from mmcv.runner import OPTIMIZER_BUILDERS, DefaultOptimizerConstructor
from mmcv.utils import SyncBatchNorm, _BatchNorm, _ConvNd
@OPTIMIZER_BUILDERS.register_module()
class TSMOptimizerConstructor(DefaultOptimizerConstructor):
"""Optimizer constructor in TSM model.
This constructor builds optim... | 4,074 | 36.045455 | 77 | py |
STTS | STTS-main/VideoSwin/mmaction/core/optimizer/copy_of_sgd.py | from mmcv.runner import OPTIMIZERS
from torch.optim import SGD
@OPTIMIZERS.register_module()
class CopyOfSGD(SGD):
"""A clone of torch.optim.SGD.
A customized optimizer could be defined like CopyOfSGD. You may derive from
built-in optimizers in torch.optim, or directly implement a new optimizer.
"""
| 320 | 25.75 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/models/localizers/base.py | from abc import ABCMeta, abstractmethod
from collections import OrderedDict
import torch
import torch.distributed as dist
import torch.nn as nn
from .. import builder
class BaseLocalizer(nn.Module, metaclass=ABCMeta):
"""Base class for localizers.
All localizers should subclass it. All subclass should over... | 5,143 | 34.722222 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/models/localizers/bsn.py | import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from ...localization import temporal_iop
from ..builder import LOCALIZERS, build_loss
from .base import BaseLocalizer
from .utils import post_processing
@LOCALIZERS.register_module()
class TEM(BaseLocalizer):
"""Temporal Evalua... | 15,855 | 39.141772 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/models/localizers/ssn.py | import torch
import torch.nn as nn
from .. import builder
from ..builder import LOCALIZERS
from .base import BaseLocalizer
@LOCALIZERS.register_module()
class SSN(BaseLocalizer):
"""Temporal Action Detection with Structured Segment Networks.
Args:
backbone (dict): Config for building backbone.
... | 5,048 | 36.4 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/models/localizers/bmn.py | import math
import numpy as np
import torch
import torch.nn as nn
from ...localization import temporal_iop, temporal_iou
from ..builder import LOCALIZERS, build_loss
from .base import BaseLocalizer
from .utils import post_processing
@LOCALIZERS.register_module()
class BMN(BaseLocalizer):
"""Boundary Matching Ne... | 17,788 | 41.659472 | 93 | py |
STTS | STTS-main/VideoSwin/mmaction/models/recognizers/base.py | import warnings
from abc import ABCMeta, abstractmethod
from collections import OrderedDict
import torch
import torch.distributed as dist
import torch.nn as nn
import torch.nn.functional as F
from mmcv.runner import auto_fp16
from .. import builder
class BaseRecognizer(nn.Module, metaclass=ABCMeta):
"""Base cla... | 12,392 | 36.554545 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/models/recognizers/recognizer3d.py | import torch
from torch import nn
from ..builder import RECOGNIZERS
from .base import BaseRecognizer
def copyParams(module_src, module_dest):
params_src = module_src.named_parameters()
params_dest = module_dest.named_parameters()
dict_dest = dict(params_dest)
for name, param in params_src:
... | 4,166 | 30.330827 | 78 | py |
STTS | STTS-main/VideoSwin/mmaction/models/recognizers/recognizer2d.py | import torch
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, labels, **kwargs):
"""Defines the computation performed at every ... | 6,572 | 34.33871 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/models/recognizers/audio_recognizer.py | from ..builder import RECOGNIZERS
from .base import BaseRecognizer
@RECOGNIZERS.register_module()
class AudioRecognizer(BaseRecognizer):
"""Audio recognizer model framework."""
def forward(self, audios, label=None, return_loss=True):
"""Define the computation performed at every call."""
if re... | 3,632 | 34.617647 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/models/common/tam.py | import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import constant_init, kaiming_init, normal_init
class TAM(nn.Module):
"""Temporal Adaptive Module(TAM) for TANet.
This module is proposed in `TAM: TEMPORAL ADAPTIVE MODULE FOR VIDEO
RECOGNITION <https://arxiv.org/pdf/2005.06803>`_
A... | 5,051 | 36.422222 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/models/common/conv_audio.py | import torch
import torch.nn as nn
from mmcv.cnn import CONV_LAYERS, ConvModule, constant_init, kaiming_init
from torch.nn.modules.utils import _pair
@CONV_LAYERS.register_module()
class ConvAudio(nn.Module):
"""Conv2d module for AudioResNet backbone.
<https://arxiv.org/abs/2001.08740>`_.
Args:
... | 3,225 | 29.72381 | 77 | py |
STTS | STTS-main/VideoSwin/mmaction/models/common/lfb.py | import io
import os.path as osp
import warnings
import numpy as np
import torch
import torch.distributed as dist
from mmcv.runner import get_dist_info
try:
import lmdb
lmdb_imported = True
except (ImportError, ModuleNotFoundError):
lmdb_imported = False
class LFB:
"""Long-Term Feature Bank (LFB).
... | 7,493 | 38.650794 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/models/common/conv2plus1d.py | import torch.nn as nn
from mmcv.cnn import CONV_LAYERS, build_norm_layer, constant_init, kaiming_init
from torch.nn.modules.utils import _triple
@CONV_LAYERS.register_module()
class Conv2plus1d(nn.Module):
"""(2+1)d Conv module for R(2+1)d backbone.
https://arxiv.org/pdf/1711.11248.pdf.
Args:
in... | 3,453 | 31.895238 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/models/necks/tpn.py | import numpy as np
import torch
import torch.nn as nn
from mmcv.cnn import ConvModule, constant_init, normal_init, xavier_init
from ..builder import NECKS, build_loss
class Identity(nn.Module):
"""Identity mapping."""
def forward(self, x):
return x
class DownSample(nn.Module):
"""DownSample mo... | 16,411 | 35.552339 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/models/roi_extractors/single_straight3d.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from mmaction.utils import import_module_error_class
try:
from mmcv.ops import RoIAlign, RoIPool
except (ImportError, ModuleNotFoundError):
@import_module_error_class('mmcv-full')
class RoIAlign(nn.Module):
pass
@import_modul... | 4,474 | 33.689922 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/models/losses/base.py | from abc import ABCMeta, abstractmethod
import torch.nn as nn
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:
loss_weight (float): Factor scalar mu... | 1,181 | 25.266667 | 77 | py |
STTS | STTS-main/VideoSwin/mmaction/models/losses/margin_loss.py | import torch
import torch.nn.functional as F
import torch.nn as nn
from ..builder import LOSSES
def batched_index_select(input, dim, index):
for i in range(1, len(input.shape)):
if i != dim:
index = index.unsqueeze(i)
expanse = list(input.shape)
expanse[0] = -1
expanse[dim] = -1
... | 2,004 | 34.175439 | 91 | py |
STTS | STTS-main/VideoSwin/mmaction/models/losses/distill_loss.py | import torch.nn.functional as F
import torch.nn as nn
from ..builder import LOSSES
@LOSSES.register_module()
class DistillationLoss(nn.Module):
"""
This module wraps a standard criterion and adds an extra knowledge distillation loss by
taking a teacher model prediction and using it as additional supervis... | 2,144 | 34.75 | 91 | py |
STTS | STTS-main/VideoSwin/mmaction/models/losses/ohem_hinge_loss.py | import torch
class OHEMHingeLoss(torch.autograd.Function):
"""This class is the core implementation for the completeness loss in
paper.
It compute class-wise hinge loss and performs online hard example mining
(OHEM).
"""
@staticmethod
def forward(ctx, pred, labels, is_positive, ohem_rati... | 2,497 | 37.430769 | 77 | py |
STTS | STTS-main/VideoSwin/mmaction/models/losses/bmn_loss.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from ..builder import LOSSES
from .binary_logistic_regression_loss import binary_logistic_regression_loss
@LOSSES.register_module()
class BMNLoss(nn.Module):
"""BMN Loss.
From paper https://arxiv.org/abs/1907.09702,
code https://github.c... | 7,173 | 38.635359 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/models/losses/nll_loss.py | import torch.nn.functional as F
from ..builder import LOSSES
from .base import BaseWeightedLoss
@LOSSES.register_module()
class NLLLoss(BaseWeightedLoss):
"""NLL Loss.
It will calculate NLL loss given cls_score and label.
"""
def _forward(self, cls_score, label, **kwargs):
"""Forward functi... | 688 | 24.518519 | 74 | py |
STTS | STTS-main/VideoSwin/mmaction/models/losses/hvu_loss.py | import torch
import torch.nn.functional as F
from ..builder import LOSSES
from .base import BaseWeightedLoss
@LOSSES.register_module()
class HVULoss(BaseWeightedLoss):
"""Calculate the BCELoss for HVU.
Args:
categories (tuple[str]): Names of tag categories, tags are organized in
this ord... | 6,676 | 46.021127 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/models/losses/binary_logistic_regression_loss.py | import torch
import torch.nn as nn
from ..builder import LOSSES
def binary_logistic_regression_loss(reg_score,
label,
threshold=0.5,
ratio_range=(1.05, 21),
eps=1e-5):
"... | 2,061 | 32.258065 | 75 | py |
STTS | STTS-main/VideoSwin/mmaction/models/losses/ssn_loss.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from ..builder import LOSSES
from .ohem_hinge_loss import OHEMHingeLoss
@LOSSES.register_module()
class SSNLoss(nn.Module):
@staticmethod
def activity_loss(activity_score, labels, activity_indexer):
"""Activity Loss.
It will... | 7,274 | 39.416667 | 102 | py |
STTS | STTS-main/VideoSwin/mmaction/models/losses/cross_entropy_loss.py | import torch
import torch.nn.functional as F
import torch.nn as nn
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 type. It's worth
mentionin... | 4,774 | 39.12605 | 132 | py |
STTS | STTS-main/VideoSwin/mmaction/models/backbones/mobilenet_v2.py | import torch.nn as nn
import torch.utils.checkpoint as cp
from mmcv.cnn import ConvModule, constant_init, kaiming_init
from mmcv.runner import load_checkpoint
from torch.nn.modules.batchnorm import _BatchNorm
from ...utils import get_root_logger
from ..builder import BACKBONES
def make_divisible(value, divisor, min_... | 10,933 | 35.691275 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/models/backbones/c3d.py | import torch.nn as nn
from mmcv.cnn import ConvModule, constant_init, kaiming_init, normal_init
from mmcv.runner import load_checkpoint
from mmcv.utils import _BatchNorm
from ...utils import get_root_logger
from ..builder import BACKBONES
@BACKBONES.register_module()
class C3D(nn.Module):
"""C3D backbone.
A... | 4,771 | 33.085714 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/models/backbones/checkpoint.py | # Copyright (c) OpenMMLab. All rights reserved.
import io
import os
import os.path as osp
import pkgutil
import re
import time
import warnings
from collections import OrderedDict
from importlib import import_module
from tempfile import TemporaryDirectory
import torch
import torchvision
from torch.optim import Optimize... | 24,129 | 34.021771 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/models/backbones/resnet3d_csn.py | import torch.nn as nn
from mmcv.cnn import ConvModule
from mmcv.utils import _BatchNorm
from ..builder import BACKBONES
from .resnet3d import Bottleneck3d, ResNet3d
class CSNBottleneck3d(Bottleneck3d):
"""Channel-Separated Bottleneck Block.
This module is proposed in
"Video Classification with Channel-S... | 6,234 | 40.845638 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/models/backbones/swin_transformer.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.utils.checkpoint as checkpoint
import numpy as np
from timm.models.layers import DropPath, trunc_normal_
# from mmcv.runner import load_checkpoint
from .checkpoint import load_checkpoint
from mmaction.utils import get_root_logger
from ..bu... | 30,486 | 40.032301 | 156 | py |
STTS | STTS-main/VideoSwin/mmaction/models/backbones/resnet.py | 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 torch.utils import checkpoint as cp
from ...utils import get_root_logger
from ..builder import BACKBONES
class BasicBlock(nn.Module):
... | 21,448 | 35.292724 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/models/backbones/resnet_audio.py | import torch.nn as nn
import torch.utils.checkpoint as cp
from mmcv.cnn import ConvModule, constant_init, kaiming_init
from mmcv.runner import load_checkpoint
from torch.nn.modules.batchnorm import _BatchNorm
from torch.nn.modules.utils import _ntuple
from ...utils import get_root_logger
from ..builder import BACKBONE... | 13,252 | 34.435829 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/models/backbones/topk.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
import einops
from einops import rearrange
from math import sqrt
class PredictorLG(nn.Module):
""" Image to Patch Embedding
"""
def __init__(self, embed_dim=384):
super().__init__()
self.in_conv = nn.Seque... | 8,524 | 33.375 | 124 | py |
STTS | STTS-main/VideoSwin/mmaction/models/backbones/resnet3d.py | import torch.nn as nn
import torch.utils.checkpoint as cp
from mmcv.cnn import (ConvModule, NonLocal3d, 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, _trip... | 40,219 | 38.277344 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/models/backbones/resnet3d_slowfast.py | import torch
import torch.nn as nn
from mmcv.cnn import ConvModule, kaiming_init
from mmcv.runner import _load_checkpoint, load_checkpoint
from mmcv.utils import print_log
from ...utils import get_root_logger
from ..builder import BACKBONES
from .resnet3d import ResNet3d
try:
from mmdet.models import BACKBONES as... | 21,060 | 39.424184 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/models/backbones/resnet2plus1d.py | from ..builder import BACKBONES
from .resnet3d import ResNet3d
@BACKBONES.register_module()
class ResNet2Plus1d(ResNet3d):
"""ResNet (2+1)d backbone.
This model is proposed in `A Closer Look at Spatiotemporal Convolutions for
Action Recognition <https://arxiv.org/abs/1711.11248>`_
"""
def __init... | 1,482 | 28.66 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/models/backbones/resnet_tsm.py | import torch
import torch.nn as nn
from mmcv.cnn import NonLocal3d
from torch.nn.modules.utils import _ntuple
from ..builder import BACKBONES
from .resnet import ResNet
class NL3DWrapper(nn.Module):
"""3D Non-local wrapper for ResNet50.
Wrap ResNet layers with 3D NonLocal modules.
Args:
block (... | 10,742 | 35.416949 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/models/backbones/resnet_tin.py | import torch
import torch.nn as nn
from mmaction.utils import import_module_error_func
from ..builder import BACKBONES
from .resnet_tsm import ResNetTSM
try:
from mmcv.ops import tin_shift
except (ImportError, ModuleNotFoundError):
@import_module_error_func('mmcv-full')
def tin_shift(*args, **kwargs):
... | 13,132 | 33.651715 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/models/backbones/tanet.py | from copy import deepcopy
import torch.nn as nn
from torch.utils import checkpoint as cp
from ..builder import BACKBONES
from ..common import TAM
from .resnet import Bottleneck, ResNet
class TABlock(nn.Module):
"""Temporal Adaptive Block (TA-Block) for TANet.
This block is proposed in `TAM: TEMPORAL ADAPTI... | 3,690 | 31.095652 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/models/backbones/x3d.py | import math
import torch.nn as nn
import torch.utils.checkpoint as cp
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 get_root_logger
from ..builder import... | 19,116 | 35.482824 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/models/heads/base.py | from abc import ABCMeta, abstractmethod
import torch
import torch.nn as nn
from ...core import top_k_accuracy
from ..builder import build_loss
class AvgConsensus(nn.Module):
"""Average consensus module.
Args:
dim (int): Decide which dim consensus function to apply.
Default: 1.
"""
... | 3,854 | 34.045455 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/models/heads/fbo_head.py | import copy
import torch
import torch.nn as nn
from mmcv.cnn import ConvModule, constant_init, kaiming_init
from mmcv.runner import load_checkpoint
from mmcv.utils import _BatchNorm
from mmaction.models.common import LFB
from mmaction.utils import get_root_logger
try:
from mmdet.models.builder import SHARED_HEAD... | 14,120 | 34.390977 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/models/heads/ssn_head.py | import torch
import torch.nn as nn
from mmcv.cnn import normal_init
from ..builder import HEADS
def parse_stage_config(stage_cfg):
"""Parse config of STPP for three stages.
Args:
stage_cfg (int | tuple[int]):
Config of structured temporal pyramid pooling.
Returns:
tuple[tupl... | 16,778 | 39.627119 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/models/heads/audio_tsn_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 AudioTSNHead(BaseHead):
"""Classification head for TSN on audio.
Args:
num_classes (int): Number of classes to be classified.
in_channels (int): Number... | 2,421 | 31.72973 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/models/heads/trn_head.py | import itertools
import numpy as np
import torch
import torch.nn as nn
from mmcv.cnn import normal_init
from ..builder import HEADS
from .base import BaseHead
class RelationModule(nn.Module):
"""Relation Module of TRN.
Args:
hidden_dim (int): The dimension of hidden layer of MLP in relation
... | 7,868 | 36.293839 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/models/heads/tsm_head.py | import torch
import torch.nn as nn
from mmcv.cnn import normal_init
from ..builder import HEADS
from .base import AvgConsensus, BaseHead
@HEADS.register_module()
class TSMHead(BaseHead):
"""Class head for TSM.
Args:
num_classes (int): Number of classes to be classified.
in_channels (int): Nu... | 4,170 | 36.241071 | 78 | py |
STTS | STTS-main/VideoSwin/mmaction/models/heads/bbox_head.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from mmaction.core.bbox import bbox_target
try:
from mmdet.models.builder import HEADS as MMDET_HEADS
mmdet_imported = True
except (ImportError, ModuleNotFoundError):
mmdet_imported = False
class BBoxHeadAVA(nn.Module):
"""Simplest R... | 8,768 | 34.358871 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/models/heads/misc_head.py | import torch
import torch.nn as nn
from mmcv.cnn import ConvModule, constant_init, kaiming_init
from mmcv.utils import _BatchNorm
try:
from mmdet.models.builder import SHARED_HEADS as MMDET_SHARED_HEADS
mmdet_imported = True
except (ImportError, ModuleNotFoundError):
mmdet_imported = False
# Note: All the... | 4,040 | 29.613636 | 76 | py |
STTS | STTS-main/VideoSwin/mmaction/models/heads/tpn_head.py | import torch.nn as nn
from ..builder import HEADS
from .tsn_head import TSNHead
@HEADS.register_module()
class TPNHead(TSNHead):
"""Class head for TPN.
Args:
num_classes (int): Number of classes to be classified.
in_channels (int): Number of channels in input feature.
loss_cls (dict)... | 3,306 | 35.340659 | 78 | py |
STTS | STTS-main/VideoSwin/mmaction/models/heads/x3d_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 X3DHead(BaseHead):
"""Classification head for I3D.
Args:
num_classes (int): Number of classes to be classified.
in_channels (int): Number of channels i... | 2,837 | 30.533333 | 78 | py |
STTS | STTS-main/VideoSwin/mmaction/models/heads/slowfast_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 SlowFastHead(BaseHead):
"""The classification head for SlowFast.
Args:
num_classes (int): Number of classes to be classified.
in_channels ... | 2,542 | 30.7875 | 78 | py |
STTS | STTS-main/VideoSwin/mmaction/models/heads/tsn_head.py | import torch.nn as nn
from mmcv.cnn import normal_init
from ..builder import HEADS
from .base import AvgConsensus, BaseHead
@HEADS.register_module()
class TSNHead(BaseHead):
"""Class head for TSN.
Args:
num_classes (int): Number of classes to be classified.
in_channels (int): Number of chann... | 3,148 | 33.228261 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/models/heads/lfb_infer_head.py | import os.path as osp
import mmcv
import torch
import torch.distributed as dist
import torch.nn as nn
from mmcv.runner import get_dist_info
try:
from mmdet.models.builder import SHARED_HEADS as MMDET_SHARED_HEADS
mmdet_imported = True
except (ImportError, ModuleNotFoundError):
mmdet_imported = False
cla... | 5,150 | 34.280822 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/models/heads/i3d_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 I3DHead(BaseHead):
"""Classification head for I3D.
Args:
num_classes (int): Number of classes to be classified.
in_channels (int): Number of channels i... | 2,446 | 32.067568 | 78 | py |
STTS | STTS-main/VideoSwin/mmaction/models/heads/roi_head.py | import numpy as np
from mmaction.core.bbox import bbox2result
from mmaction.utils import import_module_error_class
try:
from mmdet.core.bbox import bbox2roi
from mmdet.models import HEADS as MMDET_HEADS
from mmdet.models.roi_heads import StandardRoIHead
mmdet_imported = True
except (ImportError, Modul... | 4,487 | 35.487805 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/datasets/base.py | import copy
import os.path as osp
import warnings
from abc import ABCMeta, abstractmethod
from collections import OrderedDict, defaultdict
import mmcv
import numpy as np
import torch
from mmcv.utils import print_log
from torch.utils.data import Dataset
from ..core import (mean_average_precision, mean_class_accuracy,
... | 11,612 | 39.322917 | 105 | py |
STTS | STTS-main/VideoSwin/mmaction/datasets/audio_dataset.py | import os.path as osp
import torch
from .base import BaseDataset
from .builder import DATASETS
@DATASETS.register_module()
class AudioDataset(BaseDataset):
"""Audio dataset for video recognition. Extracts the audio feature on-the-
fly. Annotation file can be that of the rawframe dataset, or:
.. code-bl... | 2,555 | 35.514286 | 78 | py |
STTS | STTS-main/VideoSwin/mmaction/datasets/audio_feature_dataset.py | import os.path as osp
import torch
from .base import BaseDataset
from .builder import DATASETS
@DATASETS.register_module()
class AudioFeatureDataset(BaseDataset):
"""Audio feature dataset for video recognition. Reads the features
extracted off-line. Annotation file can be that of the rawframe dataset,
o... | 2,581 | 35.366197 | 76 | py |
STTS | STTS-main/VideoSwin/mmaction/datasets/blending_utils.py | from abc import ABCMeta, abstractmethod
import torch
import torch.nn.functional as F
from torch.distributions.beta import Beta
from .builder import BLENDINGS
__all__ = ['BaseMiniBatchBlending', 'MixupBlending', 'CutmixBlending', 'LabelSmoothing']
def one_hot(x, num_classes, on_value=1., off_value=0., device='cuda')... | 5,741 | 36.529412 | 139 | py |
STTS | STTS-main/VideoSwin/mmaction/datasets/rawframe_dataset.py | import copy
import os.path as osp
import torch
from .base import BaseDataset
from .builder import DATASETS
@DATASETS.register_module()
class RawframeDataset(BaseDataset):
"""Rawframe dataset for action recognition.
The dataset loads raw frames and apply specified transforms to return a
dict containing ... | 6,689 | 35.358696 | 78 | py |
STTS | STTS-main/VideoSwin/mmaction/datasets/hvu_dataset.py | import copy
import os.path as osp
from collections import OrderedDict
import mmcv
import numpy as np
from mmcv.utils import print_log
from ..core import mean_average_precision
from .base import BaseDataset
from .builder import DATASETS
@DATASETS.register_module()
class HVUDataset(BaseDataset):
"""HVU dataset, w... | 7,052 | 35.734375 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/datasets/ssn_dataset.py | import copy
import os.path as osp
import warnings
from collections import OrderedDict
import mmcv
import numpy as np
from torch.nn.modules.utils import _pair
from ..core import softmax
from ..localization import (eval_ap, load_localize_proposal_file,
perform_regression, temporal_iou, tempo... | 37,498 | 41.515873 | 120 | py |
STTS | STTS-main/VideoSwin/mmaction/datasets/builder.py | import platform
import random
from functools import partial
import numpy as np
from mmcv.parallel import collate
from mmcv.runner import get_dist_info
from mmcv.utils import Registry, build_from_cfg
from torch.utils.data import DataLoader
from .samplers import ClassSpecificDistributedSampler, DistributedSampler
if p... | 4,449 | 32.458647 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/datasets/samplers/distributed_sampler.py | import math
from collections import defaultdict
import torch
from torch.utils.data import DistributedSampler as _DistributedSampler
class DistributedSampler(_DistributedSampler):
"""DistributedSampler inheriting from
``torch.utils.data.DistributedSampler``.
In pytorch of lower versions, there is no ``sh... | 4,908 | 35.362963 | 78 | py |
STTS | STTS-main/VideoSwin/mmaction/datasets/pipelines/loading.py | import io
import os
import os.path as osp
import shutil
import warnings
import mmcv
import numpy as np
import torch
from mmcv.fileio import FileClient
from torch.nn.modules.utils import _pair
from ...utils import get_random_string, get_shm_dir, get_thread_id
from ..builder import PIPELINES
import random
@PIPELINES.... | 60,896 | 35.334726 | 143 | py |
STTS | STTS-main/VideoSwin/mmaction/datasets/pipelines/augmentations.py | import random
import warnings
from collections.abc import Sequence
import mmcv
import numpy as np
from torch.nn.modules.utils import _pair
import timm.data as tdata
import torch
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] * b[3]... | 79,509 | 37.207593 | 104 | py |
STTS | STTS-main/VideoSwin/mmaction/datasets/pipelines/formating.py | from collections.abc import Sequence
import mmcv
import numpy as np
import torch
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 types are: :class:`numpy.ndarray`, :class:`torch.T... | 12,741 | 33.160858 | 79 | py |
STTS | STTS-main/VideoSwin/mmaction/utils/gradcam_utils.py | import torch
import torch.nn.functional as F
class GradCAM:
"""GradCAM class helps create visualization results.
Visualization results are blended by heatmaps and input images.
This class is modified from
https://github.com/facebookresearch/SlowFast/blob/master/slowfast/visualization/gradcam_utils.py... | 9,645 | 40.577586 | 107 | py |
STTS | STTS-main/VideoSwin/mmaction/utils/precise_bn.py | # Adapted from https://github.com/facebookresearch/fvcore/blob/master/fvcore/nn/precise_bn.py # noqa: E501
# Original licence: Copyright (c) 2019 Facebook, Inc under the Apache License 2.0 # noqa: E501
import logging
import time
import mmcv
import torch
from mmcv.parallel import MMDistributedDataParallel
from mmcv.... | 5,826 | 36.352564 | 107 | py |
STTS | STTS-main/VideoSwin/mmaction/utils/module_hooks.py | import torch
from mmcv.utils import Registry, build_from_cfg
MODULE_HOOKS = Registry('module_hooks')
def register_module_hooks(Module, module_hooks_list):
handles = []
for module_hook_cfg in module_hooks_list:
hooked_module_name = module_hook_cfg.pop('hooked_module', 'backbone')
if not hasatt... | 3,371 | 37.318182 | 77 | py |
STTS | STTS-main/VideoSwin/tests/test_runtime/test_train.py | import copy
import tempfile
from collections import OrderedDict
import pytest
import torch
import torch.nn as nn
from mmcv import Config
from torch.utils.data import Dataset
from mmaction.apis import train_model
from mmaction.datasets import DATASETS
@DATASETS.register_module()
class ExampleDataset(Dataset):
d... | 4,059 | 29.298507 | 79 | py |
STTS | STTS-main/VideoSwin/tests/test_runtime/test_optimizer.py | import torch
import torch.nn as nn
from mmcv.runner import build_optimizer_constructor
class SubModel(nn.Module):
def __init__(self):
super().__init__()
self.conv1 = nn.Conv2d(2, 2, kernel_size=1, groups=2)
self.gn = nn.GroupNorm(2, 2)
self.fc = nn.Linear(2, 2)
self.param1... | 7,742 | 35.182243 | 76 | py |
STTS | STTS-main/VideoSwin/tests/test_runtime/test_config.py | import glob
import os
import os.path as osp
import mmcv
import torch.nn as nn
from mmaction.models import build_localizer, build_recognizer
def _get_config_path():
"""Find the predefined recognizer config path."""
repo_dir = osp.dirname(osp.dirname(osp.dirname(__file__)))
config_dpath = osp.join(repo_di... | 2,887 | 38.027027 | 79 | py |
STTS | STTS-main/VideoSwin/tests/test_runtime/test_eval_hook.py | import os.path as osp
import tempfile
import unittest.mock as mock
import warnings
from collections import OrderedDict
from unittest.mock import MagicMock, patch
import pytest
import torch
import torch.nn as nn
from mmcv.runner import EpochBasedRunner, IterBasedRunner
from mmcv.utils import get_logger
from torch.utils... | 12,595 | 35.616279 | 79 | py |
STTS | STTS-main/VideoSwin/tests/test_runtime/test_precise_bn.py | import copy
import numpy as np
import pytest
import torch
import torch.nn as nn
from mmcv.parallel import MMDistributedDataParallel
from mmcv.runner import EpochBasedRunner, build_optimizer
from mmcv.utils import get_logger
from torch.utils.data import DataLoader, Dataset
from mmaction.utils import PreciseBNHook
cl... | 6,456 | 30.497561 | 78 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.