Pretrained classification models for Keras modified to use scSE blocks. The weights for scSE blocks are not included (you need to train).
Model | Classes | Weights | No top | Preprocessing |
---|---|---|---|---|
ResNet18 | 1000 | imagenet |
+ | BGR |
ResNet34 | 1000 | imagenet |
+ | BGR |
ResNet50 | 1000 11586 |
imagenet imagenet11k-place365ch |
+ | BGR |
ResNet101 | 1000 | imagenet |
+ | BGR |
ResNet152 | 1000 11221 |
imagenet imagenet11k |
+ | BGR |
ResNeXt50 | 1000 | imagenet |
+ | - |
ResNeXt101 | 1000 | imagenet |
+ | - |
Imagenet inference example:
import numpy as np
from skimage.io import imread
from keras.applications.imagenet_utils import decode_predictions
from classification_models import SCSEResNet18
from classification_models.resnet import preprocess_input
# read and prepare image
x = imread('./imgs/tests/seagull.jpg')
x = preprocess_input(x, size=(224,224))
x = np.expand_dims(x, 0)
# load model
model = SCSEResNet18(input_shape=(224,224,3), weights='imagenet', classes=1000)
# processing image
y = model.predict(x)
# result
print(decode_predictions(y))
Model fine-tuning example:
import keras
from classification_models import SCSEResNet18
# prepare your data
X = ...
y = ...
n_classes = 10
# build model
base_model = SCSEResNet18(input_shape=(224,224,3), weights='imagenet', include_top=False)
x = keras.layers.AveragePooling2D((7,7))(base_model.output)
x = keras.layers.Dropout(0.3)(x)
output = keras.layers.Dense(n_classes)(x)
model = keras.models.Model(inputs=[base_model.input], outputs=[output])
# train
model.compile(optimizer='SGD', loss='categorical_crossentropy', metrics=['accuracy'])
model.fit(X, y)