Skip to content

edhowler/classification_models

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Classification models Zoo (modified)

Pretrained classification models for Keras modified to use scSE blocks. The weights for scSE blocks are not included (you need to train).

Models:

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 + -

Example

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)

About

Pretrained on ImageNet classification models for Keras

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%