This repository contains 1D variants of popular CNN models for classification like ResNets, DenseNets, VGG, etc. It also contains weights obtained by converting ImageNet weights from the same 2D models (soon). It can be useful for classification of audio or some timeseries data.
This repository is based on great classification_models repo by @qubvel
- VGG [16, 19]
- ResNet [18, 34, 50, 101, 152]
- ResNeXt [50, 101]
- SE-ResNet [18, 34, 50, 101, 152]
- SE-ResNeXt [50, 101]
- SE-Net [154]
- DenseNet [121, 169, 201]
- Inception ResNet V2
- Inception V3
- MobileNet
- MobileNet v2
- EfficientNet
- EfficientNet v2
pip install classification-models-1D
from classification_models_1D.tfkeras import Classifiers
ResNet18, preprocess_input = Classifiers.get('resnet18')
model = ResNet18(input_shape=(224*224, 2), weights=None)All possible nets for Classifiers.get() method: 'resnet18', 'resnet34', 'resnet50', 'resnet101', 'resnet152', 'seresnet18', 'seresnet34', 'seresnet50', 'seresnet101', 'seresnet152', 'seresnext50', 'seresnext101', 'senet154', 'resnext50', 'resnext101', 'vgg16', 'vgg19', 'densenet121', 'densenet169', 'densenet201', 'mobilenet', 'mobilenetv2', 'inceptionresnetv2', 'inceptionv3', 'EfficientNetB0', 'EfficientNetB1', 'EfficientNetB2', 'EfficientNetB3', 'EfficientNetB4', 'EfficientNetB5', 'EfficientNetB6', 'EfficientNetB7', 'EfficientNetV2B0', 'EfficientNetV2B1', 'EfficientNetV2B2', 'EfficientNetV2B3', 'EfficientNetV2S', 'EfficientNetV2M', 'EfficientNetV2L'
Code to convert 2D imagenet weights to 1D variant is available here: convert_imagenet_weights_to_1D_models.py.
If initial 2D model had shape (224, 224, 3) then you can use shape (W, 3) where W ~= 224*224, so something like
(224*224, 2) will be ok.
- Default pooling/stride size for 1D models set equal to 4 to match (2, 2) pooling for 2D nets. Kernel size by default is 9 to match (3, 3) kernels. You can change it for your needs using parameters
stride_sizeandkernel_size. Example:
from classification_models_1D.tfkeras import Classifiers
ResNet18, preprocess_input = Classifiers.get('resnet18')
model = ResNet18(
input_shape=(224*224, 2),
stride_size=6,
kernel_size=3,
weights=None
)- You can set different pooling for each pooling block. For example you don't need pooling at first convolution.
You can do it using tuple as value for
stride_size:
from classification_models_1D.tfkeras import Classifiers
ResNet18, preprocess_input = Classifiers.get('resnet34')
model = ResNet18(
input_shape=(65536, 2),
stride_size=(1, 4, 4, 8, 8),
kernel_size=9,
weights=None
)- For some models like (resnet, resnext, senet, vgg16, vgg19, densenet) it's possible to change number of blocks/poolings. For example if you want to switch to pooling/stride = 2 but make more poolings overall. You can do it like that:
from classification_models_1D.tfkeras import Classifiers
ResNet18, preprocess_input = Classifiers.get('resnet34')
model = ResNet18(
input_shape=(224*224, 2),
include_top=False,
weights=None,
stride_size=(2, 4, 4, 4, 2, 2, 2, 2),
kernel_size=3,
repetitions=(2, 2, 2, 2, 2, 2, 2),
init_filters=16,
)Note: Since number of filters grows 2 times, you can set initial number of filters with init_filters parameter.
- https://github.com/qubvel/classification_models - original 2D repo
- https://github.com/ZFTurbo/classification_models_3D - 3D variant repo
- Publish imagenet weights converted from 2D version
- Create pretrained weights obtained on AudioSet