Skip to main content

Image classification models. Keras.

Project description

Classification models Zoo

Pretrained classification models for Keras

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 ResNet18
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 = ResNet18(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 ResNet18

# prepare your data
X = ...
y = ...

n_classes = 10

# build model
base_model = ResNet18(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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

image_classifiers-0.1.0rc0.tar.gz (8.9 kB view hashes)

Uploaded Source

Built Distribution

image_classifiers-0.1.0rc0-py2.py3-none-any.whl (12.5 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page