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 |
|---|---|---|---|---|---|---|---|---|
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/res2net.py | interfuser/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... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/hub.py | interfuser/timm/models/hub.py | import json
import logging
import os
from functools import partial
from typing import Union, Optional
import torch
from torch.hub import (
load_state_dict_from_url,
download_url_to_file,
urlparse,
HASH_REGEX,
)
try:
from torch.hub import get_dir
except ImportError:
from torch.hub import _get_t... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/gather_excite.py | interfuser/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... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/eca.py | interfuser/timm/models/layers/eca.py | """
ECA module from ECAnet
paper: ECA-Net: Efficient Channel Attention for Deep Convolutional Neural Networks
https://arxiv.org/abs/1910.03151
Original ECA model borrowed from https://github.com/BangguWu/ECANet
Modified circular ECA implementation and adaption for use in timm package
by Chris Ha https://github.com/V... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/test_time_pool.py | interfuser/timm/models/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... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/halo_attn.py | interfuser/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... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/create_act.py | interfuser/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... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/weight_init.py | interfuser/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... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/activations_me.py | interfuser/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... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/squeeze_excite.py | interfuser/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... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/create_norm_act.py | interfuser/timm/models/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... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/norm_act.py | interfuser/timm/models/layers/norm_act.py | """ Normalization + Activation Layers
"""
import torch
from torch import nn as nn
from torch.nn import functional as F
from .create_act import get_act_layer
class BatchNormAct2d(nn.BatchNorm2d):
"""BatchNorm + Activation
This module performs BatchNorm + Activation in a manner that will remain backwards
... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/bottleneck_attn.py | interfuser/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... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/drop.py | interfuser/timm/models/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... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/non_local_attn.py | interfuser/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:... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/median_pool.py | interfuser/timm/models/layers/median_pool.py | """ Median Pool
Hacked together by / Copyright 2020 Ross Wightman
"""
import torch.nn as nn
import torch.nn.functional as F
from .helpers import to_2tuple, to_4tuple
class MedianPool2d(nn.Module):
"""Median pool (usable as median filter when stride=1) module.
Args:
kernel_size: size of pooling kerne... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/mlp.py | interfuser/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
class Mlp(nn.Module):
"""MLP as used in Vision Transformer, MLP-Mixer and related networks"""
def __init__(
self,
in_features,
hidden_features=... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/blur_pool.py | interfuser/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 ... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/inplace_abn.py | interfuser/timm/models/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,
momentu... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/global_context.py | interfuser/timm/models/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 torch import nn as nn
import torc... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/cbam.py | interfuser/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... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/cond_conv2d.py | interfuser/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... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/selective_kernel.py | interfuser/timm/models/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 ConvBnAct
from .helpers import make_divisible
def _kernel_valid(k):
if isinstance... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/split_attn.py | interfuser/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... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/helpers.py | interfuser/timm/models/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):
return x
return tuple(repeat(x, n))
return parse
... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/create_conv2d.py | interfuser/timm/models/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 implementati... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/space_to_depth.py | interfuser/timm/models/layers/space_to_depth.py | import torch
import torch.nn as nn
class SpaceToDepth(nn.Module):
def __init__(self, block_size=4):
super().__init__()
assert block_size == 4
self.bs = block_size
def forward(self, x):
N, C, H, W = x.size()
x = x.view(
N, C, H // self.bs, self.bs, W // self... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/conv2d_same.py | interfuser/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] =... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/lambda_layer.py | interfuser/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... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/separable_conv.py | interfuser/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... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/std_conv.py | interfuser/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:... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/config.py | interfuser/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 activat... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/create_attn.py | interfuser/timm/models/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 .eca import EcaModule, CecaModule
from .gather_excite import GatherExcite
from .global_context import Gl... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/norm.py | interfuser/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, eps=1e-5, affine=True):
# NOTE num_channels is swapped to first arg for consistency in swapping norm layers with BN
... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/pool2d_same.py | interfuser/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:... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/__init__.py | interfuser/timm/models/layers/__init__.py | from .activations import *
from .adaptive_avgmax_pool import (
adaptive_avgmax_pool2d,
select_adaptive_pool2d,
AdaptiveAvgMaxPool2d,
SelectAdaptivePool2d,
)
from .blur_pool import BlurPool2d
from .classifier import ClassifierHead, create_classifier
from .cond_conv2d import CondConv2d, get_condconv_initi... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/activations_jit.py | interfuser/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... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/adaptive_avgmax_pool.py | interfuser/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... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/patch_embed.py | interfuser/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
clas... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/mixed_conv2d.py | interfuser/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... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/evo_norm.py | interfuser/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 ... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/conv_bn_act.py | interfuser/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,
... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/linear.py | interfuser/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 &... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/classifier.py | interfuser/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
from .linear import Linear
def _create_pool(num_features, num_classes, pool_type="avg", use_conv=False):
... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/involution.py | interfuser/timm/models/layers/involution.py | """ PyTorch Involution Layer
Official impl: https://github.com/d-li14/involution/blob/main/cls/mmcls/models/utils/involution_naive.py
Paper: `Involution: Inverting the Inherence of Convolution for Visual Recognition` - https://arxiv.org/abs/2103.06255
"""
import torch.nn as nn
from .conv_bn_act import ConvBnAct
from .... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/swin_attn.py | interfuser/timm/models/layers/swin_attn.py | """ Shifted Window Attn
This is a WIP experiment to apply windowed attention from the Swin Transformer
to a stand-alone module for use as an attn block in conv nets.
Based on original swin window code at https://github.com/microsoft/Swin-Transformer
Swin Transformer paper: https://arxiv.org/pdf/2103.14030.pdf
"""
fro... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/split_batchnorm.py | interfuser/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... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/activations.py | interfuser/timm/models/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 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/models/layers/padding.py | interfuser/timm/models/layers/padding.py | """ Padding Helpers
Hacked together by / Copyright 2020 Ross Wightman
"""
import math
from typing import List, Tuple
import torch.nn.functional as F
# Calculate symmetric padding for a convolution
def get_padding(kernel_size: int, stride: int = 1, dilation: int = 1, **_) -> int:
padding = ((stride - 1) + dilati... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/optim/nvnovograd.py | interfuser/timm/optim/nvnovograd.py | """ Nvidia NovoGrad Optimizer.
Original impl by Nvidia from Jasper example:
- https://github.com/NVIDIA/DeepLearningExamples/blob/master/PyTorch/SpeechRecognition/Jasper
Paper: `Stochastic Gradient Methods with Layer-wise Adaptive Moments for Training of Deep Networks`
- https://arxiv.org/abs/1905.11286
"""
im... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/optim/sgdp.py | interfuser/timm/optim/sgdp.py | """
SGDP Optimizer Implementation copied from https://github.com/clovaai/AdamP/blob/master/adamp/sgdp.py
Paper: `Slowing Down the Weight Norm Increase in Momentum-based Optimizers` - https://arxiv.org/abs/2006.08217
Code: https://github.com/clovaai/AdamP
Copyright (c) 2020-present NAVER Corp.
MIT license
"""
import ... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/optim/radam.py | interfuser/timm/optim/radam.py | """RAdam Optimizer.
Implementation lifted from: https://github.com/LiyuanLucasLiu/RAdam
Paper: `On the Variance of the Adaptive Learning Rate and Beyond` - https://arxiv.org/abs/1908.03265
"""
import math
import torch
from torch.optim.optimizer import Optimizer
class RAdam(Optimizer):
def __init__(self, params, l... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/optim/optim_factory.py | interfuser/timm/optim/optim_factory.py | """ Optimizer Factory w/ Custom Weight Decay
Hacked together by / Copyright 2021 Ross Wightman
"""
from typing import Optional
import torch
import torch.nn as nn
import torch.optim as optim
from .adabelief import AdaBelief
from .adafactor import Adafactor
from .adahessian import Adahessian
from .adamp import AdamP
fr... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/optim/adamw.py | interfuser/timm/optim/adamw.py | """ AdamW Optimizer
Impl copied from PyTorch master
NOTE: Builtin optim.AdamW is used by the factory, this impl only serves as a Python based reference, will be removed
someday
"""
import math
import torch
from torch.optim.optimizer import Optimizer
class AdamW(Optimizer):
r"""Implements AdamW algorithm.
Th... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/optim/madgrad.py | interfuser/timm/optim/madgrad.py | """ PyTorch MADGRAD optimizer
MADGRAD: https://arxiv.org/abs/2101.11075
Code from: https://github.com/facebookresearch/madgrad
"""
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import ma... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/optim/lars.py | interfuser/timm/optim/lars.py | """ PyTorch LARS / LARC Optimizer
An implementation of LARS (SGD) + LARC in PyTorch
Based on:
* PyTorch SGD: https://github.com/pytorch/pytorch/blob/1.7/torch/optim/sgd.py#L100
* NVIDIA APEX LARC: https://github.com/NVIDIA/apex/blob/master/apex/parallel/LARC.py
Additional cleanup and modifications to properly su... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/optim/adabelief.py | interfuser/timm/optim/adabelief.py | import math
import torch
from torch.optim.optimizer import Optimizer
class AdaBelief(Optimizer):
r"""Implements AdaBelief algorithm. Modified from Adam in PyTorch
Arguments:
params (iterable): iterable of parameters to optimize or dicts defining
parameter groups
lr (float, optiona... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/optim/nadam.py | interfuser/timm/optim/nadam.py | import math
import torch
from torch.optim.optimizer import Optimizer
class Nadam(Optimizer):
"""Implements Nadam algorithm (a variant of Adam based on Nesterov momentum).
It has been proposed in `Incorporating Nesterov Momentum into Adam`__.
Arguments:
params (iterable): iterable of parameters ... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/optim/adahessian.py | interfuser/timm/optim/adahessian.py | """ AdaHessian Optimizer
Lifted from https://github.com/davda54/ada-hessian/blob/master/ada_hessian.py
Originally licensed MIT, Copyright 2020, David Samuel
"""
import torch
class Adahessian(torch.optim.Optimizer):
"""
Implements the AdaHessian algorithm from "ADAHESSIAN: An Adaptive Second OrderOptimizer fo... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/optim/__init__.py | interfuser/timm/optim/__init__.py | from .adabelief import AdaBelief
from .adafactor import Adafactor
from .adahessian import Adahessian
from .adamp import AdamP
from .adamw import AdamW
from .lamb import Lamb
from .lars import Lars
from .lookahead import Lookahead
from .madgrad import MADGRAD
from .nadam import Nadam
from .nvnovograd import NvNovoGrad
f... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/optim/lookahead.py | interfuser/timm/optim/lookahead.py | """ Lookahead Optimizer Wrapper.
Implementation modified from: https://github.com/alphadl/lookahead.pytorch
Paper: `Lookahead Optimizer: k steps forward, 1 step back` - https://arxiv.org/abs/1907.08610
Hacked together by / Copyright 2020 Ross Wightman
"""
import torch
from torch.optim.optimizer import Optimizer
from c... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/optim/rmsprop_tf.py | interfuser/timm/optim/rmsprop_tf.py | """ RMSProp modified to behave like Tensorflow impl
Originally cut & paste from PyTorch RMSProp
https://github.com/pytorch/pytorch/blob/063946d2b3f3f1e953a2a3b54e0b34f1393de295/torch/optim/rmsprop.py
Licensed under BSD-Clause 3 (ish), https://github.com/pytorch/pytorch/blob/master/LICENSE
Modifications Copyright 2021... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/optim/adafactor.py | interfuser/timm/optim/adafactor.py | """ Adafactor Optimizer
Lifted from https://github.com/pytorch/fairseq/blob/master/fairseq/optim/adafactor.py
Original header/copyright below.
"""
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/optim/adamp.py | interfuser/timm/optim/adamp.py | """
AdamP Optimizer Implementation copied from https://github.com/clovaai/AdamP/blob/master/adamp/adamp.py
Paper: `Slowing Down the Weight Norm Increase in Momentum-based Optimizers` - https://arxiv.org/abs/2006.08217
Code: https://github.com/clovaai/AdamP
Copyright (c) 2020-present NAVER Corp.
MIT license
"""
impor... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/optim/lamb.py | interfuser/timm/optim/lamb.py | """ PyTorch Lamb optimizer w/ behaviour similar to NVIDIA FusedLamb
This optimizer code was adapted from the following (starting with latest)
* https://github.com/HabanaAI/Model-References/blob/2b435114fe8e31f159b1d3063b8280ae37af7423/PyTorch/nlp/bert/pretraining/lamb.py
* https://github.com/NVIDIA/DeepLearningExample... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/utils/cuda.py | interfuser/timm/utils/cuda.py | """ CUDA / AMP utils
Hacked together by / Copyright 2020 Ross Wightman
"""
import torch
try:
from apex import amp
has_apex = True
except ImportError:
amp = None
has_apex = False
from .clip_grad import dispatch_clip_grad
class ApexScaler:
state_dict_key = "amp"
def __call__(
self,
... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/utils/metrics.py | interfuser/timm/utils/metrics.py | """ Eval metrics and related
Hacked together by / Copyright 2020 Ross Wightman
"""
class AverageMeter:
"""Computes and stores the average and current value"""
def __init__(self):
self.reset()
def reset(self):
self.val = 0
self.avg = 0
self.sum = 0
self.count = 0
... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/utils/model_ema.py | interfuser/timm/utils/model_ema.py | """ Exponential Moving Average (EMA) of model updates
Hacked together by / Copyright 2020 Ross Wightman
"""
import logging
from collections import OrderedDict
from copy import deepcopy
import torch
import torch.nn as nn
_logger = logging.getLogger(__name__)
class ModelEma:
"""Model Exponential Moving Average (... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/utils/carla_metrics.py | interfuser/timm/utils/carla_metrics.py | """ Eval metrics and related
Hacked together by / Copyright 2020 Ross Wightman
"""
import torch
def l1_accuracy(output, target):
"""Computes the accuracy over the k top predictions for the specified values of k"""
batch_size = target.size(0)
length = target.size(1)
return torch.sum(torch.abs(output -... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/utils/model.py | interfuser/timm/utils/model.py | """ Model / state_dict utils
Hacked together by / Copyright 2020 Ross Wightman
"""
from .model_ema import ModelEma
import torch
import fnmatch
def unwrap_model(model):
if isinstance(model, ModelEma):
return unwrap_model(model.ema)
else:
return model.module if hasattr(model, "module") else mod... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/utils/clip_grad.py | interfuser/timm/utils/clip_grad.py | import torch
from timm.utils.agc import adaptive_clip_grad
def dispatch_clip_grad(
parameters, value: float, mode: str = "norm", norm_type: float = 2.0
):
"""Dispatch to gradient clipping method
Args:
parameters (Iterable): model parameters to clip
value (float): clipping value/factor/no... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/utils/summary.py | interfuser/timm/utils/summary.py | """ Summary utilities
Hacked together by / Copyright 2020 Ross Wightman
"""
import csv
import os
from collections import OrderedDict
try:
import wandb
except ImportError:
pass
def get_outdir(path, *paths, inc=False):
outdir = os.path.join(path, *paths)
if not os.path.exists(outdir):
os.maked... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/utils/checkpoint_saver.py | interfuser/timm/utils/checkpoint_saver.py | """ Checkpoint Saver
Track top-n training checkpoints and maintain recovery checkpoints on specified intervals.
Hacked together by / Copyright 2020 Ross Wightman
"""
import glob
import operator
import os
import logging
import torch
from .model import unwrap_model, get_state_dict
_logger = logging.getLogger(__nam... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/utils/log.py | interfuser/timm/utils/log.py | """ Logging helpers
Hacked together by / Copyright 2020 Ross Wightman
"""
import logging
import logging.handlers
class FormatterNoInfo(logging.Formatter):
def __init__(self, fmt="%(levelname)s: %(message)s"):
logging.Formatter.__init__(self, fmt)
def format(self, record):
if record.levelno =... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/utils/jit.py | interfuser/timm/utils/jit.py | """ JIT scripting/tracing utils
Hacked together by / Copyright 2020 Ross Wightman
"""
import torch
def set_jit_legacy():
"""Set JIT executor to legacy w/ support for op fusion
This is hopefully a temporary need in 1.5/1.5.1/1.6 to restore performance due to changes
in the JIT exectutor. These API are not... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/utils/distributed.py | interfuser/timm/utils/distributed.py | """ Distributed training/validation utils
Hacked together by / Copyright 2020 Ross Wightman
"""
import torch
from torch import distributed as dist
from .model import unwrap_model
def reduce_tensor(tensor, n):
rt = tensor.clone()
dist.all_reduce(rt, op=dist.ReduceOp.SUM)
rt /= n
return rt
def distr... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/utils/misc.py | interfuser/timm/utils/misc.py | """ Misc utils
Hacked together by / Copyright 2020 Ross Wightman
"""
import re
def natural_key(string_):
"""See http://www.codinghorror.com/blog/archives/001018.html"""
return [int(s) if s.isdigit() else s for s in re.split(r"(\d+)", string_.lower())]
def add_bool_arg(parser, name, default=False, help=""):... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/utils/random.py | interfuser/timm/utils/random.py | import random
import numpy as np
import torch
def random_seed(seed=42, rank=0):
torch.manual_seed(seed + rank)
np.random.seed(seed + rank)
random.seed(seed + rank)
| python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/utils/__init__.py | interfuser/timm/utils/__init__.py | from .agc import adaptive_clip_grad
from .checkpoint_saver import CheckpointSaver
from .clip_grad import dispatch_clip_grad
from .cuda import ApexScaler, NativeScaler
from .distributed import distribute_bn, reduce_tensor
from .jit import set_jit_legacy
from .log import setup_default_logging, FormatterNoInfo
from .metri... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/utils/agc.py | interfuser/timm/utils/agc.py | """ Adaptive Gradient Clipping
An impl of AGC, as per (https://arxiv.org/abs/2102.06171):
@article{brock2021high,
author={Andrew Brock and Soham De and Samuel L. Smith and Karen Simonyan},
title={High-Performance Large-Scale Image Recognition Without Normalization},
journal={arXiv preprint arXiv:},
year={2021... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/scheduler/scheduler_factory.py | interfuser/timm/scheduler/scheduler_factory.py | """ Scheduler Factory
Hacked together by / Copyright 2020 Ross Wightman
"""
from .cosine_lr import CosineLRScheduler
from .tanh_lr import TanhLRScheduler
from .step_lr import StepLRScheduler
from .plateau_lr import PlateauLRScheduler
from .multistep_lr import MultiStepLRScheduler
def create_scheduler(args, optimizer)... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/scheduler/plateau_lr.py | interfuser/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... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/scheduler/step_lr.py | interfuser/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,
decay_t: flo... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/scheduler/multistep_lr.py | interfuser/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,
decay... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/scheduler/__init__.py | interfuser/timm/scheduler/__init__.py | from .cosine_lr import CosineLRScheduler
from .plateau_lr import PlateauLRScheduler
from .step_lr import StepLRScheduler
from .tanh_lr import TanhLRScheduler
from .scheduler_factory import create_scheduler
| python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/scheduler/tanh_lr.py | interfuser/timm/scheduler/tanh_lr.py | """ TanH Scheduler
TanH schedule with warmup, cycle/restarts, noise.
Hacked together by / Copyright 2020 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... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/scheduler/scheduler.py | interfuser/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 increm... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/scheduler/cosine_lr.py | interfuser/timm/scheduler/cosine_lr.py | """ Cosine Scheduler
Cosine LR schedule with warmup, cycle/restarts, noise.
Hacked together by / Copyright 2020 Ross Wightman
"""
import logging
import math
import numpy as np
import torch
from .scheduler import Scheduler
_logger = logging.getLogger(__name__)
class CosineLRScheduler(Scheduler):
"""
Cosin... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/data/distributed_sampler.py | interfuser/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 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/data/real_labels.py | interfuser/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
class RealLabelsImagenet:
d... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/data/base_io_dataset.py | interfuser/timm/data/base_io_dataset.py | import io
import json
import os
import logging
import numpy as np
from PIL import Image
import torch
_logger = logging.getLogger(__name__)
class BaseIODataset(torch.utils.data.Dataset):
def __init__(self, root=''):
self.root_path = root
def _load_text(self, path):
text = open(self.root_path... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/data/auto_augment.py | interfuser/timm/data/auto_augment.py | """ AutoAugment, RandAugment, and AugMix 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/autoaugment.p... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/data/det_utils.py | interfuser/timm/data/det_utils.py | import math
import json
import os
import copy
from tqdm import tqdm
from PIL import Image
import cv2
import numpy as np
from skimage.measure import block_reduce
from .heatmap_utils import generate_heatmap, get_yaw_angle
def convert_grid_to_xy(i, j):
x = j - 9.5
y = 17.5 - i
return x, y
def generate_de... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/data/loader.py | interfuser/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 2020 Ross Wightman
"""
import torch.utils.data
import nu... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/data/constants.py | interfuser/timm/data/constants.py | DEFAULT_CROP_PCT = 0.875
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 / (0.0167 * 255)] * 3)
| python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/data/heatmap_utils.py | interfuser/timm/data/heatmap_utils.py | import math
import json
import os
from tqdm import tqdm
from PIL import Image
import cv2
import numpy as np
# VALUES = [255, 150, 120, 90, 60, 30][::-1]
# EXTENT = [0, 0.2, 0.4, 0.6, 0.8, 1.0][::-1]
VALUES = [255]
EXTENT = [0]
def add_rect(img, loc, ori, box, value, pixels_per_meter, max_distance, color):
im... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/data/dataset.py | interfuser/timm/data/dataset.py | """ Quick n Simple Image Folder, Tarfile based DataSet
Hacked together by / Copyright 2020 Ross Wightman
"""
import torch.utils.data as data
import os
import torch
import logging
from PIL import Image
from .parsers import create_parser
_logger = logging.getLogger(__name__)
_ERROR_RETRY = 50
class ImageDataset(da... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/data/carla_loader.py | interfuser/timm/data/carla_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 2020 Ross Wightman
"""
import torch.utils.data
import nu... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/data/transforms_factory.py | interfuser/timm/data/transforms_factory.py | """ Transforms Factory
Factory methods for building image transforms for use with TIMM (PyTorch Image Models)
Hacked together by / Copyright 2020 Ross Wightman
"""
import math
import torch
from torchvision import transforms
from timm.data.constants import (
IMAGENET_DEFAULT_MEAN,
IMAGENET_DEFAULT_STD,
DEF... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
tulerfeng/PlanKD | https://github.com/tulerfeng/PlanKD/blob/7b6f542ad2b173f20d8baa0f78f83f652065d5ff/interfuser/timm/data/transforms_carla_factory.py | interfuser/timm/data/transforms_carla_factory.py | """ Transforms Factory
Factory methods for building image transforms for use with TIMM (PyTorch Image Models)
Hacked together by / Copyright 2020 Ross Wightman
"""
import math
import random
import torch
import numpy as np
from torchvision import transforms
from timm.data.constants import IMAGENET_DEFAULT_MEAN, IMAGEN... | python | Apache-2.0 | 7b6f542ad2b173f20d8baa0f78f83f652065d5ff | 2026-01-05T07:09:10.481895Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.