A lightweight library for pre-processing images for pre-trained keras models
Project description
Keras Image Helper
A lightweight library for pre-processing images for pre-trained keras models
Imagine you have a Keras model. To use it, you need to apply a certain pre-processing function to all the images. Something like that:
from tensorflow.keras.applications.xception import preprocess_input
What if you want to now deploy this model to AWS Lambda? Or deploy your model with TF-Serving? You don't want to use the entire TensorFlow package just for that.
The solution is simple - use keras_image_helper
Usage
For an xception model:
from keras_image_helper import create_preprocessor
preprocessor = create_preprocessor('xception', target_size=(299, 299))
url = 'http://bit.ly/mlbookcamp-pants'
X = preprocessor.from_url(url)
It's also possible to provide custom functions instead of preprocessor name:
def custom_function(x):
x = x / 255.0
x = x.round(1)
x.transpose(0, 3, 1, 2)
return x
preprocessor = create_preprocessor(custom_function, target_size=(3, 3))
Now you can use X for your model:
preds = model.predict(X)
That's all :tada:
For more examples, check test.ipynb
Currently you can use the following pre-processors:
xceptionresnet50vgg16inception_v3
If something you need is missing, PRs are welcome
Installation
It's available on PyPI, so you can install it with pip:
pip install keras_image_helper
You can also install the latest version from this repo:
git clone git@github.com:alexeygrigorev/keras-image-helper.git
python setup.py install
Publishing
- Install development dependencies:
uv sync --dev
- Build the package:
uv run hatch build
- Publish to test PyPI:
uv run hatch publish --repo test
- Publish to PyPI:
uv run hatch publish
- Clean up:
rm -r dist/
Note: For Hatch publishing, you'll need to configure your PyPI credentials in ~/.pypirc or use environment variables.
PyPI Credentials Setup
Create a .pypirc file in your home directory with your PyPI credentials:
[distutils]
index-servers =
pypi
testpypi
[pypi]
repository = https://upload.pypi.org/legacy/
username = __token__
password = pypi-your-main-api-token-here
[testpypi]
repository = https://test.pypi.org/legacy/
username = __token__
password = pypi-your-test-api-token-here
Done!
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file keras_image_helper-0.0.2.tar.gz.
File metadata
- Download URL: keras_image_helper-0.0.2.tar.gz
- Upload date:
- Size: 287.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
940f9f349af758c43985f17b9b01f96838e7a28f17548c603d3a926f2995db18
|
|
| MD5 |
c0959d81983494a32f9f378351b86704
|
|
| BLAKE2b-256 |
03d5e7a25cbd3a8be045e812f2ba1a5ebc54aa7fb6ff2509934613ae84995a1a
|
File details
Details for the file keras_image_helper-0.0.2-py3-none-any.whl.
File metadata
- Download URL: keras_image_helper-0.0.2-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf7d6004af56ff37ea52bfa1e0794b69005e4abd227cd79d144b217feb06b947
|
|
| MD5 |
323a3cfe03bc80c6f6202846b0b768dc
|
|
| BLAKE2b-256 |
2be383e38dc41d8e58d01d01dc24353ebb4673f43a43d2ef0bc133574df7022b
|