repo stringlengths 1 99 | file stringlengths 13 215 | code stringlengths 12 59.2M | file_length int64 12 59.2M | avg_line_length float64 3.82 1.48M | max_line_length int64 12 2.51M | extension_type stringclasses 1
value |
|---|---|---|---|---|---|---|
RandStainNA | RandStainNA-master/classification/train.py | #!/usr/bin/env python3
""" ImageNet Training Script
This is intended to be a lean and easily modifiable ImageNet training script that reproduces ImageNet
training results with some of the latest networks and training techniques. It favours canonical PyTorch
and standard Python style over trying to be able to 'do it al... | 53,098 | 47.403829 | 326 | py |
RandStainNA | RandStainNA-master/classification/test_time_aug/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 random
from functools impo... | 13,911 | 34.489796 | 118 | py |
RandStainNA | RandStainNA-master/classification/test_time_aug/train.py | #!/usr/bin/env python3
""" ImageNet Training Script
This is intended to be a lean and easily modifiable ImageNet training script that reproduces ImageNet
training results with some of the latest networks and training techniques. It favours canonical PyTorch
and standard Python style over trying to be able to 'do it al... | 54,183 | 47.639138 | 326 | py |
RandStainNA | RandStainNA-master/classification/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: "... | 4,033 | 36.351852 | 115 | py |
RandStainNA | RandStainNA-master/classification/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... | 5,582 | 50.220183 | 131 | py |
RandStainNA | RandStainNA-master/classification/timm/scheduler/plateau_lr.py | """ Plateau Scheduler
Adapts PyTorch plateau scheduler and allows application of noise, warmup.
Hacked together by / Copyright 2020 Ross Wightman
"""
import torch
from .scheduler import Scheduler
class PlateauLRScheduler(Scheduler):
"""Decay the LR by a factor every time the validation loss plateaus."""
d... | 4,140 | 35.324561 | 97 | py |
RandStainNA | RandStainNA-master/classification/timm/scheduler/tanh_lr.py | """ TanH Scheduler
TanH schedule with warmup, cycle/restarts, noise.
Hacked together by / Copyright 2021 Ross Wightman
"""
import logging
import math
import numpy as np
import torch
from .scheduler import Scheduler
_logger = logging.getLogger(__name__)
class TanhLRScheduler(Scheduler):
"""
Hyberbolic-Tan... | 3,936 | 32.364407 | 116 | py |
RandStainNA | RandStainNA-master/classification/timm/scheduler/cosine_lr.py | """ Cosine Scheduler
Cosine LR schedule with warmup, cycle/restarts, noise, k-decay.
Hacked together by / Copyright 2021 Ross Wightman
"""
import logging
import math
import numpy as np
import torch
from .scheduler import Scheduler
_logger = logging.getLogger(__name__)
class CosineLRScheduler(Scheduler):
"""
... | 4,161 | 33.683333 | 113 | py |
RandStainNA | RandStainNA-master/classification/timm/scheduler/scheduler.py | from typing import Dict, Any
import torch
class Scheduler:
""" Parameter Scheduler Base Class
A scheduler base class that can be used to schedule any optimizer parameter groups.
Unlike the builtin PyTorch schedulers, this is intended to be consistently called
* At the END of each epoch, before incre... | 4,750 | 43.820755 | 112 | py |
RandStainNA | RandStainNA-master/classification/timm/scheduler/poly_lr.py | """ Polynomial Scheduler
Polynomial LR schedule with warmup, noise.
Hacked together by / Copyright 2021 Ross Wightman
"""
import math
import logging
import torch
from .scheduler import Scheduler
_logger = logging.getLogger(__name__)
class PolyLRScheduler(Scheduler):
""" Polynomial LR Scheduler w/ warmup, no... | 4,003 | 33.222222 | 113 | py |
RandStainNA | RandStainNA-master/classification/timm/scheduler/step_lr.py | """ Step Scheduler
Basic step LR schedule with warmup, noise.
Hacked together by / Copyright 2020 Ross Wightman
"""
import math
import torch
from .scheduler import Scheduler
class StepLRScheduler(Scheduler):
"""
"""
def __init__(self,
optimizer: torch.optim.Optimizer,
... | 1,902 | 28.734375 | 105 | py |
RandStainNA | RandStainNA-master/classification/timm/scheduler/multistep_lr.py | """ MultiStep LR Scheduler
Basic multi step LR schedule with warmup, noise.
"""
import torch
import bisect
from timm.scheduler.scheduler import Scheduler
from typing import List
class MultiStepLRScheduler(Scheduler):
"""
"""
def __init__(self,
optimizer: torch.optim.Optimizer,
... | 2,098 | 30.80303 | 105 | py |
RandStainNA | RandStainNA-master/classification/timm/models/dla.py | """ Deep Layer Aggregation and DLA w/ Res2Net
DLA original adapted from Official Pytorch impl at:
DLA Paper: `Deep Layer Aggregation` - https://arxiv.org/abs/1707.06484
Res2Net additions from: https://github.com/gasvn/Res2Net/
Res2Net Paper: `Res2Net: A New Multi-scale Backbone Architecture` - https://arxiv.org/abs/19... | 17,205 | 37.752252 | 127 | py |
RandStainNA | RandStainNA-master/classification/timm/models/efficientnet_blocks.py | """ EfficientNet, MobileNetV3, etc Blocks
Hacked together by / Copyright 2019, Ross Wightman
"""
import torch
import torch.nn as nn
from torch.nn import functional as F
from .layers import create_conv2d, drop_path, make_divisible, create_act_layer
from .layers.activations import sigmoid
__all__ = [
'SqueezeExci... | 12,442 | 37.404321 | 115 | py |
RandStainNA | RandStainNA-master/classification/timm/models/hrnet.py | """ HRNet
Copied from https://github.com/HRNet/HRNet-Image-Classification
Original header:
Copyright (c) Microsoft
Licensed under the MIT License.
Written by Bin Xiao (Bin.Xiao@microsoft.com)
Modified by Ke Sun (sunk@mail.ustc.edu.cn)
"""
import logging
from typing import List
import torch
import torch.nn as... | 29,402 | 34.129032 | 126 | py |
RandStainNA | RandStainNA-master/classification/timm/models/mlp_mixer.py | """ MLP-Mixer, ResMLP, and gMLP in PyTorch
This impl originally based on MLP-Mixer paper.
Official JAX impl: https://github.com/google-research/vision_transformer/blob/linen/vit_jax/models_mixer.py
Paper: 'MLP-Mixer: An all-MLP Architecture for Vision' - https://arxiv.org/abs/2105.01601
@article{tolstikhin2021,
t... | 26,040 | 38.456061 | 133 | py |
RandStainNA | RandStainNA-master/classification/timm/models/selecsls.py | """PyTorch SelecSLS Net example for ImageNet Classification
License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/legalcode)
Author: Dushyant Mehta (@mehtadushy)
SelecSLS (core) Network Architecture as proposed in "XNect: Real-time Multi-person 3D
Human Pose Estimation with a Single RGB Camera, Mehta et al."... | 13,124 | 35.157025 | 121 | py |
RandStainNA | RandStainNA-master/classification/timm/models/regnet.py | """RegNet
Paper: `Designing Network Design Spaces` - https://arxiv.org/abs/2003.13678
Original Impl: https://github.com/facebookresearch/pycls/blob/master/pycls/models/regnet.py
Based on original PyTorch impl linked above, but re-wrote to use my own blocks (adapted from ResNet here)
and cleaned up with more descripti... | 20,998 | 41.422222 | 133 | py |
RandStainNA | RandStainNA-master/classification/timm/models/tnt.py | """ Transformer in Transformer (TNT) in PyTorch
A PyTorch implement of TNT as described in
'Transformer in Transformer' - https://arxiv.org/abs/2103.00112
The official mindspore code is released and available at
https://gitee.com/mindspore/mindspore/tree/master/model_zoo/research/cv/TNT
"""
import math
import torch
i... | 11,209 | 40.062271 | 120 | py |
RandStainNA | RandStainNA-master/classification/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
"""
import logging
import math
import re
from copy import deepco... | 19,459 | 40.939655 | 124 | py |
RandStainNA | RandStainNA-master/classification/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... | 12,155 | 41.652632 | 111 | py |
RandStainNA | RandStainNA-master/classification/timm/models/ghostnet.py | """
An implementation of GhostNet Model as defined in:
GhostNet: More Features from Cheap Operations. https://arxiv.org/abs/1911.11907
The train script of the model is similar to that of MobileNetV3
Original model: https://github.com/huawei-noah/CV-backbones/tree/master/ghostnet_pytorch
"""
import math
from functools i... | 9,326 | 32.67148 | 120 | py |
RandStainNA | RandStainNA-master/classification/timm/models/efficientnet.py | """ The EfficientNet Family in PyTorch
An implementation of EfficienNet that covers variety of related models with efficient architectures:
* EfficientNet-V2
- `EfficientNetV2: Smaller Models and Faster Training` - https://arxiv.org/abs/2104.00298
* EfficientNet (B0-B8, L2 + Tensorflow pretrained AutoAug/RandAug/A... | 97,919 | 41.225097 | 144 | py |
RandStainNA | RandStainNA-master/classification/timm/models/hardcorenas.py | from functools import partial
import torch.nn as nn
from timm.data import IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD
from .efficientnet_blocks import SqueezeExcite
from .efficientnet_builder import decode_arch_def, resolve_act_layer, resolve_bn_args, round_channels
from .helpers import build_model_with_cfg, default_... | 8,036 | 51.529412 | 148 | py |
RandStainNA | RandStainNA-master/classification/timm/models/swin_transformer.py | """ Swin Transformer
A PyTorch impl of : `Swin Transformer: Hierarchical Vision Transformer using Shifted Windows`
- https://arxiv.org/pdf/2103.14030
Code/weights from https://github.com/microsoft/Swin-Transformer, original copyright/license info below
Modifications and additions for timm hacked together by / Cop... | 27,586 | 40.672205 | 125 | py |
RandStainNA | RandStainNA-master/classification/timm/models/levit.py | """ LeViT
Paper: `LeViT: a Vision Transformer in ConvNet's Clothing for Faster Inference`
- https://arxiv.org/abs/2104.01136
@article{graham2021levit,
title={LeViT: a Vision Transformer in ConvNet's Clothing for Faster Inference},
author={Benjamin Graham and Alaaeldin El-Nouby and Hugo Touvron and Pierre Stoc... | 21,163 | 36.524823 | 141 | py |
RandStainNA | RandStainNA-master/classification/timm/models/pnasnet.py | """
pnasnet5large implementation grabbed from Cadene's pretrained models
Additional credit to https://github.com/creafz
https://github.com/Cadene/pretrained-models.pytorch/blob/master/pretrainedmodels/models/pnasnet.py
"""
from collections import OrderedDict
from functools import partial
import torch
import torch... | 14,961 | 41.626781 | 124 | py |
RandStainNA | RandStainNA-master/classification/timm/models/fx_features.py | """ PyTorch FX Based Feature Extraction Helpers
Using https://pytorch.org/vision/stable/feature_extraction.html
"""
from typing import Callable
from torch import nn
from .features import _get_feature_info
try:
from torchvision.models.feature_extraction import create_feature_extractor
has_fx_feature_extraction... | 2,855 | 37.594595 | 119 | py |
RandStainNA | RandStainNA-master/classification/timm/models/convit.py | """ ConViT Model
@article{d2021convit,
title={ConViT: Improving Vision Transformers with Soft Convolutional Inductive Biases},
author={d'Ascoli, St{\'e}phane and Touvron, Hugo and Leavitt, Matthew and Morcos, Ari and Biroli, Giulio and Sagun, Levent},
journal={arXiv preprint arXiv:2103.10697},
year={2021}
}
P... | 13,952 | 38.415254 | 126 | py |
RandStainNA | RandStainNA-master/classification/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... | 14,940 | 36.729798 | 112 | py |
RandStainNA | RandStainNA-master/classification/timm/models/resnet.py | """PyTorch ResNet
This started as a copy of https://github.com/pytorch/vision 'resnet.py' (BSD-3-Clause) with
additional dropout and dynamic global avg/max pool.
ResNeXt, SE-ResNeXt, SENet, and MXNet Gluon stem/downsample variants, tiered stems added by Ross Wightman
Copyright 2019, Ross Wightman
"""
import math
fro... | 68,756 | 43.416667 | 135 | py |
RandStainNA | RandStainNA-master/classification/timm/models/xception_aligned.py | """Pytorch impl of Aligned Xception 41, 65, 71
This is a correct, from scratch impl of Aligned Xception (Deeplab) models compatible with TF weights at
https://github.com/tensorflow/models/blob/master/research/deeplab/g3doc/model_zoo.md
Hacked together by / Copyright 2020 Ross Wightman
"""
from functools import partia... | 8,948 | 36.443515 | 124 | py |
RandStainNA | RandStainNA-master/classification/timm/models/rexnet.py | """ ReXNet
A PyTorch impl of `ReXNet: Diminishing Representational Bottleneck on Convolutional Neural Network` -
https://arxiv.org/abs/2007.00992
Adapted from original impl at https://github.com/clovaai/rexnet
Copyright (c) 2020-present NAVER Corp. MIT license
Changes for timm, feature extraction, and rounded channe... | 9,228 | 37.454167 | 121 | py |
RandStainNA | RandStainNA-master/classification/timm/models/vgg.py | """VGG
Adapted from https://github.com/pytorch/vision 'vgg.py' (BSD-3-Clause) with a few changes for
timm functionality.
Copyright 2021 Ross Wightman
"""
import torch
import torch.nn as nn
import torch.nn.functional as F
from typing import Union, List, Dict, Any, cast
from timm.data import IMAGENET_DEFAULT_MEAN, IMA... | 10,455 | 38.756654 | 117 | py |
RandStainNA | RandStainNA-master/classification/timm/models/nest.py | """ Nested Transformer (NesT) in PyTorch
A PyTorch implement of Aggregating Nested Transformers as described in:
'Aggregating Nested Transformers'
- https://arxiv.org/abs/2105.12723
The official Jax code is released and available at https://github.com/google-research/nested-transformer. The weights
have been con... | 19,521 | 40.892704 | 128 | py |
RandStainNA | RandStainNA-master/classification/timm/models/hub.py | import json
import logging
import os
from functools import partial
from pathlib import Path
from typing import Union
import torch
from torch.hub import HASH_REGEX, download_url_to_file, urlparse
try:
from torch.hub import get_dir
except ImportError:
from torch.hub import _get_torch_home as get_dir
from timm i... | 5,988 | 33.819767 | 117 | py |
RandStainNA | RandStainNA-master/classification/timm/models/densenet.py | """Pytorch Densenet implementation w/ tweaks
This file is a copy of https://github.com/pytorch/vision 'densenet.py' (BSD-3-Clause) with
fixed kwargs passthrough and addition of dynamic global avg/max pool.
"""
import re
from collections import OrderedDict
from functools import partial
import torch
import torch.nn as n... | 15,611 | 39.237113 | 129 | py |
RandStainNA | RandStainNA-master/classification/timm/models/resnetv2.py | """Pre-Activation ResNet v2 with GroupNorm and Weight Standardization.
A PyTorch implementation of ResNetV2 adapted from the Google Big-Transfoer (BiT) source code
at https://github.com/google-research/big_transfer to match timm interfaces. The BiT weights have
been included here as pretrained models from their origin... | 28,274 | 41.013373 | 129 | py |
RandStainNA | RandStainNA-master/classification/timm/models/byobnet.py | """ Bring-Your-Own-Blocks Network
A flexible network w/ dataclass based config for stacking those NN blocks.
This model is currently used to implement the following networks:
GPU Efficient (ResNets) - gernet_l/m/s (original versions called genet, but this was already used (by SENet author)).
Paper: `Neural Architect... | 62,040 | 39.496736 | 134 | py |
RandStainNA | RandStainNA-master/classification/timm/models/mobilenetv3.py | """ MobileNet V3
A PyTorch impl of MobileNet-V3, compatible with TF weights from official impl.
Paper: Searching for MobileNetV3 - https://arxiv.org/abs/1905.02244
Hacked together by / Copyright 2019, Ross Wightman
"""
from functools import partial
from typing import List
import torch
import torch.nn as nn
import t... | 26,586 | 38.446588 | 161 | py |
RandStainNA | RandStainNA-master/classification/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... | 17,642 | 36.698718 | 127 | py |
RandStainNA | RandStainNA-master/classification/timm/models/xcit.py | """ Cross-Covariance Image Transformer (XCiT) in PyTorch
Paper:
- https://arxiv.org/abs/2106.09681
Same as the official implementation, with some minor adaptations, original copyright below
- https://github.com/facebookresearch/xcit/blob/master/xcit.py
Modifications and additions for timm hacked together by ... | 35,892 | 43.040491 | 120 | py |
RandStainNA | RandStainNA-master/classification/timm/models/vovnet.py | """ VoVNet (V1 & V2)
Papers:
* `An Energy and GPU-Computation Efficient Backbone Network` - https://arxiv.org/abs/1904.09730
* `CenterMask : Real-Time Anchor-Free Instance Segmentation` - https://arxiv.org/abs/1911.06667
Looked at https://github.com/youngwanLEE/vovnet-detectron2 &
https://github.com/stigma0617/VoVNe... | 13,845 | 33.019656 | 126 | py |
RandStainNA | RandStainNA-master/classification/timm/models/vision_transformer.py | """ Vision Transformer (ViT) in PyTorch
A PyTorch implement of Vision Transformers as described in:
'An Image Is Worth 16 x 16 Words: Transformers for Image Recognition at Scale'
- https://arxiv.org/abs/2010.11929
`How to train your ViT? Data, Augmentation, and Regularization in Vision Transformers`
- https:... | 49,267 | 47.780198 | 140 | py |
RandStainNA | RandStainNA-master/classification/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)
"""
import torch
import torch.nn as nn
import torch.nn.functional as F
from timm.data import IMAGENE... | 10,804 | 33.085174 | 122 | py |
RandStainNA | RandStainNA-master/classification/timm/models/inception_v3.py | """ Inception-V3
Originally from torchvision Inception3 model
Licensed BSD-Clause 3 https://github.com/pytorch/vision/blob/master/LICENSE
"""
import torch
import torch.nn as nn
import torch.nn.functional as F
from timm.data import IMAGENET_DEFAULT_STD, IMAGENET_DEFAULT_MEAN, IMAGENET_INCEPTION_MEAN, IMAGENET_INCEPTIO... | 17,469 | 36.091295 | 127 | py |
RandStainNA | RandStainNA-master/classification/timm/models/gluon_xception.py | """Pytorch impl of Gluon Xception
This is a port of the Gluon Xception code and weights, itself ported from a PyTorch DeepLab impl.
Gluon model: (https://gluon-cv.mxnet.io/_modules/gluoncv/model_zoo/xception.html)
Original PyTorch DeepLab impl: https://github.com/jfzhang95/pytorch-deeplab-xception
Hacked together by ... | 8,705 | 34.246964 | 126 | py |
RandStainNA | RandStainNA-master/classification/timm/models/vision_transformer_hybrid.py | """ Hybrid Vision Transformer (ViT) in PyTorch
A PyTorch implement of the Hybrid Vision Transformers as described in:
'An Image Is Worth 16 x 16 Words: Transformers for Image Recognition at Scale'
- https://arxiv.org/abs/2010.11929
`How to train your ViT? Data, Augmentation, and Regularization in Vision Transfor... | 16,099 | 43.352617 | 137 | py |
RandStainNA | RandStainNA-master/classification/timm/models/visformer.py | """ Visformer
Paper: Visformer: The Vision-friendly Transformer - https://arxiv.org/abs/2104.12533
From original at https://github.com/danczs/Visformer
Modifications and additions for timm hacked together by / Copyright 2021, Ross Wightman
"""
from copy import deepcopy
import torch
import torch.nn as nn
import torc... | 16,086 | 37.857488 | 128 | py |
RandStainNA | RandStainNA-master/classification/timm/models/pit.py | """ Pooling-based Vision Transformer (PiT) in PyTorch
A PyTorch implement of Pooling-based Vision Transformers as described in
'Rethinking Spatial Dimensions of Vision Transformers' - https://arxiv.org/abs/2103.16302
This code was adapted from the original version at https://github.com/naver-ai/pit, original copyrigh... | 13,037 | 32.953125 | 122 | py |
RandStainNA | RandStainNA-master/classification/timm/models/tresnet.py | """
TResNet: High Performance GPU-Dedicated Architecture
https://arxiv.org/pdf/2003.13630.pdf
Original model: https://github.com/mrT23/TResNet
"""
from collections import OrderedDict
import torch
import torch.nn as nn
from .helpers import build_model_with_cfg
from .layers import SpaceToDepthModule, BlurPool2d, Inpl... | 11,596 | 37.916107 | 149 | py |
RandStainNA | RandStainNA-master/classification/timm/models/twins.py | """ Twins
A PyTorch impl of : `Twins: Revisiting the Design of Spatial Attention in Vision Transformers`
- https://arxiv.org/pdf/2104.13840.pdf
Code/weights from https://github.com/Meituan-AutoML/Twins, original copyright/license info below
"""
# --------------------------------------------------------
# Twins
# ... | 17,346 | 39.816471 | 131 | py |
RandStainNA | RandStainNA-master/classification/timm/models/resnest.py | """ ResNeSt Models
Paper: `ResNeSt: Split-Attention Networks` - https://arxiv.org/abs/2004.08955
Adapted from original PyTorch impl w/ weights at https://github.com/zhanghang1989/ResNeSt by Hang Zhang
Modified for torchscript compat, and consistency with timm by Ross Wightman
"""
import torch
from torch import nn
f... | 10,092 | 41.407563 | 131 | py |
RandStainNA | RandStainNA-master/classification/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
import torch
import torch.nn as nn
import torch.nn.functional as F
from .helpers import build_model_with_cfg
from .layers import ConvBnAct, c... | 25,944 | 44.677817 | 116 | py |
RandStainNA | RandStainNA-master/classification/timm/models/gluon_resnet.py | """Pytorch impl of MxNet Gluon ResNet/(SE)ResNeXt variants
This file evolved from https://github.com/pytorch/vision 'resnet.py' with (SE)-ResNeXt additions
and ports of Gluon variations (https://github.com/dmlc/gluon-cv/blob/master/gluoncv/model_zoo/resnet.py)
by Ross Wightman
"""
from timm.data import IMAGENET_DEFAU... | 11,362 | 44.634538 | 165 | py |
RandStainNA | RandStainNA-master/classification/timm/models/byoanet.py | """ Bring-Your-Own-Attention Network
A flexible network w/ dataclass based config for stacking NN blocks including
self-attention (or similar) layers.
Currently used to implement experimental variants of:
* Bottleneck Transformers
* Lambda ResNets
* HaloNets
Consider all of the models definitions here as exper... | 18,350 | 40.331081 | 140 | py |
RandStainNA | RandStainNA-master/classification/timm/models/xception.py | """
Ported to pytorch thanks to [tstandley](https://github.com/tstandley/Xception-PyTorch)
@author: tstandley
Adapted by cadene
Creates an Xception Model as defined in:
Francois Chollet
Xception: Deep Learning with Depthwise Separable Convolutions
https://arxiv.org/pdf/1610.02357.pdf
This weights ported from the Ke... | 7,388 | 30.712446 | 120 | py |
RandStainNA | RandStainNA-master/classification/timm/models/inception_resnet_v2.py | """ Pytorch Inception-Resnet-V2 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)
"""
import torch
import torch.nn as nn
import torch.nn.functional as F
from timm.data import ... | 12,464 | 33.721448 | 139 | py |
RandStainNA | RandStainNA-master/classification/timm/models/convnext.py | """ ConvNeXt
Paper: `A ConvNet for the 2020s` - https://arxiv.org/pdf/2201.03545.pdf
Original code and weights from https://github.com/facebookresearch/ConvNeXt, original copyright below
Modifications and additions for timm hacked together by / Copyright 2022, Ross Wightman
"""
# Copyright (c) Meta Platforms, Inc. a... | 17,443 | 39.757009 | 117 | py |
RandStainNA | RandStainNA-master/classification/timm/models/dpn.py | """ PyTorch implementation of DualPathNetworks
Based on original MXNet implementation https://github.com/cypw/DPNs with
many ideas from another PyTorch implementation https://github.com/oyam/pytorch-DPNs.
This implementation is compatible with the pretrained weights from cypw's MXNet implementation.
Hacked together b... | 12,448 | 38.147799 | 118 | py |
RandStainNA | RandStainNA-master/classification/timm/models/sknet.py | """ Selective Kernel Networks (ResNet base)
Paper: Selective Kernel Networks (https://arxiv.org/abs/1903.06586)
This was inspired by reading 'Compounding the Performance Improvements...' (https://arxiv.org/abs/2001.06268)
and a streamlined impl at https://github.com/clovaai/assembled-cnn but I ended up building somet... | 8,742 | 39.476852 | 124 | py |
RandStainNA | RandStainNA-master/classification/timm/models/helpers.py | """ Model creation / weight loading / state_dict helpers
Hacked together by / Copyright 2020 Ross Wightman
"""
import logging
import os
import math
from collections import OrderedDict
from copy import deepcopy
from typing import Any, Callable, Optional, Tuple
import torch
import torch.nn as nn
from torch.hub import l... | 22,671 | 42.684008 | 120 | py |
RandStainNA | RandStainNA-master/classification/timm/models/res2net.py | """ Res2Net and Res2NeXt
Adapted from Official Pytorch impl at: https://github.com/gasvn/Res2Net/
Paper: `Res2Net: A New Multi-scale Backbone Architecture` - https://arxiv.org/abs/1904.01169
"""
import math
import torch
import torch.nn as nn
from timm.data import IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD
from .help... | 7,865 | 35.248848 | 127 | py |
RandStainNA | RandStainNA-master/classification/timm/models/coat.py | """
CoaT architecture.
Paper: Co-Scale Conv-Attentional Image Transformers - https://arxiv.org/abs/2104.06399
Official CoaT code at: https://github.com/mlpc-ucsd/CoaT
Modified from timm/models/vision_transformer.py
"""
from copy import deepcopy
from functools import partial
from typing import Tuple, List
import to... | 26,936 | 39.751891 | 128 | py |
RandStainNA | RandStainNA-master/classification/timm/models/convmixer.py | import torch.nn as nn
from timm.data import IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD
from timm.models.registry import register_model
from .helpers import build_model_with_cfg
def _cfg(url='', **kwargs):
return {
'url': url,
'num_classes': 1000, 'input_size': (3, 224, 224), 'pool_size': None,
... | 3,631 | 34.960396 | 144 | py |
RandStainNA | RandStainNA-master/classification/timm/models/nfnet.py | """ Normalization Free Nets. NFNet, NF-RegNet, NF-ResNet (pre-activation) Models
Paper: `Characterizing signal propagation to close the performance gap in unnormalized ResNets`
- https://arxiv.org/abs/2101.08692
Paper: `High-Performance Large-Scale Image Recognition Without Normalization`
- https://arxiv.org/... | 41,006 | 41.318885 | 129 | py |
RandStainNA | RandStainNA-master/classification/timm/models/cspnet.py | """PyTorch CspNet
A PyTorch implementation of Cross Stage Partial Networks including:
* CSPResNet50
* CSPResNeXt50
* CSPDarkNet53
* and DarkNet53 for good measure
Based on paper `CSPNet: A New Backbone that can Enhance Learning Capability of CNN` - https://arxiv.org/abs/1911.11929
Reference impl via darknet cfg file... | 18,221 | 38.527115 | 129 | py |
RandStainNA | RandStainNA-master/classification/timm/models/crossvit.py | """ CrossViT Model
@inproceedings{
chen2021crossvit,
title={{CrossViT: Cross-Attention Multi-Scale Vision Transformer for Image Classification}},
author={Chun-Fu (Richard) Chen and Quanfu Fan and Rameswar Panda},
booktitle={International Conference on Computer Vision (ICCV)},
year={2021}
}
Paper l... | 22,472 | 42.217308 | 119 | py |
RandStainNA | RandStainNA-master/classification/timm/models/beit.py | """ BEIT: BERT Pre-Training of Image Transformers (https://arxiv.org/abs/2106.08254)
Model from official source: https://github.com/microsoft/unilm/tree/master/beit
At this point only the 1k fine-tuned classification weights and model configs have been added,
see original source above for pre-training models and proc... | 18,558 | 43.505995 | 113 | py |
RandStainNA | RandStainNA-master/classification/timm/models/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... | 3,441 | 44.289474 | 118 | py |
RandStainNA | RandStainNA-master/classification/timm/models/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... | 10,662 | 44.568376 | 117 | py |
RandStainNA | RandStainNA-master/classification/timm/models/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
"""
import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
from .padding import get_padding
class ... | 1,591 | 36.023256 | 106 | py |
RandStainNA | RandStainNA-master/classification/timm/models/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 torch import nn as nn
from .create_conv2d... | 2,528 | 33.175676 | 110 | py |
RandStainNA | RandStainNA-master/classification/timm/models/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:... | 5,887 | 42.940299 | 109 | py |
RandStainNA | RandStainNA-master/classification/timm/models/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... | 1,843 | 34.461538 | 99 | py |
RandStainNA | RandStainNA-master/classification/timm/models/layers/weight_init.py | import torch
import math
import warnings
from torch.nn.init import _calculate_fan_in_and_fan_out
def _no_grad_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/presentations/trun... | 3,324 | 35.944444 | 93 | py |
RandStainNA | RandStainNA-master/classification/timm/models/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
"""... | 6,866 | 36.52459 | 113 | py |
RandStainNA | RandStainNA-master/classification/timm/models/layers/squeeze_excite.py | """ Squeeze-and-Excitation Channel Attention
An SE implementation originally based on PyTorch SE-Net impl.
Has since evolved with additional functionality / configuration.
Paper: `Squeeze-and-Excitation Networks` - https://arxiv.org/abs/1709.01507
Also included is Effective Squeeze-Excitation (ESE).
Paper: `CenterMa... | 3,018 | 39.253333 | 102 | py |
RandStainNA | RandStainNA-master/classification/timm/models/layers/norm.py | """ Normalization layers and wrappers
"""
import torch
import torch.nn as nn
import torch.nn.functional as F
class GroupNorm(nn.GroupNorm):
def __init__(self, num_channels, num_groups=32, eps=1e-5, affine=True):
# NOTE num_channels is swapped to first arg for consistency in swapping norm layers with BN
... | 876 | 34.08 | 111 | py |
RandStainNA | RandStainNA-master/classification/timm/models/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:... | 6,209 | 41.534247 | 154 | py |
RandStainNA | RandStainNA-master/classification/timm/models/layers/evo_norm.py | """EvoNormB0 (Batched) and EvoNormS0 (Sample) in PyTorch
An attempt at getting decent performing EvoNorms running in PyTorch.
While currently faster than other impl, still quite a ways off the built-in BN
in terms of memory usage and throughput (roughly 5x mem, 1/2 - 1/3x speed).
Still very much a WIP, fiddling with ... | 3,519 | 41.926829 | 111 | py |
RandStainNA | RandStainNA-master/classification/timm/models/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... | 3,045 | 40.162162 | 106 | py |
RandStainNA | RandStainNA-master/classification/timm/models/layers/create_act.py | """ Activation Factory
Hacked together by / Copyright 2020 Ross Wightman
"""
from typing import Union, Callable, Type
from .activations import *
from .activations_jit import *
from .activations_me import *
from .config import is_exportable, is_scriptable, is_no_jit
# PyTorch has an optimized, native 'silu' (aka 'swis... | 5,359 | 33.805195 | 105 | py |
RandStainNA | RandStainNA-master/classification/timm/models/layers/mlp.py | """ MLP module w/ dropout and configurable activation layer
Hacked together by / Copyright 2020 Ross Wightman
"""
from torch import nn as nn
from .helpers import to_2tuple
class Mlp(nn.Module):
""" MLP as used in Vision Transformer, MLP-Mixer and related networks
"""
def __init__(self, in_features, hidd... | 4,097 | 33.15 | 117 | py |
RandStainNA | RandStainNA-master/classification/timm/models/layers/trace_utils.py | try:
from torch import _assert
except ImportError:
def _assert(condition: bool, message: str):
assert condition, message
def _float_to_int(x: float) -> int:
"""
Symbolic tracing helper to substitute for inbuilt `int`.
Hint: Inbuilt `int` can't accept an argument of type `Proxy`
"""
... | 335 | 23 | 64 | py |
RandStainNA | RandStainNA-master/classification/timm/models/layers/bottleneck_attn.py | """ Bottleneck Self Attention (Bottleneck Transformers)
Paper: `Bottleneck Transformers for Visual Recognition` - https://arxiv.org/abs/2101.11605
@misc{2101.11605,
Author = {Aravind Srinivas and Tsung-Yi Lin and Niki Parmar and Jonathon Shlens and Pieter Abbeel and Ashish Vaswani},
Title = {Bottleneck Transformers f... | 6,895 | 42.64557 | 118 | py |
RandStainNA | RandStainNA-master/classification/timm/models/layers/classifier.py | """ Classifier head and layer factory
Hacked together by / Copyright 2020 Ross Wightman
"""
from torch import nn as nn
from torch.nn import functional as F
from .adaptive_avgmax_pool import SelectAdaptivePool2d
def _create_pool(num_features, num_classes, pool_type='avg', use_conv=False):
flatten_in_pool = not u... | 2,231 | 39.581818 | 111 | py |
RandStainNA | RandStainNA-master/classification/timm/models/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... | 5,129 | 40.707317 | 119 | py |
RandStainNA | RandStainNA-master/classification/timm/models/layers/patch_embed.py | """ Image to Patch Embedding using Conv2d
A convolution based approach to patchifying a 2D image w/ embedding projection.
Based on the impl in https://github.com/google-research/vision_transformer
Hacked together by / Copyright 2020 Ross Wightman
"""
from torch import nn as nn
from .helpers import to_2tuple
from .t... | 1,490 | 36.275 | 110 | py |
RandStainNA | RandStainNA-master/classification/timm/models/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... | 5,941 | 43.343284 | 118 | py |
RandStainNA | RandStainNA-master/classification/timm/models/layers/gather_excite.py | """ Gather-Excite Attention Block
Paper: `Gather-Excite: Exploiting Feature Context in CNNs` - https://arxiv.org/abs/1810.12348
Official code here, but it's only partial impl in Caffe: https://github.com/hujie-frank/GENet
I've tried to support all of the extent both w/ and w/o params. I don't believe I've seen anoth... | 3,824 | 41.032967 | 120 | py |
RandStainNA | RandStainNA-master/classification/timm/models/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 .padding import pad_same, get_padding_value
def conv2d_same(
x, weight: torch.Tensor, bias: Optional[torch.Tensor] = Non... | 1,490 | 33.674419 | 108 | py |
RandStainNA | RandStainNA-master/classification/timm/models/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... | 3,890 | 31.697479 | 111 | py |
RandStainNA | RandStainNA-master/classification/timm/models/layers/conv_bn_act.py | """ Conv2d + BN + Act
Hacked together by / Copyright 2020 Ross Wightman
"""
from torch import nn as nn
from .create_conv2d import create_conv2d
from .create_norm_act import convert_norm_act
class ConvBnAct(nn.Module):
def __init__(self, in_channels, out_channels, kernel_size=1, stride=1, padding='', dilation=1,... | 1,404 | 33.268293 | 108 | py |
RandStainNA | RandStainNA-master/classification/timm/models/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 &... | 743 | 36.2 | 89 | py |
RandStainNA | RandStainNA-master/classification/timm/models/layers/config.py | """ Model / Layer Config singleton state
"""
from typing import Any, Optional
__all__ = [
'is_exportable', 'is_scriptable', 'is_no_jit',
'set_exportable', 'set_scriptable', 'set_no_jit', 'set_layer_config'
]
# Set to True if prefer to have layers with no jit optimization (includes activations)
_NO_JIT = False... | 3,069 | 25.465517 | 102 | py |
RandStainNA | RandStainNA-master/classification/timm/models/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... | 4,418 | 38.106195 | 106 | py |
RandStainNA | RandStainNA-master/classification/timm/models/layers/activations_jit.py | """ Activations
A collection of jit-scripted activations fn and modules with a common interface so that they can
easily be swapped. All have an `inplace` arg even if not used.
All jit scripted activations are lacking in-place variations on purpose, scripted kernel fusion does not
currently work across in-place op bou... | 2,529 | 26.802198 | 107 | py |
RandStainNA | RandStainNA-master/classification/timm/models/layers/activations_me.py | """ Activations (memory-efficient w/ custom autograd)
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.
These activations are not compatible with jit scripting or ONNX export of the model, please use either
the JIT or bas... | 5,886 | 25.881279 | 163 | py |
RandStainNA | RandStainNA-master/classification/timm/models/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
"""
import torch
impor... | 3,085 | 34.883721 | 106 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.