Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

image-classifiers

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

image-classifiers

Image classification models. Keras.

  • 1.0.0
  • PyPI
  • Socket score

Maintainers
1

PyPI version Build Status

Classification models Zoo - Keras (and TensorFlow Keras)

Trained on ImageNet classification models. The library is designed to work both with Keras and TensorFlow Keras. See example below.

Important!

There was a huge library update 05 of August. Now classification-models works with both frameworks: keras and tensorflow.keras. If you have models, trained before that date, to load them, please, use image-classifiers (PyPI package name) of 0.2.2 version. You can roll back using pip install -U image-classifiers==0.2.2.

Architectures:

Specification

The top-k accuracy were obtained using center single crop on the 2012 ILSVRC ImageNet validation set and may differ from the original ones. The input size used was 224x224 (min size 256) for all models except:

  • NASNetLarge 331x331 (352)
  • InceptionV3 299x299 (324)
  • InceptionResNetV2 299x299 (324)
  • Xception 299x299 (324)

The inference *Time was evaluated on 500 batches of size 16. All models have been tested using same hardware and software. Time is listed just for comparison of performance.

ModelAcc@1Acc@5Time*Source
vgg1670.7989.7424.95keras
vgg1970.8989.6924.95keras
resnet1868.2488.4916.07mxnet
resnet3472.1790.7417.37mxnet
resnet5074.8192.3822.62mxnet
resnet10176.5893.1033.03mxnet
resnet15276.6693.0842.37mxnet
resnet50v269.7389.3119.56keras
resnet101v271.9390.4128.80keras
resnet152v272.2990.6141.09keras
resnext5077.3693.4837.57keras
resnext10178.4894.0060.07keras
densenet12174.6792.0427.66keras
densenet16975.8592.9333.71keras
densenet20177.1393.4342.40keras
inceptionv377.5593.4838.94keras
xception78.8794.2042.18keras
inceptionresnetv280.0394.8954.77keras
seresnet1869.4188.8420.19pytorch
seresnet3472.6090.9122.20pytorch
seresnet5076.4493.0223.64pytorch
seresnet10177.9294.0032.55pytorch
seresnet15278.3494.0847.88pytorch
seresnext5078.7494.3038.29pytorch
seresnext10179.8894.8762.80pytorch
senet15481.0695.24137.36pytorch
nasnetlarge82.1295.72116.53keras
nasnetmobile74.0491.5427.73keras
mobilenet70.3689.3915.50keras
mobilenetv271.6390.3518.31keras

Weights

NameClassesModels
'imagenet'1000all models
'imagenet11k-place365ch'11586resnet50
'imagenet11k'11221resnet152

Installation

Requirements:

  • Keras >= 2.2.0 / TensorFlow >= 1.12
  • keras_applications >= 1.0.7
Note
This library does not have TensorFlow in a requirements for installation. 
Please, choose suitable version (‘cpu’/’gpu’) and install it manually using 
official Guide (https://www.tensorflow.org/install/).

PyPI stable package:

$ pip install image-classifiers==0.2.2

PyPI latest package:

$ pip install image-classifiers==1.0.0b1

Latest version:

$ pip install git+https://github.com/qubvel/classification_models.git

Examples

Loading model with imagenet weights:
# for keras
from classification_models.keras import Classifiers

# for tensorflow.keras
# from classification_models.tfkeras import Classifiers

ResNet18, preprocess_input = Classifiers.get('resnet18')
model = ResNet18((224, 224, 3), weights='imagenet')

This way take one additional line of code, however if you would like to train several models you do not need to import them directly, just access everything through Classifiers.

You can get all model names using Classifiers.models_names() method.

Inference example:
import numpy as np
from skimage.io import imread
from skimage.transform import resize
from keras.applications.imagenet_utils import decode_predictions
from classification_models.keras import Classifiers

ResNet18, preprocess_input = Classifiers.get('resnet18')

# read and prepare image
x = imread('./imgs/tests/seagull.jpg')
x = resize(x, (224, 224)) * 255    # cast back to 0-255 range
x = preprocess_input(x)
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.keras import Classifiers

ResNet18, preprocess_input = Classifiers.get('resnet18')

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

X = preprocess_input(X)

n_classes = 10

# build model
base_model = ResNet18(input_shape=(224,224,3), weights='imagenet', include_top=False)
x = keras.layers.GlobalAveragePooling2D()(base_model.output)
output = keras.layers.Dense(n_classes, activation='softmax')(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)

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc