Skip to main content

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:

  • xception
  • resnet50
  • vgg16
  • inception_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

  1. Install development dependencies:
uv sync --dev
  1. Build the package:
uv run hatch build
  1. Publish to test PyPI:
uv run hatch publish --repo test
  1. Publish to PyPI:
uv run hatch publish
  1. 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!

Metadata

Release files for keras-image-helper 0.0.2

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-helper 0.0.2
File Size Uploaded Provenance
keras_image_helper-0.0.2.tar.gz 287.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for keras-image-helper 0.0.2
File Interpreter ABI Platform
keras_image_helper-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 293.1 kB

Release files / keras_image_helper-0.0.2.tar.gz

Download URL keras_image_helper-0.0.2.tar.gz
Size 287.7 kB
Tags Source
SHA-256 checksum
How to use checksums
940f9f349af758c43985f17b9b01f96838e7a28f17548c603d3a926f2995db18
BLAKE2b-256 checksum
How to use checksums
03d5e7a25cbd3a8be045e812f2ba1a5ebc54aa7fb6ff2509934613ae84995a1a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.28.1

Release files / keras_image_helper-0.0.2-py3-none-any.whl

Download URL keras_image_helper-0.0.2-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cf7d6004af56ff37ea52bfa1e0794b69005e4abd227cd79d144b217feb06b947
BLAKE2b-256 checksum
How to use checksums
2be383e38dc41d8e58d01d01dc24353ebb4673f43a43d2ef0bc133574df7022b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.28.1

Security for keras-image-helper 0.0.2

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.

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files No provenance

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