index
int64
0
0
repo_id
stringlengths
15
98
file_path
stringlengths
33
130
content
stringlengths
27
14.4M
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/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...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/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...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/layers/non_local_attn.py
""" Bilinear-Attention-Transform and Non-Local Attention Paper: `Non-Local Neural Networks With Grouped Bilinear Attentional Transforms` - https://openaccess.thecvf.com/content_CVPR_2020/html/Chi_Non-Local_Neural_Networks_With_Grouped_Bilinear_Attentional_Transforms_CVPR_2020_paper.html Adapted from original code:...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/layers/__init__.py
from .activations import * from .adaptive_avgmax_pool import \ adaptive_avgmax_pool2d, select_adaptive_pool2d, AdaptiveAvgMaxPool2d, SelectAdaptivePool2d from .attention2d import MultiQueryAttention2d, Attention2d, MultiQueryAttentionV2 from .attention_pool import AttentionPoolLatent from .attention_pool2d import A...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/layers/weight_init.py
import torch import math import warnings from torch import nn from torch.nn.init import _calculate_fan_in_and_fan_out def _trunc_normal_(tensor, mean, std, a, b): # Cut & paste from PyTorch official master until it's in a few official releases - RW # Method based on https://people.sc.fsu.edu/~jburkardt/presen...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/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...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/layers/halo_attn.py
""" Halo Self Attention Paper: `Scaling Local Self-Attention for Parameter Efficient Visual Backbones` - https://arxiv.org/abs/2103.12731 @misc{2103.12731, Author = {Ashish Vaswani and Prajit Ramachandran and Aravind Srinivas and Niki Parmar and Blake Hechtman and Jonathon Shlens}, Title = {Scaling Local Self...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/layers/format.py
from enum import Enum from typing import Union import torch class Format(str, Enum): NCHW = 'NCHW' NHWC = 'NHWC' NCL = 'NCL' NLC = 'NLC' FormatT = Union[str, Format] def get_spatial_dim(fmt: FormatT): fmt = Format(fmt) if fmt is Format.NLC: dim = (1,) elif fmt is Format.NCL: ...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/layers/hybrid_embed.py
""" Image to Patch Hybird Embedding Layer Hacked together by / Copyright 2020 Ross Wightman """ import logging import math from typing import List, Optional, Tuple, Union import torch from torch import nn as nn import torch.nn.functional as F from .format import Format, nchw_to from .helpers import to_2tuple from .p...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/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 from .helpers import to_2tuple from .padding import pad_same, get_padding_value def avg_pool2d_same(x, kernel_size: List[int...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/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 = ...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/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 from .config import is_exportable, is_scriptable from .padding import pad_same, pad_same_arg, get_padding_value _USE_EXPORT_CONV = Fa...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/layers/test_time_pool.py
""" Test Time Pooling (Average-Max Pool) Hacked together by / Copyright 2020 Ross Wightman """ import logging from torch import nn import torch.nn.functional as F from .adaptive_avgmax_pool import adaptive_avgmax_pool2d _logger = logging.getLogger(__name__) class TestTimePoolHead(nn.Module): def __init__(sel...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/layers/create_act.py
""" Activation Factory Hacked together by / Copyright 2020 Ross Wightman """ from typing import Union, Callable, Type from .activations import * from .activations_me import * from .config import is_exportable, is_scriptable # PyTorch has an optimized, native 'silu' (aka 'swish') operator as of PyTorch 1.7. # Also har...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/layers/typing.py
from typing import Callable, Tuple, Type, Union import torch LayerType = Union[str, Callable, Type[torch.nn.Module]] PadType = Union[str, int, Tuple[int, int]]
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/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 to True if prefer to...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/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 &...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/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 import numpy as np import torch from torc...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/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 typing import Optional, Type import torch import torch.nn as nn import torch.nn.functional a...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/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): def parse(x): if isinstance(x, collections.abc.Iterable) and not isinstance(x, str): return tuple(x) return tuple...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/layers/norm_act.py
""" Normalization + Activation Layers Provides Norm+Act fns for standard PyTorch norm layers such as * BatchNorm * GroupNorm * LayerNorm This allows swapping with alternative layers that are natively both norm + act such as * EvoNorm (evo_norm.py) * FilterResponseNorm (filter_response_norm.py) * InplaceABN (inplace_a...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/layers/create_norm_act.py
""" NormAct (Normalizaiton + Activation Layer) Factory Create norm + act combo modules that attempt to be backwards compatible with separate norm + act isntances in models. Where these are used it will be possible to swap separate BN + act layers with combined modules like IABN or EvoNorms. Hacked together by / Copyr...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/layers/pos_embed_rel.py
""" Relative position embedding modules and functions Hacked together by / Copyright 2022 Ross Wightman """ import math import os from typing import Optional, Tuple import torch import torch.nn as nn import torch.nn.functional as F from .grid import ndgrid from .interpolate import RegularGridInterpolator from .mlp i...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/layers/attention2d.py
from typing import List, Optional, Union import torch from torch import nn as nn from torch.nn import functional as F from .config import use_fused_attn from .create_conv2d import create_conv2d from .helpers import to_2tuple from .pool2d_same import create_pool2d class MultiQueryAttentionV2(nn.Module): """Multi...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/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...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/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...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/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 ...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/layers/mlp.py
""" MLP module w/ dropout and configurable activation layer Hacked together by / Copyright 2020 Ross Wightman """ from functools import partial from torch import nn as nn from .grn import GlobalResponseNorm from .helpers import to_2tuple class Mlp(nn.Module): """ MLP as used in Vision Transformer, MLP-Mixer an...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/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 """ import torch from torch import nn as nn from .conv_bn_act import ConvNormAct from .helpers import make_divisible from .trace_utils import _assert def ...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/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 .helpers import to_2tuple _logger = logging.getLogger(__name__) def resample_abs_pos_embed( po...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/layers/attention_pool2d.py
""" Attention Pool 2D Implementations of 2D spatial feature pooling using multi-head attention instead of average pool. Based on idea in CLIP by OpenAI, licensed Apache 2.0 https://github.com/openai/CLIP/blob/3b473b0e682c091a9e53623eebc1ca1657385717/clip/model.py Hacked together by / Copyright 2021 Ross Wightman """...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/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 """ import torch from torch import nn as nn from .conv2d_same import create_conv2d_pad def _split_channels(num_chan, num_groups): split = [nu...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/layers/drop.py
""" DropBlock, DropPath PyTorch implementations of DropBlock and DropPath (Stochastic Depth) regularization layers. Papers: DropBlock: A regularization method for convolutional networks (https://arxiv.org/abs/1810.12890) Deep Networks with Stochastic Depth (https://arxiv.org/abs/1603.09382) Code: DropBlock impl ins...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/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...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/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....
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/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...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/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...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/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...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/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...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/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 *...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/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...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/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...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/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_...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/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...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/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...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/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...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/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...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/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...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/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...
0
hf_public_repos/pytorch-image-models/timm/data
hf_public_repos/pytorch-image-models/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...
0
hf_public_repos/pytorch-image-models/timm/data
hf_public_repos/pytorch-image-models/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...
0
hf_public_repos/pytorch-image-models/timm/data
hf_public_repos/pytorch-image-models/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)...
0
hf_public_repos/pytorch-image-models/timm/data
hf_public_repos/pytorch-image-models/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...
0
hf_public_repos/pytorch-image-models/timm/data
hf_public_repos/pytorch-image-models/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...
0
hf_public_repos/pytorch-image-models/timm/data
hf_public_repos/pytorch-image-models/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
0
hf_public_repos/pytorch-image-models/timm/data
hf_public_repos/pytorch-image-models/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...
0
hf_public_repos/pytorch-image-models/timm/data
hf_public_repos/pytorch-image-models/timm/data/readers/__init__.py
from .reader_factory import create_reader from .img_extensions import *
0
hf_public_repos/pytorch-image-models/timm/data
hf_public_repos/pytorch-image-models/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...
0
hf_public_repos/pytorch-image-models/timm/data
hf_public_repos/pytorch-image-models/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...
0
hf_public_repos/pytorch-image-models/timm/data
hf_public_repos/pytorch-image-models/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...
0
hf_public_repos/pytorch-image-models/timm/data
hf_public_repos/pytorch-image-models/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...
0
hf_public_repos/pytorch-image-models/timm/data
hf_public_repos/pytorch-image-models/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...
0
hf_public_repos/pytorch-image-models/timm/data
hf_public_repos/pytorch-image-models/timm/data/_info/imagenet_a_indices.txt
6 11 13 15 17 22 23 27 30 37 39 42 47 50 57 70 71 76 79 89 90 94 96 97 99 105 107 108 110 113 124 125 130 132 143 144 150 151 207 234 235 254 277 283 287 291 295 298 301 306 307 308 309 310 311 313 314 315 317 319 323 324 326 327 330 334 335 336 347 361 363 372 378 386 397 400 401 402 404 407 411 416 417 420 425 428 43...
0
hf_public_repos/pytorch-image-models/timm/data
hf_public_repos/pytorch-image-models/timm/data/_info/imagenet22k_ms_to_22k_indices.txt
1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 ...
0
hf_public_repos/pytorch-image-models/timm/data
hf_public_repos/pytorch-image-models/timm/data/_info/imagenet21k_miil_synsets.txt
n00005787 n00006484 n00007846 n00015388 n00017222 n00021265 n00021939 n00120010 n00141669 n00288000 n00288384 n00324978 n00326094 n00433458 n00433661 n00433802 n00434075 n00439826 n00440039 n00440382 n00440509 n00440747 n00440941 n00441073 n00441824 n00442115 n00442437 n00442847 n00442981 n00443231 n00443692 n00443803 ...
0
hf_public_repos/pytorch-image-models/timm/data
hf_public_repos/pytorch-image-models/timm/data/_info/imagenet22k_ms_synsets.txt
n01440764 n01443537 n01484850 n01491361 n01494475 n01496331 n01498041 n01514668 n01514859 n01518878 n01530575 n01531178 n01532829 n01534433 n01537544 n01558993 n01560419 n01580077 n01582220 n01592084 n01601694 n01608432 n01614925 n01616318 n01622779 n01629819 n01630670 n01631663 n01632458 n01632777 n01641577 n01644373 ...
0
hf_public_repos/pytorch-image-models/timm/data
hf_public_repos/pytorch-image-models/timm/data/_info/imagenet_a_synsets.txt
n01498041 n01531178 n01534433 n01558993 n01580077 n01614925 n01616318 n01631663 n01641577 n01669191 n01677366 n01687978 n01694178 n01698640 n01735189 n01770081 n01770393 n01774750 n01784675 n01819313 n01820546 n01833805 n01843383 n01847000 n01855672 n01882714 n01910747 n01914609 n01924916 n01944390 n01985128 n01986214 ...
0
hf_public_repos/pytorch-image-models/timm/data
hf_public_repos/pytorch-image-models/timm/data/_info/imagenet21k_goog_to_22k_indices.txt
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 10...
0
hf_public_repos/pytorch-image-models/timm/data
hf_public_repos/pytorch-image-models/timm/data/_info/imagenet22k_to_12k_indices.txt
1 3 4 5 6 7 8 9 10 11 13 14 15 16 17 18 19 20 21 23 24 26 27 28 29 30 31 32 33 34 37 38 41 43 44 45 46 47 48 49 50 51 53 55 56 57 58 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 89 90 91 93 94 95 96 97 99 100 101 102 103 105 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121...
0
hf_public_repos/pytorch-image-models/timm/data
hf_public_repos/pytorch-image-models/timm/data/_info/imagenet21k_goog_to_12k_indices.txt
1 3 4 5 6 7 8 9 10 11 13 14 15 16 17 18 19 20 21 23 24 26 27 28 29 30 31 32 33 34 37 38 41 43 44 45 46 47 48 49 50 51 53 55 56 57 58 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 89 90 91 93 94 95 96 97 99 100 101 102 103 105 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121...
0
hf_public_repos/pytorch-image-models/timm/data
hf_public_repos/pytorch-image-models/timm/data/_info/imagenet_synset_to_definition.txt
n00004475 a living thing that has (or can develop) the ability to act or function independently n00005787 organisms (plants and animals) that live at or near the bottom of a sea n00006024 an organism that depends on complex organic substances for nutrition n00006484 (biology) the basic structural and functional unit of...
0
hf_public_repos/pytorch-image-models/timm/data
hf_public_repos/pytorch-image-models/timm/data/_info/imagenet21k_goog_synsets.txt
n00004475 n00005787 n00006024 n00006484 n00007846 n00015388 n00017222 n00021265 n00021939 n00120010 n00141669 n00288000 n00288190 n00288384 n00324978 n00326094 n00433458 n00433661 n00433802 n00434075 n00439826 n00440039 n00440218 n00440382 n00440509 n00440643 n00440747 n00440941 n00441073 n00441824 n00442115 n00442437 ...
0
hf_public_repos/pytorch-image-models/timm/data
hf_public_repos/pytorch-image-models/timm/data/_info/imagenet21k_miil_w21_synsets.txt
n00005787 n00006484 n00007846 n00015388 n00017222 n00021265 n00021939 n00120010 n00141669 n00288000 n00288384 n00324978 n00326094 n00433458 n00433661 n00433802 n00434075 n00439826 n00440039 n00440382 n00440509 n00440747 n00440941 n00441073 n00441824 n00442115 n00442437 n00442847 n00442981 n00443231 n00443692 n00443803 ...
0
hf_public_repos/pytorch-image-models/timm/data
hf_public_repos/pytorch-image-models/timm/data/_info/imagenet_synsets.txt
n01440764 n01443537 n01484850 n01491361 n01494475 n01496331 n01498041 n01514668 n01514859 n01518878 n01530575 n01531178 n01532829 n01534433 n01537544 n01558993 n01560419 n01580077 n01582220 n01592084 n01601694 n01608432 n01614925 n01616318 n01622779 n01629819 n01630670 n01631663 n01632458 n01632777 n01641577 n01644373 ...
0
hf_public_repos/pytorch-image-models/timm/data
hf_public_repos/pytorch-image-models/timm/data/_info/imagenet22k_ms_to_12k_indices.txt
1001 1003 1004 1005 1006 1007 1008 1009 1010 1011 1013 1014 1015 1016 1017 1018 1019 1020 1021 1023 1024 1026 1027 1028 1029 1030 1031 1032 1033 1034 1037 1038 1041 1043 1044 1045 1046 1047 1048 1049 1050 1051 1053 1055 1056 1057 1058 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 ...
0
hf_public_repos/pytorch-image-models/timm/data
hf_public_repos/pytorch-image-models/timm/data/_info/imagenet_synset_to_lemma.txt
n00004475 organism, being n00005787 benthos n00006024 heterotroph n00006484 cell n00007846 person, individual, someone, somebody, mortal, soul n00015388 animal, animate being, beast, brute, creature, fauna n00017222 plant, flora, plant life n00021265 food, nutrient n00021939 artifact, artefact n00120010 hop n00141669 c...
0
hf_public_repos/pytorch-image-models/timm/data
hf_public_repos/pytorch-image-models/timm/data/_info/imagenet22k_synsets.txt
n00004475 n00005787 n00006024 n00006484 n00007846 n00015388 n00017222 n00021265 n00021939 n00120010 n00141669 n00288000 n00288190 n00288384 n00324978 n00326094 n00433458 n00433661 n00433802 n00434075 n00439826 n00440039 n00440218 n00440382 n00440509 n00440643 n00440747 n00440941 n00441073 n00441824 n00442115 n00442437 ...
0
hf_public_repos/pytorch-image-models/timm/data
hf_public_repos/pytorch-image-models/timm/data/_info/imagenet_real_labels.json
[[], [970, 795], [230, 231], [809], [516, 850], [57], [334], [700], [674], [332], [109], [286], [370], [757], [595], [147], [327, 108], [21, 22], [478], [517], [334], [], [948], [727], [23], [619, 526, 846], [270], [167], [64, 55], [858], [324], [573], [150], [981], [586], [887], [], [398], [], [74], [516], [756], [129...
0
hf_public_repos/pytorch-image-models/timm/data
hf_public_repos/pytorch-image-models/timm/data/_info/imagenet_r_synsets.txt
n01443537 n01484850 n01494475 n01498041 n01514859 n01518878 n01531178 n01534433 n01614925 n01616318 n01630670 n01632777 n01644373 n01677366 n01694178 n01748264 n01770393 n01774750 n01784675 n01806143 n01820546 n01833805 n01843383 n01847000 n01855672 n01860187 n01882714 n01910747 n01944390 n01983481 n01986214 n02007558 ...
0
hf_public_repos/pytorch-image-models/timm/data
hf_public_repos/pytorch-image-models/timm/data/_info/imagenet_r_indices.txt
1 2 4 6 8 9 11 13 22 23 26 29 31 39 47 63 71 76 79 84 90 94 96 97 99 100 105 107 113 122 125 130 132 144 145 147 148 150 151 155 160 161 162 163 171 172 178 187 195 199 203 207 208 219 231 232 234 235 242 245 247 250 251 254 259 260 263 265 267 269 276 277 281 288 289 291 292 293 296 299 301 308 309 310 311 314 315 319...
0
hf_public_repos/pytorch-image-models/timm/data
hf_public_repos/pytorch-image-models/timm/data/_info/imagenet12k_synsets.txt
n00005787 n00006484 n00007846 n00015388 n00017222 n00021265 n00021939 n00120010 n00141669 n00288000 n00288384 n00324978 n00326094 n00433458 n00433661 n00433802 n00434075 n00439826 n00440039 n00440382 n00440509 n00440747 n00440941 n00441073 n00441824 n00442115 n00442437 n00442847 n00442981 n00443231 n00443692 n00443803 ...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/loss/binary_cross_entropy.py
""" Binary Cross Entropy w/ a few extras Hacked together by / Copyright 2021 Ross Wightman """ from typing import Optional, Union import torch import torch.nn as nn import torch.nn.functional as F class BinaryCrossEntropy(nn.Module): """ BCE with optional one-hot from dense targets, label smoothing, thresholdin...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/loss/asymmetric_loss.py
import torch import torch.nn as nn class AsymmetricLossMultiLabel(nn.Module): def __init__(self, gamma_neg=4, gamma_pos=1, clip=0.05, eps=1e-8, disable_torch_grad_focal_loss=False): super(AsymmetricLossMultiLabel, self).__init__() self.gamma_neg = gamma_neg self.gamma_pos = gamma_pos ...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/loss/__init__.py
from .asymmetric_loss import AsymmetricLossMultiLabel, AsymmetricLossSingleLabel from .binary_cross_entropy import BinaryCrossEntropy from .cross_entropy import LabelSmoothingCrossEntropy, SoftTargetCrossEntropy from .jsd import JsdCrossEntropy
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/loss/cross_entropy.py
""" Cross Entropy w/ smoothing or soft targets Hacked together by / Copyright 2021 Ross Wightman """ import torch import torch.nn as nn import torch.nn.functional as F class LabelSmoothingCrossEntropy(nn.Module): """ NLL loss with label smoothing. """ def __init__(self, smoothing=0.1): super(Lab...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/loss/jsd.py
import torch import torch.nn as nn import torch.nn.functional as F from .cross_entropy import LabelSmoothingCrossEntropy class JsdCrossEntropy(nn.Module): """ Jensen-Shannon Divergence + Cross-Entropy Loss Based on impl here: https://github.com/google-research/augmix/blob/master/imagenet.py From paper: ...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/models/_efficientnet_builder.py
""" EfficientNet, MobileNetV3, etc Builder Assembles EfficieNet and related network feature blocks from string definitions. Handles stride, dilation calculations, and selects feature extraction points. Hacked together by / Copyright 2019, Ross Wightman """ from typing import Callable, Optional import logging import ...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/models/_builder.py
import dataclasses import logging import os from copy import deepcopy from typing import Any, Callable, Dict, List, Optional, Tuple from torch import nn as nn from torch.hub import load_state_dict_from_url from timm.models._features import FeatureListNet, FeatureDictNet, FeatureHookNet, FeatureGetterNet from timm.mod...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/models/edgenext.py
""" EdgeNeXt Paper: `EdgeNeXt: Efficiently Amalgamated CNN-Transformer Architecture for Mobile Vision Applications` - https://arxiv.org/abs/2206.10589 Original code and weights from https://github.com/mmaaz60/EdgeNeXt Modifications and additions for timm by / Copyright 2022, Ross Wightman """ import math from funct...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/models/eva.py
""" EVA EVA from https://github.com/baaivision/EVA , paper: https://arxiv.org/abs/2211.07636 @article{EVA, title={EVA: Exploring the Limits of Masked Visual Representation Learning at Scale}, author={Fang, Yuxin and Wang, Wen and Xie, Binhui and Sun, Quan and Wu, Ledell and Wang, Xinggang and Huang, Tiejun and ...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/models/inception_v3.py
""" Inception-V3 Originally from torchvision Inception3 model Licensed BSD-Clause 3 https://github.com/pytorch/vision/blob/master/LICENSE """ from functools import partial from typing import Optional import torch import torch.nn as nn import torch.nn.functional as F from timm.data import IMAGENET_DEFAULT_STD, IMAGEN...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/models/maxxvit.py
""" MaxVit and CoAtNet Vision Transformer - CNN Hybrids in PyTorch This is a from-scratch implementation of both CoAtNet and MaxVit in PyTorch. 99% of the implementation was done from papers, however last minute some adjustments were made based on the (as yet unfinished?) public code release https://github.com/google...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/models/_pretrained.py
import copy from collections import deque, defaultdict from dataclasses import dataclass, field, replace, asdict from typing import Any, Deque, Dict, Tuple, Optional, Union __all__ = ['PretrainedCfg', 'filter_pretrained_cfg', 'DefaultCfg'] @dataclass class PretrainedCfg: """ """ # weight source location...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/models/nasnet.py
""" NasNet-A (Large) nasnetalarge implementation grabbed from Cadene's pretrained models https://github.com/Cadene/pretrained-models.pytorch """ from functools import partial from typing import Optional import torch import torch.nn as nn import torch.nn.functional as F from timm.layers import ConvNormAct, create_co...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/models/focalnet.py
""" FocalNet As described in `Focal Modulation Networks` - https://arxiv.org/abs/2203.11926 Significant modifications and refactoring from the original impl at https://github.com/microsoft/FocalNet This impl is/has: * fully convolutional, NCHW tensor layout throughout, seemed to have minimal performance impact but m...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/models/senet.py
""" SEResNet implementation from Cadene's pretrained models https://github.com/Cadene/pretrained-models.pytorch/blob/master/pretrainedmodels/models/senet.py Additional credit to https://github.com/creafz Original model: https://github.com/hujie-frank/SENet ResNet code gently borrowed from https://github.com/pytorch/v...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/models/inception_v4.py
""" Pytorch Inception-V4 implementation Sourced from https://github.com/Cadene/tensorflow-model-zoo.torch (MIT License) which is based upon Google's Tensorflow implementation and pretrained weights (Apache 2.0 License) """ from functools import partial import torch import torch.nn as nn from timm.data import IMAGENET...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/models/_features.py
""" PyTorch Feature Extraction Helpers A collection of classes, functions, modules to help extract features from models and provide a common interface for describing them. The return_layers, module re-writing idea inspired by torchvision IntermediateLayerGetter https://github.com/pytorch/vision/blob/d88d8961ae51507d0...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/models/volo.py
""" Vision OutLOoker (VOLO) implementation Paper: `VOLO: Vision Outlooker for Visual Recognition` - https://arxiv.org/abs/2106.13112 Code adapted from official impl at https://github.com/sail-sg/volo, original copyright in comment below Modifications and additions for timm by / Copyright 2022, Ross Wightman """ # Co...
0
hf_public_repos/pytorch-image-models/timm
hf_public_repos/pytorch-image-models/timm/models/cait.py
""" Class-Attention in Image Transformers (CaiT) Paper: 'Going deeper with Image Transformers' - https://arxiv.org/abs/2103.17239 Original code and weights from https://github.com/facebookresearch/deit, copyright below Modifications and additions for timm hacked together by / Copyright 2021, Ross Wightman """ # Copy...