repo
stringlengths
7
90
file_url
stringlengths
81
315
file_path
stringlengths
4
228
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 14:38:15
2026-01-05 02:33:18
truncated
bool
2 classes
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/blur_pool.py
timm/layers/blur_pool.py
""" BlurPool layer inspired by - Kornia's Max_BlurPool2d - Making Convolutional Networks Shift-Invariant Again :cite:`zhang2019shiftinvar` Hacked together by Chris Ha and Ross Wightman """ from functools import partial from math import comb # Python 3.8 from typing import Callable, Optional, Type, Union import tor...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/ml_decoder.py
timm/layers/ml_decoder.py
from typing import Optional import torch from torch import nn from torch import nn, Tensor from torch.nn.modules.transformer import _get_activation_fn def add_ml_decoder_head(model): if hasattr(model, 'global_pool') and hasattr(model, 'fc'): # most CNN models, like Resnet50 model.global_pool = nn.Identi...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/inplace_abn.py
timm/layers/inplace_abn.py
import torch from torch import nn as nn try: from inplace_abn.functions import inplace_abn, inplace_abn_sync has_iabn = True except ImportError: has_iabn = False def inplace_abn(x, weight, bias, running_mean, running_var, training=True, momentum=0.1, eps=1e-05, activation="leaky_re...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/global_context.py
timm/layers/global_context.py
""" Global Context Attention Block Paper: `GCNet: Non-local Networks Meet Squeeze-Excitation Networks and Beyond` - https://arxiv.org/abs/1904.11492 Official code consulted as reference: https://github.com/xvjiarui/GCNet Hacked together by / Copyright 2021 Ross Wightman """ from typing import Optional, Tuple, Ty...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/pos_embed.py
timm/layers/pos_embed.py
""" Position Embedding Utilities Hacked together by / Copyright 2022 Ross Wightman """ import logging import math from typing import List, Tuple, Optional, Union import torch import torch.nn.functional as F from ._fx import register_notrace_function _logger = logging.getLogger(__name__) @torch.fx.wrap @register_n...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/cbam.py
timm/layers/cbam.py
""" CBAM (sort-of) Attention Experimental impl of CBAM: Convolutional Block Attention Module: https://arxiv.org/abs/1807.06521 WARNING: Results with these attention layers have been mixed. They can significantly reduce performance on some tasks, especially fine-grained it seems. I may end up removing this impl. Hack...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/cond_conv2d.py
timm/layers/cond_conv2d.py
""" PyTorch Conditionally Parameterized Convolution (CondConv) Paper: CondConv: Conditionally Parameterized Convolutions for Efficient Inference (https://arxiv.org/abs/1904.04971) Hacked together by / Copyright 2020 Ross Wightman """ import math from functools import partial from typing import Union, Tuple import t...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/layer_scale.py
timm/layers/layer_scale.py
import torch from torch import nn class LayerScale(nn.Module): """ LayerScale on tensors with channels in last-dim. """ def __init__( self, dim: int, init_values: float = 1e-5, inplace: bool = False, device=None, dtype=None, ) -> ...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/selective_kernel.py
timm/layers/selective_kernel.py
""" Selective Kernel Convolution/Attention Paper: Selective Kernel Networks (https://arxiv.org/abs/1903.06586) Hacked together by / Copyright 2020 Ross Wightman """ from typing import List, Optional, Tuple, Type, Union import torch from torch import nn as nn from .conv_bn_act import ConvNormAct from .helpers import...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/split_attn.py
timm/layers/split_attn.py
""" Split Attention Conv2d (for ResNeSt Models) Paper: `ResNeSt: Split-Attention Networks` - /https://arxiv.org/abs/2004.08955 Adapted from original PyTorch impl at https://github.com/zhanghang1989/ResNeSt Modified for torchscript compat, performance, and consistency with timm by Ross Wightman """ from typing import...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/helpers.py
timm/layers/helpers.py
""" Layer/Module Helpers Hacked together by / Copyright 2020 Ross Wightman """ from itertools import repeat import collections.abc # From PyTorch internals def _ntuple(n): """Return a function that converts input to an n-tuple. Scalar values are repeated n times, while iterables are converted to tuples. ...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/create_norm.py
timm/layers/create_norm.py
""" Norm Layer Factory Create norm modules by string (to mirror create_act and creat_norm-act fns) Copyright 2022 Ross Wightman """ import functools import types from typing import Type import torch.nn as nn from .norm import ( GroupNorm, GroupNorm1, LayerNorm, LayerNorm2d, LayerNormFp32, La...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/create_conv2d.py
timm/layers/create_conv2d.py
""" Create Conv2d Factory Method Hacked together by / Copyright 2020 Ross Wightman """ from .mixed_conv2d import MixedConv2d from .cond_conv2d import CondConv2d from .conv2d_same import create_conv2d_pad def create_conv2d(in_channels, out_channels, kernel_size, **kwargs): """ Select a 2d convolution implementat...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/space_to_depth.py
timm/layers/space_to_depth.py
import torch import torch.nn as nn class SpaceToDepth(nn.Module): """Rearrange spatial dimensions into channel dimension. Divides spatial dimensions by block_size and multiplies channels by block_size^2. Used in TResNet as an efficient stem operation. Args: block_size: Spatial reduction fact...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/conv2d_same.py
timm/layers/conv2d_same.py
""" Conv2d w/ Same Padding Hacked together by / Copyright 2020 Ross Wightman """ import torch import torch.nn as nn import torch.nn.functional as F from typing import Tuple, Optional, Union from ._fx import register_notrace_module from .config import is_exportable, is_scriptable from .padding import pad_same, pad_sam...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/lambda_layer.py
timm/layers/lambda_layer.py
""" Lambda Layer Paper: `LambdaNetworks: Modeling Long-Range Interactions Without Attention` - https://arxiv.org/abs/2102.08602 @misc{2102.08602, Author = {Irwan Bello}, Title = {LambdaNetworks: Modeling Long-Range Interactions Without Attention}, Year = {2021}, } Status: This impl is a WIP. Code snippets in the...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/separable_conv.py
timm/layers/separable_conv.py
""" Depthwise Separable Conv Modules Basic DWS convs. Other variations of DWS exist with batch norm or activations between the DW and PW convs such as the Depthwise modules in MobileNetV2 / EfficientNet and Xception. Hacked together by / Copyright 2020 Ross Wightman """ from typing import Optional, Type, Union from ...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/std_conv.py
timm/layers/std_conv.py
""" Convolution with Weight Standardization (StdConv and ScaledStdConv) StdConv: @article{weightstandardization, author = {Siyuan Qiao and Huiyu Wang and Chenxi Liu and Wei Shen and Alan Yuille}, title = {Weight Standardization}, journal = {arXiv preprint arXiv:1903.10520}, year = {2019}, } Code:...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/config.py
timm/layers/config.py
""" Model / Layer Config singleton state """ import os import warnings from typing import Any, Optional import torch __all__ = [ 'is_exportable', 'is_scriptable', 'is_no_jit', 'use_fused_attn', 'set_exportable', 'set_scriptable', 'set_no_jit', 'set_layer_config', 'set_fused_attn', 'set_reentrant_ckpt', 'u...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/create_attn.py
timm/layers/create_attn.py
""" Attention Factory Hacked together by / Copyright 2021 Ross Wightman """ import torch from functools import partial from .bottleneck_attn import BottleneckAttn from .cbam import CbamModule, LightCbamModule from .coord_attn import CoordAttn, EfficientLocalAttn, StripAttn, SimpleCoordAttn from .eca import EcaModule,...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/norm.py
timm/layers/norm.py
""" Normalization layers and wrappers Norm layer definitions that support fast norm and consistent channel arg order (always first arg). Hacked together by / Copyright 2022 Ross Wightman """ import numbers from typing import Tuple import torch import torch.nn as nn import torch.nn.functional as F from .fast_norm im...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/pool2d_same.py
timm/layers/pool2d_same.py
""" AvgPool2d w/ Same Padding Hacked together by / Copyright 2020 Ross Wightman """ import torch import torch.nn as nn import torch.nn.functional as F from typing import List, Tuple, Optional, Union from ._fx import register_notrace_module from .helpers import to_2tuple from .padding import pad_same, get_padding_valu...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/__init__.py
timm/layers/__init__.py
from ._fx import ( create_feature_extractor, get_graph_node_names, register_notrace_function, register_notrace_module, is_notrace_module, is_notrace_function, get_notrace_modules, get_notrace_functions, ) from .activations import * from .adaptive_avgmax_pool import ( adaptive_avgmax_...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/adaptive_avgmax_pool.py
timm/layers/adaptive_avgmax_pool.py
""" PyTorch selectable adaptive pooling Adaptive pooling with the ability to select the type of pooling from: * 'avg' - Average pooling * 'max' - Max pooling * 'avgmax' - Sum of average and max pooling re-scaled by 0.5 * 'avgmaxc' - Concatenation of average and max pooling along feature dim, doubles fea...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/attention.py
timm/layers/attention.py
from typing import Final, Optional, Type import torch from torch import nn as nn from torch.nn import functional as F from ._fx import register_notrace_function from .config import use_fused_attn from .pos_embed_sincos import apply_rot_embed_cat @torch.fx.wrap @register_notrace_function def maybe_add_mask(scores: t...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/grid.py
timm/layers/grid.py
from typing import Tuple import torch def ndgrid(*tensors) -> Tuple[torch.Tensor, ...]: """generate N-D grid in dimension order. The ndgrid function is like meshgrid except that the order of the first two input arguments are switched. That is, the statement [X1,X2,X3] = ndgrid(x1,x2,x3) produc...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/patch_embed.py
timm/layers/patch_embed.py
""" Image to Patch Embedding using Conv2d A convolution based approach to patchifying a 2D image w/ embedding projection. Based on code in: * https://github.com/google-research/vision_transformer * https://github.com/google-research/big_vision/tree/main/big_vision Hacked together by / Copyright 2020 Ross Wightma...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/_fx.py
timm/layers/_fx.py
from typing import Callable, Dict, List, Optional, Union, Tuple, Type import torch from torch import nn try: # NOTE we wrap torchvision fns to use timm leaf / no trace definitions from torchvision.models.feature_extraction import create_feature_extractor as _create_feature_extractor from torchvision.model...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/mixed_conv2d.py
timm/layers/mixed_conv2d.py
""" PyTorch Mixed Convolution Paper: MixConv: Mixed Depthwise Convolutional Kernels (https://arxiv.org/abs/1907.09595) Hacked together by / Copyright 2020 Ross Wightman """ from typing import List, Union import torch from torch import nn as nn from .conv2d_same import create_conv2d_pad def _split_channels(num_cha...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/coord_attn.py
timm/layers/coord_attn.py
""" Coordinate Attention and Variants Coordinate Attention decomposes channel attention into two 1D feature encoding processes to capture long-range dependencies with precise positional information. This module includes the original implementation along with simplified and other variants. Papers / References: - Coord...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/evo_norm.py
timm/layers/evo_norm.py
""" EvoNorm in PyTorch Based on `Evolving Normalization-Activation Layers` - https://arxiv.org/abs/2004.02967 @inproceedings{NEURIPS2020, author = {Liu, Hanxiao and Brock, Andy and Simonyan, Karen and Le, Quoc}, booktitle = {Advances in Neural Information Processing Systems}, editor = {H. Larochelle and M. Ranzato ...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/conv_bn_act.py
timm/layers/conv_bn_act.py
""" Conv2d + BN + Act Hacked together by / Copyright 2020 Ross Wightman """ from typing import Any, Dict, Optional, Type from torch import nn as nn from .typing import LayerType, PadType from .blur_pool import create_aa from .create_conv2d import create_conv2d from .create_norm_act import get_norm_act_layer class ...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/grn.py
timm/layers/grn.py
""" Global Response Normalization Module Based on the GRN layer presented in `ConvNeXt-V2 - Co-designing and Scaling ConvNets with Masked Autoencoders` - https://arxiv.org/abs/2301.00808 This implementation * works for both NCHW and NHWC tensor layouts * uses affine param names matching existing torch norm layers * s...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/linear.py
timm/layers/linear.py
""" Linear layer (alternate definition) """ import torch import torch.nn.functional as F from torch import nn as nn class Linear(nn.Linear): r"""Applies a linear transformation to the incoming data: :math:`y = xA^T + b` Wraps torch.nn.Linear to support AMP + torchscript usage by manually casting weight &...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/classifier.py
timm/layers/classifier.py
""" Classifier head and layer factory Hacked together by / Copyright 2020 Ross Wightman """ from collections import OrderedDict from functools import partial from typing import Optional, Union, Callable import torch import torch.nn as nn from torch.nn import functional as F from .adaptive_avgmax_pool import SelectAd...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/split_batchnorm.py
timm/layers/split_batchnorm.py
""" Split BatchNorm A PyTorch BatchNorm layer that splits input batch into N equal parts and passes each through a separate BN layer. The first split is passed through the parent BN layers with weight/bias keys the same as the original BN. All other splits pass through BN sub-layers under the '.aux_bn' namespace. Thi...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/activations.py
timm/layers/activations.py
""" Activations A collection of activations fn and modules with a common interface so that they can easily be swapped. All have an `inplace` arg even if not used. Hacked together by / Copyright 2020 Ross Wightman """ import torch from torch import nn as nn from torch.nn import functional as F def swish(x, inplace:...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/padding.py
timm/layers/padding.py
""" Padding Helpers Hacked together by / Copyright 2020 Ross Wightman """ import math from typing import List, Tuple, Union import torch import torch.nn.functional as F from .helpers import to_2tuple # Calculate symmetric padding for a convolution def get_padding(kernel_size: int, stride: int = 1, dilation: int = ...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/data/naflex_transforms.py
timm/data/naflex_transforms.py
""" NaFlex (NaViT + FlexiViT) Transforms and Collation Implements PyTorch versions of the transforms described in the NaViT and FlexiViT papers: - NaViT: https://arxiv.org/abs/2307.14995 - FlexiViT: https://arxiv.org/abs/2212.08013 Enables variable resolution/aspect ratio image handling with efficient patching. Hack...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/data/imagenet_info.py
timm/data/imagenet_info.py
import csv import os import pkgutil import re from typing import Dict, List, Optional, Union from .dataset_info import DatasetInfo # NOTE no ambiguity wrt to mapping from # classes to ImageNet subset so far, but likely to change _NUM_CLASSES_TO_SUBSET = { 1000: 'imagenet-1k', 11221: 'imagenet-21k-miil', # m...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/data/naflex_mixup.py
timm/data/naflex_mixup.py
"""Variable‑size Mixup / CutMix utilities for NaFlex data loaders. This module provides: * `mix_batch_variable_size` – pixel‑level Mixup/CutMix that operates on a list of images whose spatial sizes differ, mixing only their central overlap so no resizing is required. * `pairwise_mixup_target` – builds soft‑label ...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/data/distributed_sampler.py
timm/data/distributed_sampler.py
import math import torch from torch.utils.data import Sampler import torch.distributed as dist class OrderedDistributedSampler(Sampler): """Sampler that restricts data loading to a subset of the dataset. It is especially useful in conjunction with :class:`torch.nn.parallel.DistributedDataParallel`. In suc...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/data/real_labels.py
timm/data/real_labels.py
""" Real labels evaluator for ImageNet Paper: `Are we done with ImageNet?` - https://arxiv.org/abs/2006.07159 Based on Numpy example at https://github.com/google-research/reassessed-imagenet Hacked together by / Copyright 2020 Ross Wightman """ import os import json import numpy as np import pkgutil class RealLabels...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/data/auto_augment.py
timm/data/auto_augment.py
""" AutoAugment, RandAugment, AugMix, and 3-Augment for PyTorch This code implements the searched ImageNet policies with various tweaks and improvements and does not include any of the search code. AA and RA Implementation adapted from: https://github.com/tensorflow/tpu/blob/master/models/official/efficientnet/au...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
true
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/data/naflex_random_erasing.py
timm/data/naflex_random_erasing.py
"""Patch-level random erasing augmentation for NaFlex Vision Transformers. This module implements random erasing specifically designed for patchified images, operating at the patch granularity rather than pixel level. It supports two modes: - 'patch': Randomly erases individual patches (speckle-like noise) - 'region':...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/data/loader.py
timm/data/loader.py
""" Loader Factory, Fast Collate, CUDA Prefetcher Prefetcher and Fast Collate inspired by NVIDIA APEX example at https://github.com/NVIDIA/apex/commit/d5e2bb4bdeedd27b1dfaf5bb2b24d6c000dee9be#diff-cf86c282ff7fba81fad27a559379d5bf Hacked together by / Copyright 2019, Ross Wightman """ import logging import random from...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/data/constants.py
timm/data/constants.py
DEFAULT_CROP_PCT = 0.875 DEFAULT_CROP_MODE = 'center' IMAGENET_DEFAULT_MEAN = (0.485, 0.456, 0.406) IMAGENET_DEFAULT_STD = (0.229, 0.224, 0.225) IMAGENET_INCEPTION_MEAN = (0.5, 0.5, 0.5) IMAGENET_INCEPTION_STD = (0.5, 0.5, 0.5) IMAGENET_DPN_MEAN = (124 / 255, 117 / 255, 104 / 255) IMAGENET_DPN_STD = tuple([1 / (.0167 *...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/data/dataset.py
timm/data/dataset.py
""" Quick n Simple Image Folder, Tarfile based DataSet Hacked together by / Copyright 2019, Ross Wightman """ import io import logging from typing import Optional import torch import torch.utils.data as data from PIL import Image from .readers import create_reader _logger = logging.getLogger(__name__) _ERROR_RETR...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/data/dataset_info.py
timm/data/dataset_info.py
from abc import ABC, abstractmethod from typing import Dict, List, Optional, Union class DatasetInfo(ABC): def __init__(self): pass @abstractmethod def num_classes(self): pass @abstractmethod def label_names(self): pass @abstractmethod def label_descriptions(sel...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/data/transforms_factory.py
timm/data/transforms_factory.py
""" Transforms Factory Factory methods for building image transforms for use with TIMM (PyTorch Image Models) Hacked together by / Copyright 2019, Ross Wightman """ import math from typing import Optional, Tuple, Union import torch from torchvision import transforms from timm.data.constants import IMAGENET_DEFAULT_M...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/data/naflex_dataset.py
timm/data/naflex_dataset.py
""" Dynamic Sequence Length Datasets for Variable Resolution Image Processing Implements two dataset wrappers: 1. NaFlexMapDatasetWrapper - Map-style dataset that returns batches with variable sequence lengths TODO: 2. NaFlexIterableDatasetWrapper - Iterable dataset that yields batches with variable sequence lengths ...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/data/config.py
timm/data/config.py
import logging from .constants import * _logger = logging.getLogger(__name__) def resolve_data_config( args=None, pretrained_cfg=None, model=None, use_test_size=False, verbose=False ): assert model or args or pretrained_cfg, "At least one of model, args, or pretrained_cfg...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/data/__init__.py
timm/data/__init__.py
from .auto_augment import RandAugment, AutoAugment, rand_augment_ops, auto_augment_policy,\ rand_augment_transform, auto_augment_transform from .config import resolve_data_config, resolve_model_data_config from .constants import * from .dataset import ImageDataset, IterableImageDataset, AugMixDataset from .dataset_...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/data/naflex_loader.py
timm/data/naflex_loader.py
"""NaFlex data loader for dynamic sequence length training. This module provides a specialized data loader for Vision Transformer models that supports: - Dynamic sequence length sampling during training for improved efficiency - Variable patch size training with probabilistic selection - Patch-level random erasing aug...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/data/dataset_factory.py
timm/data/dataset_factory.py
""" Dataset Factory Hacked together by / Copyright 2021, Ross Wightman """ import os from typing import Optional from torchvision.datasets import CIFAR100, CIFAR10, MNIST, KMNIST, FashionMNIST, ImageFolder try: from torchvision.datasets import Places365 has_places365 = True except ImportError: has_places3...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/data/mixup.py
timm/data/mixup.py
""" Mixup and Cutmix Papers: mixup: Beyond Empirical Risk Minimization (https://arxiv.org/abs/1710.09412) CutMix: Regularization Strategy to Train Strong Classifiers with Localizable Features (https://arxiv.org/abs/1905.04899) Code Reference: CutMix: https://github.com/clovaai/CutMix-PyTorch Hacked together by / Co...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/data/random_erasing.py
timm/data/random_erasing.py
""" Random Erasing (Cutout) Originally inspired by impl at https://github.com/zhunzhong07/Random-Erasing, Apache 2.0 Copyright Zhun Zhong & Liang Zheng Hacked together by / Copyright 2019, Ross Wightman """ import random import math import torch def _get_pixels(per_pixel, rand_color, patch_size, dtype=torch.float3...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/data/transforms.py
timm/data/transforms.py
import math import numbers import random import warnings from typing import List, Sequence, Tuple, Union import torch import torchvision.transforms as transforms import torchvision.transforms.functional as F try: from torchvision.transforms.functional import InterpolationMode has_interpolation_mode = True exce...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/data/tf_preprocessing.py
timm/data/tf_preprocessing.py
""" Tensorflow Preprocessing Adapter Allows use of Tensorflow preprocessing pipeline in PyTorch Transform Copyright of original Tensorflow code below. Hacked together by / Copyright 2020 Ross Wightman """ # Copyright 2018 The TensorFlow Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2....
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/data/readers/reader_factory.py
timm/data/readers/reader_factory.py
import os from typing import Optional from .reader_image_folder import ReaderImageFolder from .reader_image_in_tar import ReaderImageInTar def create_reader( name: str, root: Optional[str] = None, split: str = 'train', **kwargs, ): kwargs = {k: v for k, v in kwargs.items() if v is...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/data/readers/img_extensions.py
timm/data/readers/img_extensions.py
from copy import deepcopy __all__ = ['get_img_extensions', 'is_img_extension', 'set_img_extensions', 'add_img_extensions', 'del_img_extensions'] IMG_EXTENSIONS = ('.png', '.jpg', '.jpeg') # singleton, kept public for bwd compat use _IMG_EXTENSIONS_SET = set(IMG_EXTENSIONS) # set version, private, kept in sync de...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/data/readers/reader.py
timm/data/readers/reader.py
from abc import abstractmethod class Reader: def __init__(self): pass @abstractmethod def _filename(self, index, basename=False, absolute=False): pass def filename(self, index, basename=False, absolute=False): return self._filename(index, basename=basename, absolute=absolute)...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/data/readers/reader_wds.py
timm/data/readers/reader_wds.py
""" Dataset reader for webdataset Hacked together by / Copyright 2022 Ross Wightman """ import io import json import logging import math import os import random import sys from dataclasses import dataclass from functools import partial from itertools import islice from typing import Any, Callable, Dict, List, Optional...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/data/readers/reader_image_tar.py
timm/data/readers/reader_image_tar.py
""" A dataset reader that reads single tarfile based datasets This reader can read datasets consisting if a single tarfile containing images. I am planning to deprecated it in favour of ParerImageInTar. Hacked together by / Copyright 2020 Ross Wightman """ import os import tarfile from timm.utils.misc import natural...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/data/readers/reader_hfds.py
timm/data/readers/reader_hfds.py
""" Dataset reader that wraps Hugging Face datasets Hacked together by / Copyright 2022 Ross Wightman """ import io import math from typing import Optional import torch import torch.distributed as dist from PIL import Image try: import datasets except ImportError as e: print("Please install Hugging Face data...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/data/readers/class_map.py
timm/data/readers/class_map.py
import os import pickle def load_class_map(map_or_filename, root=''): if isinstance(map_or_filename, dict): assert dict, 'class_map dict must be non-empty' return map_or_filename class_map_path = map_or_filename if not os.path.exists(class_map_path): class_map_path = os.path.join(r...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/data/readers/shared_count.py
timm/data/readers/shared_count.py
from multiprocessing import Value class SharedCount: def __init__(self, epoch: int = 0): self.shared_epoch = Value('i', epoch) @property def value(self): return self.shared_epoch.value @value.setter def value(self, epoch): self.shared_epoch.value = epoch
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/data/readers/__init__.py
timm/data/readers/__init__.py
from .reader_factory import create_reader from .img_extensions import *
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/data/readers/reader_image_folder.py
timm/data/readers/reader_image_folder.py
""" A dataset reader that extracts images from folders Folders are scanned recursively to find image files. Labels are based on the folder hierarchy, just leaf folders by default. Hacked together by / Copyright 2020 Ross Wightman """ import os from typing import Dict, List, Optional, Set, Tuple, Union from timm.util...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/data/readers/reader_hfids.py
timm/data/readers/reader_hfids.py
""" Dataset reader for HF IterableDataset """ import math import os from itertools import repeat, chain from typing import Optional import torch import torch.distributed as dist from PIL import Image try: import datasets from datasets.distributed import split_dataset_by_node from datasets.splits import Sp...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/data/readers/reader_tfds.py
timm/data/readers/reader_tfds.py
""" Dataset reader that wraps TFDS datasets Wraps many (most?) TFDS image-classification datasets from https://github.com/tensorflow/datasets https://www.tensorflow.org/datasets/catalog/overview#image_classification Hacked together by / Copyright 2020 Ross Wightman """ import math import os import sys from typing imp...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/data/readers/reader_image_in_tar.py
timm/data/readers/reader_image_in_tar.py
""" A dataset reader that reads tarfile based datasets This reader can extract image samples from: * a single tar of image files * a folder of multiple tarfiles containing imagefiles * a tar of tars containing image files Labels are based on the combined folder and/or tar name structure. Hacked together by / Copyrig...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/task/task.py
timm/task/task.py
"""Base training task abstraction. This module provides the base TrainingTask class that encapsulates a complete forward pass including loss computation. Tasks return a dictionary with loss components and outputs for logging. """ from typing import Dict, Optional import torch import torch.nn as nn class TrainingTas...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/task/__init__.py
timm/task/__init__.py
"""Training task abstractions for timm. This module provides task-based abstractions for training loops where each task encapsulates both the forward pass and loss computation, returning a dictionary with loss components and outputs for logging. """ from .task import TrainingTask from .classification import Classifica...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/task/classification.py
timm/task/classification.py
"""Classification training task.""" import logging from typing import Callable, Dict, Optional, Union import torch import torch.nn as nn from .task import TrainingTask _logger = logging.getLogger(__name__) class ClassificationTask(TrainingTask): """Standard supervised classification task. Simple task that...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/task/distillation.py
timm/task/distillation.py
"""Knowledge distillation training tasks and components.""" import logging from typing import Dict, Optional, Tuple import torch import torch.nn as nn import torch.nn.functional as F from timm.models import create_model from timm.utils import unwrap_model from .task import TrainingTask _logger = logging.getLogger(...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/convert/convert_nest_flax.py
convert/convert_nest_flax.py
""" Convert weights from https://github.com/google-research/nested-transformer NOTE: You'll need https://github.com/google/CommonLoopUtils, not included in requirements.txt """ import sys import numpy as np import torch from clu import checkpoint arch_depths = { 'nest_base': [2, 2, 20], 'nest_small': [2, 2...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
huggingface/pytorch-image-models
https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/convert/convert_from_mxnet.py
convert/convert_from_mxnet.py
import argparse import hashlib import os import mxnet as mx import gluoncv import torch from timm import create_model parser = argparse.ArgumentParser(description='Convert from MXNet') parser.add_argument('--model', default='all', type=str, metavar='MODEL', help='Name of model to train (default: "...
python
Apache-2.0
31a85de79aad229c070c595c5ea0c43dfc95461e
2026-01-04T14:41:55.902905Z
false
myshell-ai/OpenVoice
https://github.com/myshell-ai/OpenVoice/blob/74a1d147b17a8c3092dd5430504bd83ef6c7eb23/setup.py
setup.py
from setuptools import setup, find_packages setup(name='MyShell-OpenVoice', version='0.0.0', description='Instant voice cloning by MyShell.', long_description=open('README.md').read().strip(), long_description_content_type='text/markdown', keywords=[ 'text-to-speech', ...
python
MIT
74a1d147b17a8c3092dd5430504bd83ef6c7eb23
2026-01-04T14:42:07.279944Z
false
myshell-ai/OpenVoice
https://github.com/myshell-ai/OpenVoice/blob/74a1d147b17a8c3092dd5430504bd83ef6c7eb23/openvoice/api.py
openvoice/api.py
import torch import numpy as np import re import soundfile from openvoice import utils from openvoice import commons import os import librosa from openvoice.text import text_to_sequence from openvoice.mel_processing import spectrogram_torch from openvoice.models import SynthesizerTrn class OpenVoiceBaseClass(object):...
python
MIT
74a1d147b17a8c3092dd5430504bd83ef6c7eb23
2026-01-04T14:42:07.279944Z
false
myshell-ai/OpenVoice
https://github.com/myshell-ai/OpenVoice/blob/74a1d147b17a8c3092dd5430504bd83ef6c7eb23/openvoice/attentions.py
openvoice/attentions.py
import math import torch from torch import nn from torch.nn import functional as F from openvoice import commons import logging logger = logging.getLogger(__name__) class LayerNorm(nn.Module): def __init__(self, channels, eps=1e-5): super().__init__() self.channels = channels self.eps = ...
python
MIT
74a1d147b17a8c3092dd5430504bd83ef6c7eb23
2026-01-04T14:42:07.279944Z
false
myshell-ai/OpenVoice
https://github.com/myshell-ai/OpenVoice/blob/74a1d147b17a8c3092dd5430504bd83ef6c7eb23/openvoice/models.py
openvoice/models.py
import math import torch from torch import nn from torch.nn import functional as F from openvoice import commons from openvoice import modules from openvoice import attentions from torch.nn import Conv1d, ConvTranspose1d, Conv2d from torch.nn.utils import weight_norm, remove_weight_norm, spectral_norm from openvoice...
python
MIT
74a1d147b17a8c3092dd5430504bd83ef6c7eb23
2026-01-04T14:42:07.279944Z
false
myshell-ai/OpenVoice
https://github.com/myshell-ai/OpenVoice/blob/74a1d147b17a8c3092dd5430504bd83ef6c7eb23/openvoice/mel_processing.py
openvoice/mel_processing.py
import torch import torch.utils.data from librosa.filters import mel as librosa_mel_fn MAX_WAV_VALUE = 32768.0 def dynamic_range_compression_torch(x, C=1, clip_val=1e-5): """ PARAMS ------ C: compression factor """ return torch.log(torch.clamp(x, min=clip_val) * C) def dynamic_range_decompr...
python
MIT
74a1d147b17a8c3092dd5430504bd83ef6c7eb23
2026-01-04T14:42:07.279944Z
false
myshell-ai/OpenVoice
https://github.com/myshell-ai/OpenVoice/blob/74a1d147b17a8c3092dd5430504bd83ef6c7eb23/openvoice/modules.py
openvoice/modules.py
import math import torch from torch import nn from torch.nn import functional as F from torch.nn import Conv1d from torch.nn.utils import weight_norm, remove_weight_norm from openvoice import commons from openvoice.commons import init_weights, get_padding from openvoice.transforms import piecewise_rational_quadratic_...
python
MIT
74a1d147b17a8c3092dd5430504bd83ef6c7eb23
2026-01-04T14:42:07.279944Z
false
myshell-ai/OpenVoice
https://github.com/myshell-ai/OpenVoice/blob/74a1d147b17a8c3092dd5430504bd83ef6c7eb23/openvoice/commons.py
openvoice/commons.py
import math import torch from torch.nn import functional as F def init_weights(m, mean=0.0, std=0.01): classname = m.__class__.__name__ if classname.find("Conv") != -1: m.weight.data.normal_(mean, std) def get_padding(kernel_size, dilation=1): return int((kernel_size * dilation - dilation) / 2) ...
python
MIT
74a1d147b17a8c3092dd5430504bd83ef6c7eb23
2026-01-04T14:42:07.279944Z
false
myshell-ai/OpenVoice
https://github.com/myshell-ai/OpenVoice/blob/74a1d147b17a8c3092dd5430504bd83ef6c7eb23/openvoice/utils.py
openvoice/utils.py
import re import json import numpy as np def get_hparams_from_file(config_path): with open(config_path, "r", encoding="utf-8") as f: data = f.read() config = json.loads(data) hparams = HParams(**config) return hparams class HParams: def __init__(self, **kwargs): for k, v in kwarg...
python
MIT
74a1d147b17a8c3092dd5430504bd83ef6c7eb23
2026-01-04T14:42:07.279944Z
false
myshell-ai/OpenVoice
https://github.com/myshell-ai/OpenVoice/blob/74a1d147b17a8c3092dd5430504bd83ef6c7eb23/openvoice/__init__.py
openvoice/__init__.py
python
MIT
74a1d147b17a8c3092dd5430504bd83ef6c7eb23
2026-01-04T14:42:07.279944Z
false
myshell-ai/OpenVoice
https://github.com/myshell-ai/OpenVoice/blob/74a1d147b17a8c3092dd5430504bd83ef6c7eb23/openvoice/se_extractor.py
openvoice/se_extractor.py
import os import glob import torch import hashlib import librosa import base64 from glob import glob import numpy as np from pydub import AudioSegment from faster_whisper import WhisperModel import hashlib import base64 import librosa from whisper_timestamped.transcribe import get_audio_tensor, get_vad_segments model_...
python
MIT
74a1d147b17a8c3092dd5430504bd83ef6c7eb23
2026-01-04T14:42:07.279944Z
false
myshell-ai/OpenVoice
https://github.com/myshell-ai/OpenVoice/blob/74a1d147b17a8c3092dd5430504bd83ef6c7eb23/openvoice/openvoice_app.py
openvoice/openvoice_app.py
import os import torch import argparse import gradio as gr from zipfile import ZipFile import langid from openvoice import se_extractor from openvoice.api import BaseSpeakerTTS, ToneColorConverter parser = argparse.ArgumentParser() parser.add_argument("--share", action='store_true', default=False, help="make link publ...
python
MIT
74a1d147b17a8c3092dd5430504bd83ef6c7eb23
2026-01-04T14:42:07.279944Z
false
myshell-ai/OpenVoice
https://github.com/myshell-ai/OpenVoice/blob/74a1d147b17a8c3092dd5430504bd83ef6c7eb23/openvoice/transforms.py
openvoice/transforms.py
import torch from torch.nn import functional as F import numpy as np DEFAULT_MIN_BIN_WIDTH = 1e-3 DEFAULT_MIN_BIN_HEIGHT = 1e-3 DEFAULT_MIN_DERIVATIVE = 1e-3 def piecewise_rational_quadratic_transform( inputs, unnormalized_widths, unnormalized_heights, unnormalized_derivatives, inverse=False, ...
python
MIT
74a1d147b17a8c3092dd5430504bd83ef6c7eb23
2026-01-04T14:42:07.279944Z
false
myshell-ai/OpenVoice
https://github.com/myshell-ai/OpenVoice/blob/74a1d147b17a8c3092dd5430504bd83ef6c7eb23/openvoice/text/english.py
openvoice/text/english.py
""" from https://github.com/keithito/tacotron """ ''' Cleaners are transformations that run over the input text at both training and eval time. Cleaners can be selected by passing a comma-delimited list of cleaner names as the "cleaners" hyperparameter. Some cleaners are English-specific. You'll typically want to use...
python
MIT
74a1d147b17a8c3092dd5430504bd83ef6c7eb23
2026-01-04T14:42:07.279944Z
false
myshell-ai/OpenVoice
https://github.com/myshell-ai/OpenVoice/blob/74a1d147b17a8c3092dd5430504bd83ef6c7eb23/openvoice/text/symbols.py
openvoice/text/symbols.py
''' Defines the set of symbols used in text input to the model. ''' # japanese_cleaners # _pad = '_' # _punctuation = ',.!?-' # _letters = 'AEINOQUabdefghijkmnoprstuvwyzʃʧ↓↑ ' '''# japanese_cleaners2 _pad = '_' _punctuation = ',.!?-~…' _letters = 'AEINOQUabdefghijkmnoprstuvwyzʃʧʦ↓↑ ' ''' '''# korean_...
python
MIT
74a1d147b17a8c3092dd5430504bd83ef6c7eb23
2026-01-04T14:42:07.279944Z
false
myshell-ai/OpenVoice
https://github.com/myshell-ai/OpenVoice/blob/74a1d147b17a8c3092dd5430504bd83ef6c7eb23/openvoice/text/cleaners.py
openvoice/text/cleaners.py
import re from openvoice.text.english import english_to_lazy_ipa, english_to_ipa2, english_to_lazy_ipa2 from openvoice.text.mandarin import number_to_chinese, chinese_to_bopomofo, latin_to_bopomofo, chinese_to_romaji, chinese_to_lazy_ipa, chinese_to_ipa, chinese_to_ipa2 def cjke_cleaners2(text): text = re.sub(r'\[...
python
MIT
74a1d147b17a8c3092dd5430504bd83ef6c7eb23
2026-01-04T14:42:07.279944Z
false
myshell-ai/OpenVoice
https://github.com/myshell-ai/OpenVoice/blob/74a1d147b17a8c3092dd5430504bd83ef6c7eb23/openvoice/text/__init__.py
openvoice/text/__init__.py
""" from https://github.com/keithito/tacotron """ from openvoice.text import cleaners from openvoice.text.symbols import symbols # Mappings from symbol to numeric ID and vice versa: _symbol_to_id = {s: i for i, s in enumerate(symbols)} _id_to_symbol = {i: s for i, s in enumerate(symbols)} def text_to_sequence(text,...
python
MIT
74a1d147b17a8c3092dd5430504bd83ef6c7eb23
2026-01-04T14:42:07.279944Z
false
myshell-ai/OpenVoice
https://github.com/myshell-ai/OpenVoice/blob/74a1d147b17a8c3092dd5430504bd83ef6c7eb23/openvoice/text/mandarin.py
openvoice/text/mandarin.py
import os import sys import re from pypinyin import lazy_pinyin, BOPOMOFO import jieba import cn2an import logging # List of (Latin alphabet, bopomofo) pairs: _latin_to_bopomofo = [(re.compile('%s' % x[0], re.IGNORECASE), x[1]) for x in [ ('a', 'ㄟˉ'), ('b', 'ㄅㄧˋ'), ('c', 'ㄙㄧˉ'), ('d', 'ㄉㄧˋ'), ('e'...
python
MIT
74a1d147b17a8c3092dd5430504bd83ef6c7eb23
2026-01-04T14:42:07.279944Z
false
chatanywhere/GPT_API_free
https://github.com/chatanywhere/GPT_API_free/blob/19d8c2842657cb576a380a1a2a3c2c5c4acc8bc2/demo.py
demo.py
from openai import OpenAI client = OpenAI( # defaults to os.environ.get("OPENAI_API_KEY") api_key="YOUR API KEY", base_url="https://api.chatanywhere.tech/v1" ) # 非流式响应 def gpt_35_api(messages: list): """为提供的对话消息创建新的回答 Args: messages (list): 完整的对话消息 """ completion = client.chat.c...
python
MIT
19d8c2842657cb576a380a1a2a3c2c5c4acc8bc2
2026-01-04T14:42:09.575296Z
false
gradio-app/gradio
https://github.com/gradio-app/gradio/blob/3b56b13268ddcaf74d4e85e5dbf5a616d7843995/render_readme.py
render_readme.py
#!/usr/bin/env python import re from pathlib import Path README_TEMPLATE_FILEPATH = "readme_template.md" GETTING_STARTED_TEMPLATE_FILEPATH = "guides/01_getting-started/01_quickstart.md" readme_template = Path(README_TEMPLATE_FILEPATH).read_text() getting_started_template = Path(GETTING_STARTED_TEMPLATE_FILEPATH).rea...
python
Apache-2.0
3b56b13268ddcaf74d4e85e5dbf5a616d7843995
2026-01-04T14:40:26.993006Z
false
gradio-app/gradio
https://github.com/gradio-app/gradio/blob/3b56b13268ddcaf74d4e85e5dbf5a616d7843995/scripts/delete_old_spaces.py
scripts/delete_old_spaces.py
import argparse import datetime from typing import Optional from huggingface_hub import HfApi def delete_space(space_id: str, hf_token: str, api_client: Optional[HfApi] = None): api_client = api_client or HfApi() api_client.delete_repo(repo_id=space_id, token=hf_token, repo_type="space") def get_spaces_to_...
python
Apache-2.0
3b56b13268ddcaf74d4e85e5dbf5a616d7843995
2026-01-04T14:40:26.993006Z
false
gradio-app/gradio
https://github.com/gradio-app/gradio/blob/3b56b13268ddcaf74d4e85e5dbf5a616d7843995/scripts/overwrite_xray_config.py
scripts/overwrite_xray_config.py
import json import os import random import gradio as gr def fake_func(): return "Hello There" def xray_model(diseases, img): return {disease: random.random() for disease in diseases} def ct_model(diseases, img): return {disease: 0.1 for disease in diseases} with gr.Blocks() as demo: gr.Markdown...
python
Apache-2.0
3b56b13268ddcaf74d4e85e5dbf5a616d7843995
2026-01-04T14:40:26.993006Z
false
gradio-app/gradio
https://github.com/gradio-app/gradio/blob/3b56b13268ddcaf74d4e85e5dbf5a616d7843995/scripts/download_artifacts.py
scripts/download_artifacts.py
import argparse import requests WORKFLOW_RUN_ENDPOINT = ( "https://api.github.com/repos/{owner}/{repo}/actions/runs/{run_id}/artifacts" ) ARTIFACT_DOWNLOAD_ENDPOINT = ( "https://api.github.com/repos/{owner}/{repo}/actions/artifacts/{artifact_id}/zip" ) def download_artifact( owner: str, repo: str, run_i...
python
Apache-2.0
3b56b13268ddcaf74d4e85e5dbf5a616d7843995
2026-01-04T14:40:26.993006Z
false