Skip to main content

keras-image-classification-wrapper

A thin wrapper around keras image classification applications.

Installation

pip install keras-image-classification-wrapper

Usage

def classify(
    image: Union[str, bytes, pillow.Image.Image],
    results: int = 3,
    model: str = INCEPTIONV3,
) -> tuple:

Classify an image.

results has to be less that 5, since keras applications don't give more than five results.

model has to be one of: XCEPTION, VGG16, VGG19, RESNET50, RESNET101, RESNET152, RESNET50V2, RESNET101V2, RESNET152V2, RESNETRS101, RESNETRS152, RESNETRS200, RESNETRS270, RESNETRS350, RESNETRS420, REGNETX002, REGNETX004, REGNETX006, REGNETX008, REGNETX016, REGNETX032, REGNETX040, REGNETX064, REGNETX080, REGNETX120, REGNETX160, REGNETX320, REGNETY002, REGNETY004, REGNETY006, REGNETY008, REGNETY016, REGNETY032, REGNETY040, REGNETY064, REGNETY080, REGNETY120, REGNETY160, REGNETY320, INCEPTIONV3, INCEPTIONRESNETV2, MOBILENET, MOBILENETV2, MOBILENETV3SMALL, MOBILENETV3LARGE, DENSENET121, DENSENET169, DENSENET201, NASNETMOBILE, NASNETLARGE, EFFICIENTNETB0, EFFICIENTNETB1, EFFICIENTNETB2, EFFICIENTNETB3, EFFICIENTNETB4, EFFICIENTNETB5, EFFICIENTNETB6, EFFICIENTNETB7, EFFICIENTNETV2B0, EFFICIENTNETV2B1, EFFICIENTNETV2B2, EFFICIENTNETV2B3, EFFICIENTNETV2S, EFFICIENTNETV2M, EFFICIENTNETV2L. Take a look at model characteristics, if you are not sure, which one to choose.

def load_model(model: str) -> None:

Preload a model.

Loading of desired model is done automatically at the first call of classify. But it can take significant time, if weights need to be downloaded. So you can preload a model.

Usage examples

With local files:

import keras_image_classification as image_classification

file_path = "path/to/image.png"

labels = image_classification.classify(file_path, results = 3,
                                       model = image_classification.INCEPTIONV3)
print(labels)

With byte-like objects (here with requests):

import requests
import keras_image_classification as image_classification

response = requests.get("https://http.cat/100")
assert response.status_code == 200

labels = image_classification.classify(response.content, results = 3,
                                       model = image_classification.INCEPTIONV3)
print(labels)

You can also pass pillow images directly:

import PIL as pillow
import keras_image_classification as image_classification

file_path = "path/to/image.png"
image = pillow.Image.open(file_path)

labels = image_classification.classify(image, results = 3,
                                       model = image_classification.INCEPTIONV3)
print(labels)

Output:

({'imagenet_id': 'n02123394', 'label': 'Persian_cat', 'probability': 0.7993967533111572},
 {'imagenet_id': 'n06359193', 'label': 'web_site', 'probability': 0.03162319213151932},
 {'imagenet_id': 'n03598930', 'label': 'jigsaw_puzzle', 'probability': 0.013497020117938519})

Metadata

Release files for keras-image-classification-wrapper 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for keras-image-classification-wrapper 0.0.3
File Size Uploaded Provenance Actions
keras-image-classification-wrapper-0.0.3.tar.gz 5.3 kB Without provenance Details for keras-image-classification-wrapper-0.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for keras-image-classification-wrapper 0.0.3
File Interpreter ABI Platform Actions
keras_image_classification_wrapper-0.0.3-py3-none-any.whl Python 3 none any Details for keras_image_classification_wrapper-0.0.3-py3-none-any.whl

Total release size: 11.1 kB

Release files / keras-image-classification-wrapper-0.0.3.tar.gz

Download URL keras-image-classification-wrapper-0.0.3.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
213088548e48fc0bcf6712a8f9c91912d4fcd48184fce174fba8c0e6f13632d3
BLAKE2b-256 checksum
How to use checksums
46007064c39adfebe7ee8d465d148fc2a21525fa2dd5193f70b3c65b6a9800f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.5

Release files / keras_image_classification_wrapper-0.0.3-py3-none-any.whl

Download URL keras_image_classification_wrapper-0.0.3-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fbbc30e8569123c600274545de2de9ad38e299988b4b539af628f6059ab4d99b
BLAKE2b-256 checksum
How to use checksums
0fbfcc817b1f3008fb536f78b2cfcb4e708b158e8a87add808f3b1a6496e0110
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.5

Security for keras-image-classification-wrapper 0.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page