{"id":15065034,"url":"https://github.com/james77777778/keras-aug","last_synced_at":"2025-04-10T13:08:46.691Z","repository":{"id":164259293,"uuid":"625979318","full_name":"james77777778/keras-aug","owner":"james77777778","description":"A library that includes pure TF/Keras preprocessing and augmentation layers, providing support for various data types such as images, labels, bounding boxes, segmentation masks, and more.","archived":false,"fork":false,"pushed_at":"2023-11-13T12:25:40.000Z","size":688,"stargazers_count":8,"open_issues_count":3,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-04-25T20:20:40.085Z","etag":null,"topics":["augmentation","keras","keras-cv","preprocessing","tensorflow"],"latest_commit_sha":null,"homepage":"https://kerasaug.readthedocs.io/en/latest/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/james77777778.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-04-10T14:36:17.000Z","updated_at":"2024-02-28T12:35:15.000Z","dependencies_parsed_at":"2023-12-19T10:07:54.375Z","dependency_job_id":null,"html_url":"https://github.com/james77777778/keras-aug","commit_stats":{"total_commits":182,"total_committers":1,"mean_commits":182.0,"dds":0.0,"last_synced_commit":"9f6c60d2c19b1c7fe7c8ab80c38842e808e92adf"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/james77777778%2Fkeras-aug","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/james77777778%2Fkeras-aug/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/james77777778%2Fkeras-aug/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/james77777778%2Fkeras-aug/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/james77777778","download_url":"https://codeload.github.com/james77777778/keras-aug/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248224504,"owners_count":21068073,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["augmentation","keras","keras-cv","preprocessing","tensorflow"],"created_at":"2024-09-25T00:29:51.804Z","updated_at":"2025-04-10T13:08:46.673Z","avatar_url":"https://github.com/james77777778.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# KerasAug\n\n\u003c!-- markdownlint-disable MD033 --\u003e\n\n![Keras](https://img.shields.io/badge/keras-v3.4.1+-success.svg)\n[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/james77777778/keras-aug/actions.yml?label=tests)](https://github.com/james77777778/keras-aug/actions/workflows/actions.yml?query=branch%3Amain++)\n[![codecov](https://codecov.io/gh/james77777778/keras-aug/branch/main/graph/badge.svg?token=81ELI3VH7H)](https://codecov.io/gh/james77777778/keras-aug)\n[![PyPI](https://img.shields.io/pypi/v/keras-aug)](https://pypi.org/project/keras-aug/)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/keras-aug)\n[![Open in HF Spaces](https://huggingface.co/datasets/huggingface/badges/resolve/main/open-in-hf-spaces-sm-dark.svg)](https://huggingface.co/spaces/james77777778/KerasAug)\n\n## Description\n\nKerasAug is a library that includes Keras 3 preprocessing and augmentation layers, providing support for various data types such as images, labels, bounding boxes, segmentation masks, and more.\n\n\u003cdiv align=\"center\"\u003e\n\u003cimg width=\"45%\" src=\"https://github.com/user-attachments/assets/bf9488c4-5c6b-4c87-8fa8-30170a67c92c\" alt=\"object_detection.gif\"\u003e \u003cimg width=\"45%\" src=\"https://github.com/user-attachments/assets/556db949-9461-438a-b1cf-3621ec63416e\"  alt=\"semantic_segmentation.gif\"\u003e\n\u003c/div\u003e\n\n\u003e [!NOTE]\n\u003e See `docs/*.py` for the GIF generation. YOLOV8-like pipeline for bounding boxes and segmentation masks.\n\nKerasAug aims to provide fast, robust and user-friendly preprocessing and augmentation layers, facilitating seamless integration with Keras 3 and `tf.data`.\n\nThe APIs largely follow `torchvision`, and the correctness of the layers has been verified through unit tests.\n\nAlso, you can check out the demo app on HF:\nApp here: [![Open in HF Spaces](https://huggingface.co/datasets/huggingface/badges/resolve/main/open-in-hf-spaces-sm-dark.svg)](https://huggingface.co/spaces/james77777778/KerasAug)\n\n## Why KerasAug\n\n- 🚀 Supports many preprocessing \u0026 augmentation layers across all backends (JAX, TensorFlow and Torch).\n- 🧰 Seamlessly integrates with `tf.data`, offering a performant and scalable data pipeline.\n- 🔥 Follows the same API design as `torchvision`.\n- 🙌 Depends only on Keras 3.\n\n## Installation\n\n```bash\npip install keras keras-aug -U\n```\n\n\u003e [!IMPORTANT]  \n\u003e Make sure you have installed a supported backend for Keras.\n\n## Quickstart\n\n### Rock, Paper and Scissors Image Classification\n\n[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/11xc0nW06iWQ_R-oH4wLB_MYV4GY4mNwy?usp=sharing)\n\n```python\nimport keras\nimport tensorflow as tf\nimport tensorflow_datasets as tfds\n\nfrom keras_aug import layers as ka_layers\n\nBATCH_SIZE = 64\nNUM_CLASSES = 3\nINPUT_SIZE = (128, 128)\n\n# Create a `tf.data.Dataset`-compatible preprocessing pipeline.\n# Note that this example works with all backends.\ntrain_dataset, validation_dataset = tfds.load(\n    \"rock_paper_scissors\", as_supervised=True, split=[\"train\", \"test\"]\n)\ntrain_dataset = (\n    train_dataset.batch(BATCH_SIZE)\n    .map(\n        lambda images, labels: {\n            \"images\": tf.cast(images, \"float32\") / 255.0,\n            \"labels\": tf.one_hot(labels, NUM_CLASSES),\n        }\n    )\n    .map(ka_layers.vision.Resize(INPUT_SIZE))\n    .shuffle(128)\n    .map(ka_layers.vision.RandAugment())\n    .map(ka_layers.vision.CutMix(num_classes=NUM_CLASSES))\n    .map(ka_layers.vision.Rescale(scale=2.0, offset=-1))  # [0, 1] to [-1, 1]\n    .map(lambda data: (data[\"images\"], data[\"labels\"]))\n    .prefetch(tf.data.AUTOTUNE)\n)\nvalidation_dataset = (\n    validation_dataset.batch(BATCH_SIZE)\n    .map(\n        lambda images, labels: {\n            \"images\": tf.cast(images, \"float32\") / 255.0,\n            \"labels\": tf.one_hot(labels, NUM_CLASSES),\n        }\n    )\n    .map(ka_layers.vision.Resize(INPUT_SIZE))\n    .map(ka_layers.vision.Rescale(scale=2.0, offset=-1))  # [0, 1] to [-1, 1]\n    .map(lambda data: (data[\"images\"], data[\"labels\"]))\n    .prefetch(tf.data.AUTOTUNE)\n)\n\n# Create a model using MobileNetV2 as the backbone.\nbackbone = keras.applications.MobileNetV2(\n    input_shape=(*INPUT_SIZE, 3), include_top=False\n)\nbackbone.trainable = False\ninputs = keras.Input((*INPUT_SIZE, 3))\nx = backbone(inputs)\nx = keras.layers.GlobalAveragePooling2D()(x)\noutputs = keras.layers.Dense(NUM_CLASSES, activation=\"softmax\")(x)\nmodel = keras.Model(inputs, outputs)\nmodel.summary()\nmodel.compile(\n    loss=\"categorical_crossentropy\",\n    optimizer=keras.optimizers.SGD(learning_rate=1e-3, momentum=0.9),\n    metrics=[\"accuracy\"],\n)\n\n# Train and evaluate your model\nmodel.fit(train_dataset, validation_data=validation_dataset, epochs=8)\nmodel.evaluate(validation_dataset)\n```\n\nThe above example runs with all backends (JAX, TensorFlow, Torch).\n\n### More Examples\n\n- [YOLOV8 object detection pipeline](guides/voc_yolov8_aug.py) [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1AgnnvfTRMHKq--7gvmHP7RyxTeQResV4?usp=sharing)\n\n- [YOLOV8 semantic segmentation pipeline](guides/oxford_yolov8_aug.py) [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1IJwUPiHreO7iIJ3VewgfLRoBdFdcQcJE?usp=sharing)\n\n## Gradio App\n\n```bash\ngradio deploy\n```\n\n## Citing KerasAug\n\n```bibtex\n@misc{chiu2023kerasaug,\n  title={KerasAug},\n  author={Hongyu, Chiu},\n  year={2023},\n  howpublished={\\url{https://github.com/james77777778/keras-aug}},\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjames77777778%2Fkeras-aug","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjames77777778%2Fkeras-aug","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjames77777778%2Fkeras-aug/lists"}