code stringlengths 66 870k | docstring stringlengths 19 26.7k | func_name stringlengths 1 138 | language stringclasses 1
value | repo stringlengths 7 68 | path stringlengths 5 324 | url stringlengths 46 389 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
def compute_metrics(self, results: list) -> dict:
"""Compute the metrics from processed results.
Args:
results (list): The processed results of each batch.
Returns:
dict: The computed metrics. The keys are the names of the metrics,
and the values are correspo... | Compute the metrics from processed results.
Args:
results (list): The processed results of each batch.
Returns:
dict: The computed metrics. The keys are the names of the metrics,
and the values are corresponding results.
| compute_metrics | python | open-mmlab/mmaction2 | mmaction/evaluation/metrics/ava_metric.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/evaluation/metrics/ava_metric.py | Apache-2.0 |
def process(self, data_batch, data_samples):
"""Process one batch of data samples.
The processed results should be stored in ``self.results``, which will
be used to computed the metrics when all batches have been processed.
Args:
data_batch: A batch of data from the dataloa... | Process one batch of data samples.
The processed results should be stored in ``self.results``, which will
be used to computed the metrics when all batches have been processed.
Args:
data_batch: A batch of data from the dataloader.
data_samples (Sequence[dict]): A batch ... | process | python | open-mmlab/mmaction2 | mmaction/evaluation/metrics/multimodal_metric.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/evaluation/metrics/multimodal_metric.py | Apache-2.0 |
def compute_metrics(self, results: List):
"""Compute the metrics from processed results.
Args:
results (dict): The processed results of each batch.
Returns:
Dict: The computed metrics. The keys are the names of the metrics,
and the values are corresponding r... | Compute the metrics from processed results.
Args:
results (dict): The processed results of each batch.
Returns:
Dict: The computed metrics. The keys are the names of the metrics,
and the values are corresponding results.
| compute_metrics | python | open-mmlab/mmaction2 | mmaction/evaluation/metrics/multimodal_metric.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/evaluation/metrics/multimodal_metric.py | Apache-2.0 |
def process(self, data_batch, data_samples) -> None:
"""transfer tensors in predictions to CPU."""
for sample in data_samples:
question_id = sample['question_id']
pred_answer = sample['pred_answer']
result = {
'question_id': int(question_id),
... | transfer tensors in predictions to CPU. | process | python | open-mmlab/mmaction2 | mmaction/evaluation/metrics/multimodal_metric.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/evaluation/metrics/multimodal_metric.py | Apache-2.0 |
def compute_metrics(self, results: List):
"""Dump the result to json file."""
mmengine.dump(results, self.file_path)
logger = MMLogger.get_current_instance()
logger.info(f'Results has been saved to {self.file_path}.')
return {} | Dump the result to json file. | compute_metrics | python | open-mmlab/mmaction2 | mmaction/evaluation/metrics/multimodal_metric.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/evaluation/metrics/multimodal_metric.py | Apache-2.0 |
def process(self, data_batch, data_samples):
"""Process one batch of data samples.
The processed results should be stored in ``self.results``, which will
be used to computed the metrics when all batches have been processed.
Args:
data_batch: A batch of data from the dataloa... | Process one batch of data samples.
The processed results should be stored in ``self.results``, which will
be used to computed the metrics when all batches have been processed.
Args:
data_batch: A batch of data from the dataloader.
data_samples (Sequence[dict]): A batch ... | process | python | open-mmlab/mmaction2 | mmaction/evaluation/metrics/multimodal_metric.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/evaluation/metrics/multimodal_metric.py | Apache-2.0 |
def compute_metrics(self, results: List):
"""Compute the metrics from processed results.
Args:
results (dict): The processed results of each batch.
Returns:
Dict: The computed metrics. The keys are the names of the metrics,
and the values are corresponding r... | Compute the metrics from processed results.
Args:
results (dict): The processed results of each batch.
Returns:
Dict: The computed metrics. The keys are the names of the metrics,
and the values are corresponding results.
| compute_metrics | python | open-mmlab/mmaction2 | mmaction/evaluation/metrics/multimodal_metric.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/evaluation/metrics/multimodal_metric.py | Apache-2.0 |
def process(self, data_batch: Sequence[dict],
data_samples: Sequence[dict]):
"""Process one batch of data and predictions.
The processed results should be stored in ``self.results``, which will
be used to computed the metrics when all batches have been processed.
Args:
... | Process one batch of data and predictions.
The processed results should be stored in ``self.results``, which will
be used to computed the metrics when all batches have been processed.
Args:
data_batch (Sequence[dict]): A batch of data from the dataloader.
predictions (S... | process | python | open-mmlab/mmaction2 | mmaction/evaluation/metrics/multimodal_metric.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/evaluation/metrics/multimodal_metric.py | Apache-2.0 |
def compute_metrics(self, results: List):
"""Compute the metrics from processed results.
Args:
results (list): The processed results of each batch.
Returns:
Dict: The computed metrics. The keys are the names of the metrics,
and the values are corresponding r... | Compute the metrics from processed results.
Args:
results (list): The processed results of each batch.
Returns:
Dict: The computed metrics. The keys are the names of the metrics,
and the values are corresponding results.
| compute_metrics | python | open-mmlab/mmaction2 | mmaction/evaluation/metrics/multimodal_metric.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/evaluation/metrics/multimodal_metric.py | Apache-2.0 |
def calculate(pred: Union[np.ndarray, torch.Tensor],
target: Union[np.ndarray, torch.Tensor],
topk: Union[int, Sequence[int]],
pred_indices: (bool) = False,
target_indices: (bool) = False) -> float:
"""Calculate the average recall.
... | Calculate the average recall.
Args:
pred (torch.Tensor | np.ndarray | Sequence): The prediction
results. A :obj:`torch.Tensor` or :obj:`np.ndarray` with
shape ``(N, M)`` or a sequence of index/onehot
format labels.
target (torch.Tensor | n... | calculate | python | open-mmlab/mmaction2 | mmaction/evaluation/metrics/multimodal_metric.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/evaluation/metrics/multimodal_metric.py | Apache-2.0 |
def _format_pred(label, topk=None, is_indices=False):
"""format various label to List[indices]."""
if is_indices:
assert isinstance(label, Sequence), \
'`pred` must be Sequence of indices when' \
f' `pred_indices` set to True, but get {type(label)}'
for i, sample... | format various label to List[indices]. | _format_pred | python | open-mmlab/mmaction2 | mmaction/evaluation/metrics/multimodal_metric.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/evaluation/metrics/multimodal_metric.py | Apache-2.0 |
def _format_target(label, is_indices=False):
"""format various label to List[indices]."""
if is_indices:
assert isinstance(label, Sequence), \
'`target` must be Sequence of indices when' \
f' `target_indices` set to True, but get {type(label)}'
for i, sample_gt i... | format various label to List[indices]. | _format_target | python | open-mmlab/mmaction2 | mmaction/evaluation/metrics/multimodal_metric.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/evaluation/metrics/multimodal_metric.py | Apache-2.0 |
def process(self, data_batch: Sequence[Tuple[Any, dict]],
data_samples: Sequence[dict]) -> None:
"""Process one batch of data samples and predictions. The processed
results should be stored in ``self.results``, which will be used to
compute the metrics when all batches have been ... | Process one batch of data samples and predictions. The processed
results should be stored in ``self.results``, which will be used to
compute the metrics when all batches have been processed.
Args:
data_batch (Sequence[Tuple[Any, dict]]): A batch of data
from the data... | process | python | open-mmlab/mmaction2 | mmaction/evaluation/metrics/multisports_metric.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/evaluation/metrics/multisports_metric.py | Apache-2.0 |
def compute_metrics(self, results: list) -> dict:
"""Compute the metrics from processed results.
Args:
results (list): The processed results of each batch.
Returns:
dict: The computed metrics. The keys are the names of the metrics,
and the values are correspo... | Compute the metrics from processed results.
Args:
results (list): The processed results of each batch.
Returns:
dict: The computed metrics. The keys are the names of the metrics,
and the values are corresponding results.
| compute_metrics | python | open-mmlab/mmaction2 | mmaction/evaluation/metrics/multisports_metric.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/evaluation/metrics/multisports_metric.py | Apache-2.0 |
def process(self, data_batch: Optional[Dict],
data_samples: Sequence[Dict]) -> None:
"""Process one batch of data samples and data_samples. The processed
results should be stored in ``self.results``, which will be used to
compute the metrics when all batches have been processed.
... | Process one batch of data samples and data_samples. The processed
results should be stored in ``self.results``, which will be used to
compute the metrics when all batches have been processed.
Args:
data_batch (dict, optional): A batch of data from the dataloader.
data_sa... | process | python | open-mmlab/mmaction2 | mmaction/evaluation/metrics/retrieval_metric.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/evaluation/metrics/retrieval_metric.py | Apache-2.0 |
def compute_metrics(self, results: List) -> Dict:
"""Compute the metrics from processed results.
Args:
results (list): The processed results of each batch.
Returns:
dict: The computed metrics. The keys are the names of the metrics,
and the values are corresp... | Compute the metrics from processed results.
Args:
results (list): The processed results of each batch.
Returns:
dict: The computed metrics. The keys are the names of the metrics,
and the values are corresponding results.
| compute_metrics | python | open-mmlab/mmaction2 | mmaction/evaluation/metrics/retrieval_metric.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/evaluation/metrics/retrieval_metric.py | Apache-2.0 |
def process(self, data_batch: Sequence[Tuple[Any, dict]],
predictions: Sequence[dict]) -> None:
"""Process one batch of data samples and predictions. The processed
results should be stored in ``self.results``, which will be used to
compute the metrics when all batches have been p... | Process one batch of data samples and predictions. The processed
results should be stored in ``self.results``, which will be used to
compute the metrics when all batches have been processed.
Args:
data_batch (Sequence[Tuple[Any, dict]]): A batch of data
from the data... | process | python | open-mmlab/mmaction2 | mmaction/evaluation/metrics/video_grounding_metric.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/evaluation/metrics/video_grounding_metric.py | Apache-2.0 |
def compute_metrics(self, results: list) -> dict:
"""Compute the metrics from processed results.
Args:
results (list): The processed results of each batch.
Returns:
dict: The computed metrics. The keys are the names of the metrics,
and the values are correspo... | Compute the metrics from processed results.
Args:
results (list): The processed results of each batch.
Returns:
dict: The computed metrics. The keys are the names of the metrics,
and the values are corresponding results.
| compute_metrics | python | open-mmlab/mmaction2 | mmaction/evaluation/metrics/video_grounding_metric.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/evaluation/metrics/video_grounding_metric.py | Apache-2.0 |
def forward(self, x: torch.Tensor) -> torch.Tensor:
"""Defines the computation performed at every call."""
N, M, T, V, C = x.size()
x = x.permute(0, 1, 3, 4, 2).contiguous()
if self.data_bn_type == 'MVC':
x = self.data_bn(x.view(N, M * V * C, T))
else:
x =... | Defines the computation performed at every call. | forward | python | open-mmlab/mmaction2 | mmaction/models/backbones/aagcn.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/aagcn.py | Apache-2.0 |
def _make_stem_layer(self) -> None:
"""Construct the stem layers consists of a conv+norm+act module and a
pooling layer."""
self.conv1 = ConvModule(
self.in_channels,
64,
kernel_size=7,
stride=2,
padding=3,
bias=False,
... | Construct the stem layers consists of a conv+norm+act module and a
pooling layer. | _make_stem_layer | python | open-mmlab/mmaction2 | mmaction/models/backbones/c2d.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/c2d.py | Apache-2.0 |
def forward(self, x: torch.Tensor) \
-> Union[torch.Tensor, Tuple[torch.Tensor]]:
"""Defines the computation performed at every call.
Args:
x (torch.Tensor): The input data.
Returns:
Union[torch.Tensor or Tuple[torch.Tensor]]: The feature of the
... | Defines the computation performed at every call.
Args:
x (torch.Tensor): The input data.
Returns:
Union[torch.Tensor or Tuple[torch.Tensor]]: The feature of the
input samples extracted by the backbone.
| forward | python | open-mmlab/mmaction2 | mmaction/models/backbones/c2d.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/c2d.py | Apache-2.0 |
def init_weights(self):
"""Initiate the parameters either from existing checkpoint or from
scratch."""
if isinstance(self.pretrained, str):
logger = MMLogger.get_current_instance()
logger.info(f'load model from: {self.pretrained}')
load_checkpoint(self, self.... | Initiate the parameters either from existing checkpoint or from
scratch. | init_weights | python | open-mmlab/mmaction2 | mmaction/models/backbones/c3d.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/c3d.py | Apache-2.0 |
def forward(self, x):
"""Defines the computation performed at every call.
Args:
x (torch.Tensor): The input data.
the size of x is (num_batches, 3, 16, 112, 112).
Returns:
torch.Tensor: The feature of the input
samples extracted by the backbo... | Defines the computation performed at every call.
Args:
x (torch.Tensor): The input data.
the size of x is (num_batches, 3, 16, 112, 112).
Returns:
torch.Tensor: The feature of the input
samples extracted by the backbone.
| forward | python | open-mmlab/mmaction2 | mmaction/models/backbones/c3d.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/c3d.py | Apache-2.0 |
def make_divisible(value, divisor, min_value=None, min_ratio=0.9):
"""Make divisible function.
This function rounds the channel number down to the nearest value that can
be divisible by the divisor.
Args:
value (int): The original channel number.
divisor (int): The divisor to fully divi... | Make divisible function.
This function rounds the channel number down to the nearest value that can
be divisible by the divisor.
Args:
value (int): The original channel number.
divisor (int): The divisor to fully divide the channel number.
min_value (int, optional): The minimum valu... | make_divisible | python | open-mmlab/mmaction2 | mmaction/models/backbones/mobilenet_v2.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/mobilenet_v2.py | Apache-2.0 |
def forward(self, x):
"""Defines the computation performed at every call.
Args:
x (Tensor): The input data.
Returns:
Tensor: The output of the module.
"""
def _inner_forward(x):
if self.use_res_connect:
return x + self.conv(x... | Defines the computation performed at every call.
Args:
x (Tensor): The input data.
Returns:
Tensor: The output of the module.
| forward | python | open-mmlab/mmaction2 | mmaction/models/backbones/mobilenet_v2.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/mobilenet_v2.py | Apache-2.0 |
def make_layer(self, out_channels, num_blocks, stride, expand_ratio):
"""Stack InvertedResidual blocks to build a layer for MobileNetV2.
Args:
out_channels (int): out_channels of block.
num_blocks (int): number of blocks.
stride (int): stride of the first block. Defa... | Stack InvertedResidual blocks to build a layer for MobileNetV2.
Args:
out_channels (int): out_channels of block.
num_blocks (int): number of blocks.
stride (int): stride of the first block. Defaults to 1
expand_ratio (int): Expand the number of channels of the
... | make_layer | python | open-mmlab/mmaction2 | mmaction/models/backbones/mobilenet_v2.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/mobilenet_v2.py | Apache-2.0 |
def forward(self, x):
"""Defines the computation performed at every call.
Args:
x (Tensor): The input data.
Returns:
Tensor or Tuple[Tensor]: The feature of the input samples extracted
by the backbone.
"""
x = self.conv1(x)
outs = []... | Defines the computation performed at every call.
Args:
x (Tensor): The input data.
Returns:
Tensor or Tuple[Tensor]: The feature of the input samples extracted
by the backbone.
| forward | python | open-mmlab/mmaction2 | mmaction/models/backbones/mobilenet_v2.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/mobilenet_v2.py | Apache-2.0 |
def _freeze_stages(self):
"""Prevent all the parameters from being optimized before
``self.frozen_stages``."""
if self.frozen_stages >= 0:
self.conv1.eval()
for param in self.conv1.parameters():
param.requires_grad = False
for i in range(1, self.fr... | Prevent all the parameters from being optimized before
``self.frozen_stages``. | _freeze_stages | python | open-mmlab/mmaction2 | mmaction/models/backbones/mobilenet_v2.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/mobilenet_v2.py | Apache-2.0 |
def train(self, mode=True):
"""Set the optimization status when training."""
super(MobileNetV2, self).train(mode)
self._freeze_stages()
if mode and self.norm_eval:
for m in self.modules():
if isinstance(m, _BatchNorm):
m.eval() | Set the optimization status when training. | train | python | open-mmlab/mmaction2 | mmaction/models/backbones/mobilenet_v2.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/mobilenet_v2.py | Apache-2.0 |
def make_temporal_shift(self):
"""Make temporal shift for some layers."""
for m in self.modules():
if isinstance(m, InvertedResidual) and \
len(m.conv) == 3 and m.use_res_connect:
m.conv[0] = TemporalShift(
m.conv[0],
... | Make temporal shift for some layers. | make_temporal_shift | python | open-mmlab/mmaction2 | mmaction/models/backbones/mobilenet_v2_tsm.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/mobilenet_v2_tsm.py | Apache-2.0 |
def init_weights(self):
"""Initiate the parameters either from existing checkpoint or from
scratch."""
if self.pretrained2d:
logger = MMLogger.get_current_instance()
self.load_original_weights(logger)
else:
if self.pretrained:
self.init... | Initiate the parameters either from existing checkpoint or from
scratch. | init_weights | python | open-mmlab/mmaction2 | mmaction/models/backbones/mobilenet_v2_tsm.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/mobilenet_v2_tsm.py | Apache-2.0 |
def make_temporal_shift(self):
"""Make temporal shift for some layers.
To make reparameterization work, we can only build the shift layer
before the 'block', instead of the 'blockres'
"""
def make_block_temporal(stage, num_segments):
"""Make temporal shift on some b... | Make temporal shift for some layers.
To make reparameterization work, we can only build the shift layer
before the 'block', instead of the 'blockres'
| make_temporal_shift | python | open-mmlab/mmaction2 | mmaction/models/backbones/mobileone_tsm.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/mobileone_tsm.py | Apache-2.0 |
def make_block_temporal(stage, num_segments):
"""Make temporal shift on some blocks.
Args:
stage (nn.Module): Model layers to be shifted.
num_segments (int): Number of frame segments.
Returns:
nn.Module: The shifted blocks.
... | Make temporal shift on some blocks.
Args:
stage (nn.Module): Model layers to be shifted.
num_segments (int): Number of frame segments.
Returns:
nn.Module: The shifted blocks.
| make_block_temporal | python | open-mmlab/mmaction2 | mmaction/models/backbones/mobileone_tsm.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/mobileone_tsm.py | Apache-2.0 |
def init_weights(self):
"""Initiate the parameters either from existing checkpoint or from
scratch."""
if self.pretrained2d:
logger = MMLogger.get_current_instance()
self.load_original_weights(logger)
else:
super().init_weights() | Initiate the parameters either from existing checkpoint or from
scratch. | init_weights | python | open-mmlab/mmaction2 | mmaction/models/backbones/mobileone_tsm.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/mobileone_tsm.py | Apache-2.0 |
def resize_pos_embed(pos_embed: torch.Tensor,
src_shape: Tuple[int],
dst_shape: Tuple[int],
mode: str = 'trilinear',
num_extra_tokens: int = 1) -> torch.Tensor:
"""Resize pos_embed weights.
Args:
pos_embed (torch.Tensor... | Resize pos_embed weights.
Args:
pos_embed (torch.Tensor): Position embedding weights with shape
[1, L, C].
src_shape (tuple): The resolution of downsampled origin training
image, in format (T, H, W).
dst_shape (tuple): The resolution of downsampled new training
... | resize_pos_embed | python | open-mmlab/mmaction2 | mmaction/models/backbones/mvit.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/mvit.py | Apache-2.0 |
def resize_decomposed_rel_pos(rel_pos: torch.Tensor, q_size: int,
k_size: int) -> torch.Tensor:
"""Get relative positional embeddings according to the relative positions
of query and key sizes.
Args:
rel_pos (Tensor): relative position embeddings (L, C).
q_size... | Get relative positional embeddings according to the relative positions
of query and key sizes.
Args:
rel_pos (Tensor): relative position embeddings (L, C).
q_size (int): size of query q.
k_size (int): size of key k.
Returns:
Extracted positional embeddings according to rela... | resize_decomposed_rel_pos | python | open-mmlab/mmaction2 | mmaction/models/backbones/mvit.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/mvit.py | Apache-2.0 |
def attention_pool(x: torch.Tensor,
pool: nn.Module,
in_size: Tuple[int],
with_cls_token: bool = False,
norm: Optional[nn.Module] = None) -> tuple:
"""Pooling the feature tokens.
Args:
x (torch.Tensor): The input tensor, should... | Pooling the feature tokens.
Args:
x (torch.Tensor): The input tensor, should be with shape
``(B, num_heads, L, C)`` or ``(B, L, C)``.
pool (nn.Module): The pooling module.
in_size (Tuple[int]): The shape of the input feature map.
with_cls_token (bool): Whether concatenat... | attention_pool | python | open-mmlab/mmaction2 | mmaction/models/backbones/mvit.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/mvit.py | Apache-2.0 |
def forward(self, x: torch.Tensor) -> torch.Tensor:
"""Defines the computation performed at every call.
Args:
x (torch.Tensor): The input data.
Returns:
torch.Tensor: The output of the module.
"""
identity = x
out = self.conv1(x)
out = s... | Defines the computation performed at every call.
Args:
x (torch.Tensor): The input data.
Returns:
torch.Tensor: The output of the module.
| forward | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet.py | Apache-2.0 |
def forward(self, x: torch.Tensor) -> torch.Tensor:
"""Defines the computation performed at every call.
Args:
x (torch.Tensor): The input data.
Returns:
torch.Tensor: The output of the module.
"""
def _inner_forward(x):
"""Forward wrapper fo... | Defines the computation performed at every call.
Args:
x (torch.Tensor): The input data.
Returns:
torch.Tensor: The output of the module.
| forward | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet.py | Apache-2.0 |
def make_res_layer(block: nn.Module,
inplanes: int,
planes: int,
blocks: int,
stride: int = 1,
dilation: int = 1,
style: str = 'pytorch',
conv_cfg: Optional[ConfigType] = None,
... | Build residual layer for ResNet.
Args:
block: (nn.Module): Residual module to be built.
inplanes (int): Number of channels for the input feature in each block.
planes (int): Number of channels for the output feature in each block.
blocks (int): Number of residual blocks.
str... | make_res_layer | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet.py | Apache-2.0 |
def _make_stem_layer(self) -> None:
"""Construct the stem layers consists of a conv+norm+act module and a
pooling layer."""
self.conv1 = ConvModule(
self.in_channels,
64,
kernel_size=7,
stride=2,
padding=3,
bias=False,
... | Construct the stem layers consists of a conv+norm+act module and a
pooling layer. | _make_stem_layer | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet.py | Apache-2.0 |
def _load_conv_params(conv: nn.Module, state_dict_tv: OrderedDict,
module_name_tv: str,
loaded_param_names: List[str]) -> None:
"""Load the conv parameters of resnet from torchvision.
Args:
conv (nn.Module): The destination conv module.
... | Load the conv parameters of resnet from torchvision.
Args:
conv (nn.Module): The destination conv module.
state_dict_tv (OrderedDict): The state dict of pretrained
torchvision model.
module_name_tv (str): The name of corresponding conv module in the
... | _load_conv_params | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet.py | Apache-2.0 |
def _load_bn_params(bn: nn.Module, state_dict_tv: OrderedDict,
module_name_tv: str,
loaded_param_names: List[str]) -> None:
"""Load the bn parameters of resnet from torchvision.
Args:
bn (nn.Module): The destination bn module.
stat... | Load the bn parameters of resnet from torchvision.
Args:
bn (nn.Module): The destination bn module.
state_dict_tv (OrderedDict): The state dict of pretrained
torchvision model.
module_name_tv (str): The name of corresponding bn module in the
t... | _load_bn_params | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet.py | Apache-2.0 |
def _load_torchvision_checkpoint(self,
logger: mmengine.MMLogger = None) -> None:
"""Initiate the parameters from torchvision pretrained checkpoint."""
state_dict_torchvision = _load_checkpoint(
self.pretrained, map_location='cpu')
if 'state_dict'... | Initiate the parameters from torchvision pretrained checkpoint. | _load_torchvision_checkpoint | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet.py | Apache-2.0 |
def init_weights(self) -> None:
"""Initiate the parameters either from existing checkpoint or from
scratch."""
if isinstance(self.pretrained, str):
logger = MMLogger.get_current_instance()
if self.torchvision_pretrain:
# torchvision's
self.... | Initiate the parameters either from existing checkpoint or from
scratch. | init_weights | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet.py | Apache-2.0 |
def forward(self, x: torch.Tensor) \
-> Union[torch.Tensor, Tuple[torch.Tensor]]:
"""Defines the computation performed at every call.
Args:
x (torch.Tensor): The input data.
Returns:
Union[torch.Tensor or Tuple[torch.Tensor]]: The feature of the
... | Defines the computation performed at every call.
Args:
x (torch.Tensor): The input data.
Returns:
Union[torch.Tensor or Tuple[torch.Tensor]]: The feature of the
input samples extracted by the backbone.
| forward | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet.py | Apache-2.0 |
def _freeze_stages(self) -> None:
"""Prevent all the parameters from being optimized before
``self.frozen_stages``."""
if self.frozen_stages >= 0:
self.conv1.bn.eval()
for m in self.conv1.modules():
for param in m.parameters():
param.re... | Prevent all the parameters from being optimized before
``self.frozen_stages``. | _freeze_stages | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet.py | Apache-2.0 |
def train(self, mode: bool = True) -> None:
"""Set the optimization status when training."""
super().train(mode)
self._freeze_stages()
if mode and self.norm_eval:
for m in self.modules():
if isinstance(m, _BatchNorm):
m.eval()
if mo... | Set the optimization status when training. | train | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet.py | Apache-2.0 |
def _freeze_stages(self):
"""Prevent all the parameters from being optimized before
``self.frozen_stages``."""
if self.frozen_stages >= 0:
self.conv1.eval()
for param in self.conv1.parameters():
param.requires_grad = False
for i in range(1, self.f... | Prevent all the parameters from being optimized before
``self.frozen_stages``. | _freeze_stages | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet2plus1d.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet2plus1d.py | Apache-2.0 |
def forward(self, x):
"""Defines the computation performed at every call.
Args:
x (torch.Tensor): The input data.
Returns:
torch.Tensor: The feature of the input
samples extracted by the backbone.
"""
x = self.conv1(x)
x = self.maxpoo... | Defines the computation performed at every call.
Args:
x (torch.Tensor): The input data.
Returns:
torch.Tensor: The feature of the input
samples extracted by the backbone.
| forward | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet2plus1d.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet2plus1d.py | Apache-2.0 |
def forward(self, x: torch.Tensor) -> torch.Tensor:
"""Defines the computation performed at every call."""
def _inner_forward(x):
"""Forward wrapper for utilizing checkpoint."""
identity = x
out = self.conv1(x)
out = self.conv2(out)
if self.... | Defines the computation performed at every call. | forward | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet3d.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet3d.py | Apache-2.0 |
def forward(self, x: torch.Tensor) -> torch.Tensor:
"""Defines the computation performed at every call."""
def _inner_forward(x):
"""Forward wrapper for utilizing checkpoint."""
identity = x
out = self.conv1(x)
out = self.conv2(out)
out = sel... | Defines the computation performed at every call. | forward | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet3d.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet3d.py | Apache-2.0 |
def make_res_layer(block: nn.Module,
inplanes: int,
planes: int,
blocks: int,
spatial_stride: Union[int, Sequence[int]] = 1,
temporal_stride: Union[int, Sequence[int]] = 1,
dilation:... | Build residual layer for ResNet3D.
Args:
block (nn.Module): Residual module to be built.
inplanes (int): Number of channels for the input feature
in each block.
planes (int): Number of channels for the output feature
in each block.
... | make_res_layer | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet3d.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet3d.py | Apache-2.0 |
def _inflate_conv_params(conv3d: nn.Module, state_dict_2d: OrderedDict,
module_name_2d: str,
inflated_param_names: List[str]) -> None:
"""Inflate a conv module from 2d to 3d.
Args:
conv3d (nn.Module): The destination conv3d module.
... | Inflate a conv module from 2d to 3d.
Args:
conv3d (nn.Module): The destination conv3d module.
state_dict_2d (OrderedDict): The state dict of pretrained 2d model.
module_name_2d (str): The name of corresponding conv module in the
2d model.
inflated... | _inflate_conv_params | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet3d.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet3d.py | Apache-2.0 |
def _inflate_bn_params(bn3d: nn.Module, state_dict_2d: OrderedDict,
module_name_2d: str,
inflated_param_names: List[str]) -> None:
"""Inflate a norm module from 2d to 3d.
Args:
bn3d (nn.Module): The destination bn3d module.
s... | Inflate a norm module from 2d to 3d.
Args:
bn3d (nn.Module): The destination bn3d module.
state_dict_2d (OrderedDict): The state dict of pretrained 2d model.
module_name_2d (str): The name of corresponding bn module in the
2d model.
inflated_param... | _inflate_bn_params | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet3d.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet3d.py | Apache-2.0 |
def _inflate_weights(self, logger: MMLogger) -> None:
"""Inflate the resnet2d parameters to resnet3d.
The differences between resnet3d and resnet2d mainly lie in an extra
axis of conv kernel. To utilize the pretrained parameters in 2d model,
the weight of conv2d models should be inflate... | Inflate the resnet2d parameters to resnet3d.
The differences between resnet3d and resnet2d mainly lie in an extra
axis of conv kernel. To utilize the pretrained parameters in 2d model,
the weight of conv2d models should be inflated to fit in the shapes of
the 3d counterpart.
Ar... | _inflate_weights | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet3d.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet3d.py | Apache-2.0 |
def _make_stem_layer(self) -> None:
"""Construct the stem layers consists of a conv+norm+act module and a
pooling layer."""
self.conv1 = ConvModule(
self.in_channels,
self.base_channels,
kernel_size=self.conv1_kernel,
stride=(self.conv1_stride_t, s... | Construct the stem layers consists of a conv+norm+act module and a
pooling layer. | _make_stem_layer | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet3d.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet3d.py | Apache-2.0 |
def _freeze_stages(self) -> None:
"""Prevent all the parameters from being optimized before
``self.frozen_stages``."""
if self.frozen_stages >= 0:
self.conv1.eval()
for param in self.conv1.parameters():
param.requires_grad = False
for i in range(1... | Prevent all the parameters from being optimized before
``self.frozen_stages``. | _freeze_stages | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet3d.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet3d.py | Apache-2.0 |
def _init_weights(self, pretrained: Optional[str] = None) -> None:
"""Initiate the parameters either from existing checkpoint or from
scratch.
Args:
pretrained (str | None): The path of the pretrained weight. Will
override the original `pretrained` if set. The arg is... | Initiate the parameters either from existing checkpoint or from
scratch.
Args:
pretrained (str | None): The path of the pretrained weight. Will
override the original `pretrained` if set. The arg is added to
be compatible with mmdet. Defaults to None.
| _init_weights | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet3d.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet3d.py | Apache-2.0 |
def forward(self, x: torch.Tensor) \
-> Union[torch.Tensor, Tuple[torch.Tensor]]:
"""Defines the computation performed at every call.
Args:
x (torch.Tensor): The input data.
Returns:
torch.Tensor or tuple[torch.Tensor]: The feature of the input
s... | Defines the computation performed at every call.
Args:
x (torch.Tensor): The input data.
Returns:
torch.Tensor or tuple[torch.Tensor]: The feature of the input
samples extracted by the backbone.
| forward | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet3d.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet3d.py | Apache-2.0 |
def train(self, mode: bool = True) -> None:
"""Set the optimization status when training."""
super().train(mode)
self._freeze_stages()
if mode and self.norm_eval:
for m in self.modules():
if isinstance(m, _BatchNorm):
m.eval() | Set the optimization status when training. | train | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet3d.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet3d.py | Apache-2.0 |
def _freeze_stages(self) -> None:
"""Prevent all the parameters from being optimized before
``self.frozen_stages``."""
if self.all_frozen:
layer = getattr(self, self.layer_name)
layer.eval()
for param in layer.parameters():
param.requires_grad ... | Prevent all the parameters from being optimized before
``self.frozen_stages``. | _freeze_stages | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet3d.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet3d.py | Apache-2.0 |
def forward(self, x: torch.Tensor) -> torch.Tensor:
"""Defines the computation performed at every call.
Args:
x (torch.Tensor): The input data.
Returns:
torch.Tensor: The feature of the input
samples extracted by the residual layer.
"""
r... | Defines the computation performed at every call.
Args:
x (torch.Tensor): The input data.
Returns:
torch.Tensor: The feature of the input
samples extracted by the residual layer.
| forward | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet3d.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet3d.py | Apache-2.0 |
def train(self, mode: bool = True) -> None:
"""Set the optimization status when training."""
super().train(mode)
self._freeze_stages()
if mode and self.norm_eval:
for m in self.modules():
if isinstance(m, _BatchNorm):
m.eval() | Set the optimization status when training. | train | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet3d.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet3d.py | Apache-2.0 |
def train(self, mode=True):
"""Set the optimization status when training."""
super(ResNet3d, self).train(mode)
self._freeze_stages()
if mode and self.norm_eval:
for m in self.modules():
if isinstance(m, _BatchNorm):
m.eval()
... | Set the optimization status when training. | train | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet3d_csn.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet3d_csn.py | Apache-2.0 |
def forward(self, x: torch.Tensor) -> torch.Tensor:
"""Defines the computation performed at every call."""
# x should be a 5-d tensor
assert len(x.shape) == 5
N, C, T, H, W = x.shape
out_shape = (N, self.out_channels, self.stride[0] * T,
self.stride[1] * H, s... | Defines the computation performed at every call. | forward | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet3d_slowfast.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet3d_slowfast.py | Apache-2.0 |
def inflate_weights(self, logger: MMLogger) -> None:
"""Inflate the resnet2d parameters to resnet3d pathway.
The differences between resnet3d and resnet2d mainly lie in an extra
axis of conv kernel. To utilize the pretrained parameters in 2d model,
the weight of conv2d models should be ... | Inflate the resnet2d parameters to resnet3d pathway.
The differences between resnet3d and resnet2d mainly lie in an extra
axis of conv kernel. To utilize the pretrained parameters in 2d model,
the weight of conv2d models should be inflated to fit in the shapes of
the 3d counterpart. For... | inflate_weights | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet3d_slowfast.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet3d_slowfast.py | Apache-2.0 |
def _inflate_conv_params(self, conv3d: nn.Module,
state_dict_2d: OrderedDict, module_name_2d: str,
inflated_param_names: List[str]) -> None:
"""Inflate a conv module from 2d to 3d.
The differences of conv modules betweene 2d and 3d in Pathway
... | Inflate a conv module from 2d to 3d.
The differences of conv modules betweene 2d and 3d in Pathway
mainly lie in the inplanes due to lateral connections. To fit the
shapes of the lateral connection counterpart, it will expand
parameters by concatting conv2d parameters and extra zero pad... | _inflate_conv_params | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet3d_slowfast.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet3d_slowfast.py | Apache-2.0 |
def _freeze_stages(self) -> None:
"""Prevent all the parameters from being optimized before
`self.frozen_stages`."""
if self.frozen_stages >= 0:
self.conv1.eval()
for param in self.conv1.parameters():
param.requires_grad = False
for i in range(1, ... | Prevent all the parameters from being optimized before
`self.frozen_stages`. | _freeze_stages | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet3d_slowfast.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet3d_slowfast.py | Apache-2.0 |
def init_weights(self, pretrained: Optional[str] = None) -> None:
"""Initiate the parameters either from existing checkpoint or from
scratch."""
if pretrained:
self.pretrained = pretrained
# Override the init_weights of i3d
super().init_weights()
for module_n... | Initiate the parameters either from existing checkpoint or from
scratch. | init_weights | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet3d_slowfast.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet3d_slowfast.py | Apache-2.0 |
def build_pathway(cfg: Dict, *args, **kwargs) -> nn.Module:
"""Build pathway.
Args:
cfg (dict): cfg should contain:
- type (str): identify backbone type.
Returns:
nn.Module: Created pathway.
"""
if not (isinstance(cfg, dict) and 'type' in cfg):
raise TypeError('... | Build pathway.
Args:
cfg (dict): cfg should contain:
- type (str): identify backbone type.
Returns:
nn.Module: Created pathway.
| build_pathway | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet3d_slowfast.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet3d_slowfast.py | Apache-2.0 |
def init_weights(self, pretrained: Optional[str] = None) -> None:
"""Initiate the parameters either from existing checkpoint or from
scratch."""
if pretrained:
self.pretrained = pretrained
if isinstance(self.pretrained, str):
logger = MMLogger.get_current_instanc... | Initiate the parameters either from existing checkpoint or from
scratch. | init_weights | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet3d_slowfast.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet3d_slowfast.py | Apache-2.0 |
def forward(self, x: torch.Tensor) -> tuple:
"""Defines the computation performed at every call.
Args:
x (torch.Tensor): The input data.
Returns:
tuple[torch.Tensor]: The feature of the input samples
extracted by the backbone.
"""
x_slow ... | Defines the computation performed at every call.
Args:
x (torch.Tensor): The input data.
Returns:
tuple[torch.Tensor]: The feature of the input samples
extracted by the backbone.
| forward | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet3d_slowfast.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet3d_slowfast.py | Apache-2.0 |
def forward(self, x: torch.Tensor) -> torch.Tensor:
"""Defines the computation performed at every call.
Args:
x (torch.Tensor): The input data.
Returns:
torch.Tensor: The output of the module.
"""
def _inner_forward(x):
identity = x
... | Defines the computation performed at every call.
Args:
x (torch.Tensor): The input data.
Returns:
torch.Tensor: The output of the module.
| forward | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet_audio.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet_audio.py | Apache-2.0 |
def make_res_layer(block: nn.Module,
inplanes: int,
planes: int,
blocks: int,
stride: int = 1,
dilation: int = 1,
factorize: int = 1,
norm_cfg: Optional[Config... | Build residual layer for ResNetAudio.
Args:
block (nn.Module): Residual module to be built.
inplanes (int): Number of channels for the input feature
in each block.
planes (int): Number of channels for the output feature
in each block.
... | make_res_layer | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet_audio.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet_audio.py | Apache-2.0 |
def _make_stem_layer(self) -> None:
"""Construct the stem layers consists of a ``conv+norm+act`` module and
a pooling layer."""
self.conv1 = ConvModule(
self.in_channels,
self.base_channels,
kernel_size=self.conv1_kernel,
stride=self.conv1_stride,
... | Construct the stem layers consists of a ``conv+norm+act`` module and
a pooling layer. | _make_stem_layer | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet_audio.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet_audio.py | Apache-2.0 |
def _freeze_stages(self) -> None:
"""Prevent all the parameters from being optimized before
``self.frozen_stages``."""
if self.frozen_stages >= 0:
self.conv1.bn.eval()
for m in [self.conv1.conv, self.conv1.bn]:
for param in m.parameters():
... | Prevent all the parameters from being optimized before
``self.frozen_stages``. | _freeze_stages | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet_audio.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet_audio.py | Apache-2.0 |
def init_weights(self) -> None:
"""Initiate the parameters either from existing checkpoint or from
scratch."""
if isinstance(self.pretrained, str):
logger = MMLogger.get_current_instance()
logger.info(f'load model from: {self.pretrained}')
load_checkpoint(sel... | Initiate the parameters either from existing checkpoint or from
scratch. | init_weights | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet_audio.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet_audio.py | Apache-2.0 |
def forward(self, x: torch.Tensor) -> torch.Tensor:
"""Defines the computation performed at every call.
Args:
x (torch.Tensor): The input data.
Returns:
torch.Tensor: The feature of the input samples extracted
by the backbone.
"""
x = sel... | Defines the computation performed at every call.
Args:
x (torch.Tensor): The input data.
Returns:
torch.Tensor: The feature of the input samples extracted
by the backbone.
| forward | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet_audio.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet_audio.py | Apache-2.0 |
def train(self, mode: bool = True) -> None:
"""Set the optimization status when training."""
super().train(mode)
self._freeze_stages()
if mode and self.norm_eval:
for m in self.modules():
if isinstance(m, _BatchNorm):
m.eval() | Set the optimization status when training. | train | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet_audio.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet_audio.py | Apache-2.0 |
def batch_norm(inputs: torch.Tensor,
module: nn.modules.batchnorm,
training: Optional[bool] = None) -> torch.Tensor:
"""Applies Batch Normalization for each channel across a batch of data
using params from the given batch normalization module.
Args:
inputs (Tensor): Th... | Applies Batch Normalization for each channel across a batch of data
using params from the given batch normalization module.
Args:
inputs (Tensor): The input data.
module (nn.modules.batchnorm): a batch normalization module. Will use
params from this batch normalization module to do ... | batch_norm | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet_omni.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet_omni.py | Apache-2.0 |
def forward(self, x: torch.Tensor) -> torch.Tensor:
"""Defines the computation performed at every call.
Accept both 3D (BCTHW for videos) and 2D (BCHW for images) tensors.
"""
if x.ndim == 4:
return self.forward_2d(x)
# Forward call for 3D tensors.
out = sel... | Defines the computation performed at every call.
Accept both 3D (BCTHW for videos) and 2D (BCHW for images) tensors.
| forward | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet_omni.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet_omni.py | Apache-2.0 |
def forward(self, x: torch.Tensor) -> torch.Tensor:
"""Defines the computation performed at every call.
Accept both 3D (BCTHW for videos) and 2D (BCHW for images) tensors.
"""
if x.ndim == 4:
return self.forward_2d(x)
# Forward call for 3D tensors.
x = self.... | Defines the computation performed at every call.
Accept both 3D (BCTHW for videos) and 2D (BCHW for images) tensors.
| forward | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet_omni.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet_omni.py | Apache-2.0 |
def linear_sampler(data, offset):
"""Differentiable Temporal-wise Frame Sampling, which is essentially a
linear interpolation process.
It gets the feature map which has been split into several groups
and shift them by different offsets according to their groups.
Then compute the weighted sum along ... | Differentiable Temporal-wise Frame Sampling, which is essentially a
linear interpolation process.
It gets the feature map which has been split into several groups
and shift them by different offsets according to their groups.
Then compute the weighted sum along with the temporal dimension.
Args:
... | linear_sampler | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet_tin.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet_tin.py | Apache-2.0 |
def forward(self, x):
"""Defines the computation performed at every call.
Args:
x (torch.Tensor): The input data.
Returns:
torch.Tensor: The output of the module.
"""
# input shape: [num_batches * num_segments, C, H, W]
# output x shape: [num_bat... | Defines the computation performed at every call.
Args:
x (torch.Tensor): The input data.
Returns:
torch.Tensor: The output of the module.
| forward | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet_tin.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet_tin.py | Apache-2.0 |
def init_weights(self):
"""Initiate the parameters either from existing checkpoint or from
scratch."""
# we set the initial bias of the convolution
# layer to 0, and the final initial output will be 1.0
self.conv.bias.data[...] = 0 | Initiate the parameters either from existing checkpoint or from
scratch. | init_weights | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet_tin.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet_tin.py | Apache-2.0 |
def forward(self, x):
"""Defines the computation performed at every call.
Args:
x (torch.Tensor): The input data.
Returns:
torch.Tensor: The output of the module.
"""
# calculate weight
# [N, C, T]
n, _, t = x.shape
# [N, groups, ... | Defines the computation performed at every call.
Args:
x (torch.Tensor): The input data.
Returns:
torch.Tensor: The output of the module.
| forward | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet_tin.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet_tin.py | Apache-2.0 |
def init_weights(self):
"""Initiate the parameters either from existing checkpoint or from
scratch."""
# The bias of the last fc layer is initialized to
# make the post-sigmoid output start from 1
self.fc2.bias.data[...] = 0.5108 | Initiate the parameters either from existing checkpoint or from
scratch. | init_weights | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet_tin.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet_tin.py | Apache-2.0 |
def forward(self, x):
"""Defines the computation performed at every call.
Args:
x (torch.Tensor): The input data.
Returns:
torch.Tensor: The output of the module.
"""
# calculate offset
# [N, C, T]
n, _, t = x.shape
# [N, 1, T]
... | Defines the computation performed at every call.
Args:
x (torch.Tensor): The input data.
Returns:
torch.Tensor: The output of the module.
| forward | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet_tin.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet_tin.py | Apache-2.0 |
def forward(self, x):
"""Defines the computation performed at every call.
Args:
x (torch.Tensor): The input data.
Returns:
torch.Tensor: The output of the module.
"""
# x: [N, C, H, W],
# where N = num_batches x num_segments, C = shift_div * num_... | Defines the computation performed at every call.
Args:
x (torch.Tensor): The input data.
Returns:
torch.Tensor: The output of the module.
| forward | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet_tin.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet_tin.py | Apache-2.0 |
def make_temporal_interlace(self):
"""Make temporal interlace for some layers."""
num_segment_list = [self.num_segments] * 4
assert num_segment_list[-1] > 0
n_round = 1
if len(list(self.layer3.children())) >= 23:
print(f'=> Using n_round {n_round} to insert temporal ... | Make temporal interlace for some layers. | make_temporal_interlace | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet_tin.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet_tin.py | Apache-2.0 |
def make_block_interlace(stage, num_segments, shift_div):
"""Apply Deformable shift for a ResNet layer module.
Args:
stage (nn.module): A ResNet layer to be deformed.
num_segments (int): Number of frame segments.
shift_div (int): Number of divisio... | Apply Deformable shift for a ResNet layer module.
Args:
stage (nn.module): A ResNet layer to be deformed.
num_segments (int): Number of frame segments.
shift_div (int): Number of division parts for shift.
Returns:
nn.Sequential: A... | make_block_interlace | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet_tin.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet_tin.py | Apache-2.0 |
def forward(self, x):
"""Defines the computation performed at every call."""
x = self.block(x)
n, c, h, w = x.size()
x = x.view(n // self.num_segments, self.num_segments, c, h,
w).transpose(1, 2).contiguous()
x = self.non_local_block(x)
x = x.transpose... | Defines the computation performed at every call. | forward | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet_tsm.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet_tsm.py | Apache-2.0 |
def shift(x, num_segments, shift_div=3):
"""Perform temporal shift operation on the feature.
Args:
x (torch.Tensor): The input feature to be shifted.
num_segments (int): Number of frame segments.
shift_div (int): Number of divisions for shift. Default: 3.
Re... | Perform temporal shift operation on the feature.
Args:
x (torch.Tensor): The input feature to be shifted.
num_segments (int): Number of frame segments.
shift_div (int): Number of divisions for shift. Default: 3.
Returns:
torch.Tensor: The shifted feature... | shift | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet_tsm.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet_tsm.py | Apache-2.0 |
def make_temporal_shift(self):
"""Make temporal shift for some layers."""
if self.temporal_pool:
num_segment_list = [
self.num_segments, self.num_segments // 2,
self.num_segments // 2, self.num_segments // 2
]
else:
num_segment_... | Make temporal shift for some layers. | make_temporal_shift | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet_tsm.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet_tsm.py | Apache-2.0 |
def make_block_temporal(stage, num_segments):
"""Make temporal shift on some blocks.
Args:
stage (nn.Module): Model layers to be shifted.
num_segments (int): Number of frame segments.
Returns:
nn.Module: The sh... | Make temporal shift on some blocks.
Args:
stage (nn.Module): Model layers to be shifted.
num_segments (int): Number of frame segments.
Returns:
nn.Module: The shifted blocks.
| make_block_temporal | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet_tsm.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet_tsm.py | Apache-2.0 |
def make_block_temporal(stage, num_segments):
"""Make temporal shift on some blocks.
Args:
stage (nn.Module): Model layers to be shifted.
num_segments (int): Number of frame segments.
Returns:
nn.Module: The sh... | Make temporal shift on some blocks.
Args:
stage (nn.Module): Model layers to be shifted.
num_segments (int): Number of frame segments.
Returns:
nn.Module: The shifted blocks.
| make_block_temporal | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet_tsm.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet_tsm.py | Apache-2.0 |
def make_temporal_pool(self):
"""Make temporal pooling between layer1 and layer2, using a 3D max
pooling layer."""
class TemporalPool(nn.Module):
"""Temporal pool module.
Wrap layer2 in ResNet50 with a 3D max pooling layer.
Args:
net (nn.Mod... | Make temporal pooling between layer1 and layer2, using a 3D max
pooling layer. | make_temporal_pool | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet_tsm.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet_tsm.py | Apache-2.0 |
def forward(self, x):
"""Defines the computation performed at every call."""
# [N, C, H, W]
n, c, h, w = x.size()
# [N // num_segments, C, num_segments, H, W]
x = x.view(n // self.num_segments, self.num_segments, c, h,
... | Defines the computation performed at every call. | forward | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet_tsm.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet_tsm.py | Apache-2.0 |
def make_non_local(self):
"""Wrap resnet layer into non local wrapper."""
# This part is for ResNet50
for i in range(self.num_stages):
non_local_stage = self.non_local_stages[i]
if sum(non_local_stage) == 0:
continue
layer_name = f'layer{i + 1... | Wrap resnet layer into non local wrapper. | make_non_local | python | open-mmlab/mmaction2 | mmaction/models/backbones/resnet_tsm.py | https://github.com/open-mmlab/mmaction2/blob/master/mmaction/models/backbones/resnet_tsm.py | Apache-2.0 |
Subsets and Splits
Django Code with Docstrings
Filters Python code examples from Django repository that contain Django-related code, helping identify relevant code snippets for understanding Django framework usage patterns.
SQL Console for Shuu12121/python-treesitter-filtered-datasetsV2
Retrieves Python code examples from Django repository that contain 'django' in the code, which helps identify Django-specific code snippets but provides limited analytical insights beyond basic filtering.
SQL Console for Shuu12121/python-treesitter-filtered-datasetsV2
Retrieves specific code examples from the Flask repository but doesn't provide meaningful analysis or patterns beyond basic data retrieval.
HTTPX Repo Code and Docstrings
Retrieves specific code examples from the httpx repository, which is useful for understanding how particular libraries are used but doesn't provide broader analytical insights about the dataset.
Requests Repo Docstrings & Code
Retrieves code examples with their docstrings and file paths from the requests repository, providing basic filtering but limited analytical value beyond finding specific code samples.
Quart Repo Docstrings & Code
Retrieves code examples with their docstrings from the Quart repository, providing basic code samples but offering limited analytical value for understanding broader patterns or relationships in the dataset.