Skip to content

Instantly share code, notes, and snippets.

@gau-nernst
gau-nernst / torchvision_extractor.py
Last active December 22, 2021 13:52
Torchvision feature extractor
from torch import nn
from torchvision.models import resnet, mobilenet, efficientnet
from torchvision.models.feature_extraction import create_feature_extractor
class _Extractor(nn.Module):
def __init__(self, backbone, node_names):
super().__init__()
self.feat_extractor = create_feature_extractor(backbone, node_names)
@gau-nernst
gau-nernst / separable_conv.py
Last active December 21, 2021 06:11
Separable Convolution Block in PyTorch
from torch import nn
class SeparableConv2d(nn.Sequential):
def __init__(self, in_channels, out_channels, kernel_size=3, stride=1, padding=1, dilation=1, norm_layer=None, activation=None):
super().__init__()
if norm_layer is None:
norm_layer = nn.BatchNorm2d
if activation is None:
activation = nn.ReLU6