A thin wrapper around keras image classification applications.
Project description
keras-image-classification-wrapper
A thin wrapper around keras image classification applications.
Installation
pip install keras-image-classification-wrapper
Usage
-
</code></pre> </li> </ul> <p>def classify( image: Union[str, bytes, pillow.Image.Image], results: int = 3, model: str = INCEPTIONV3, ) -> tuple:</p> <pre><code> 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`, `INCEPTIONV3`, `INCEPTIONRESNETV2`, `MOBILENET`, `MOBILENETV2`, `DENSENET121`, `DENSENET169`, `DENSENET201`, `NASNETMOBILE`, `NASNETLARGE`, `EFFICIENTNETB0`, `EFFICIENTNETB1`, `EFFICIENTNETB2`, `EFFICIENTNETB3`, `EFFICIENTNETB4`, `EFFICIENTNETB5`, `EFFICIENTNETB6`, `EFFICIENTNETB7`. Take a look at [model characteristics](https://keras.io/api/applications/#available-models), if you are not sure, which one to choose. - ``` python 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:
({'label': 'Persian_cat', 'probability': 0.7992992997169495}, {'label': 'web_site', 'probability': 0.03164924681186676}, {'label': 'jigsaw_puzzle', 'probability': 0.0135102029889822})
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for keras-image-classification-wrapper-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0877a947f7c36cd9d8a0779f8792b19bf8837d43f38a4ef7129c3a505a7359d |
|
MD5 | c664765e10092cadd5bdb3e8174d14ee |
|
BLAKE2b-256 | c198fa76d5302aecfd036917e42f3aa2f2e11400d5471ffcb27ddb74b74269a9 |
Close
Hashes for keras_image_classification_wrapper-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4fcb98a226bcc4e48d5553290e5f78eb7cd320bff4779773250674f156b028e |
|
MD5 | 7f287af43b1b01895e8a4db20727df5d |
|
BLAKE2b-256 | 0a9dd6125457a6b54453c20fb187f0f541b05f87b40abc8c98d8fb3b2ba93700 |