Skip to main content

TensorFlow augmentation layers including RGBA background compositing, random color temperature, and color cast.

Project description

tf-image-augment-layers

TensorFlow/Keras 用の高性能画像拡張レイヤーコレクション。市販カメラのホワイトバランスのゆらぎを模倣するために、色温度・色被りの拡張を実装してみました。 RGBA 背景合成・色温度変換・色被り生成など、標準の Keras augmentation にない高度拡張を GPU 上で高速に実行できます。特に背景差し替えは、先行研究で「CNN が対象物へより注視しやすくなる」と報告されており、その検証目的として本実装を追加しました。


🚀 Features

Why this library? 標準の TensorFlow/Keras では扱えない RGBA 背景合成や高度な色変換が可能になり、データ拡張の幅が大きく広がります。

  • 🖼 RGBA 対応(透明 PNG を安全に処理)
  • 🎨 背景ランダム置換(グレー / ノイズ / 白 / 黒)
  • 🌡 色温度を Kelvin 指定でランダム変換
  • 💡 色被り(Green / Magenta)をランダム付加
  • すべて TensorFlow グラフ上で実行され GPU / TPU に最適化
  • 🔄 Keras Sequential / Functional / tf.data と完全互換

📦 Installation

PyPI 公開後に使用できます:

pip install tf-image-augment-layers

🧩 Available Layers

Layer Description
ReplaceBackgroundWithGrayNoiseLayer RGBA 背景をグレー / ノイズ / 白 / 黒に置換
RGBAtoRGBLayer RGBA → RGB に変換
RandomColorTemperatureLayer 色温度を Kelvin 範囲でランダム変換
ColorCastLayer 色被り(Green / Magenta)をランダム追加
background_composit() 背景置換を行う関数(単独利用可)

🔧 Usage Example

Keras Sequential に組み込む

Note: 色温度変換(RandomColorTemperatureLayer)や色被り(ColorCastLayer)は RGB 画像を前提としています。RGBA の場合は必ず RGBAtoRGBLayer を適用して 3 チャンネルに変換してから使用してください。

from augment_layers import (
    RGBAtoRGBLayer,
    ReplaceBackgroundWithGrayNoiseLayer,
    RandomColorTemperatureLayer,
    ColorCastLayer,
)
import tensorflow as tf

data_augmentation = tf.keras.Sequential([
    RGBAtoRGBLayer(),
    ReplaceBackgroundWithGrayNoiseLayer(use_white=True),
    RandomColorTemperatureLayer(kelvin_range=(3000, 7500)),
    ColorCastLayer(max_strength=0.3),
])

model = tf.keras.Sequential([
    data_augmentation,
    tf.keras.layers.Rescaling(1./255),
    tf.keras.layers.Conv2D(32, 3, activation="relu"),
    tf.keras.layers.Flatten(),
    tf.keras.layers.Dense(10, activation="softmax"),
])

🧪 Using with tf.data

augment = ReplaceBackgroundWithGrayNoiseLayer(use_white=True)

def preprocess(image, label):
    return augment(image, training=True), label

dataset = dataset.map(preprocess)

🌈 RGBA → RGB

from augment_layers import RGBAtoRGBLayer

rgba_to_rgb = RGBAtoRGBLayer()
rgb_image = rgba_to_rgb(rgba_batch, training=True)

🔥 Background Replacement

from augment_layers import background_composit

aug_image = background_composit(rgba_image, use_white=True)

📜 License

MIT License


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tf_image_augment_layers-0.1.1.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tf_image_augment_layers-0.1.1-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file tf_image_augment_layers-0.1.1.tar.gz.

File metadata

  • Download URL: tf_image_augment_layers-0.1.1.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for tf_image_augment_layers-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2e9d8c9e8843ec6d285f184f132aacb126888eb49a0c711ac91acdbfc36d7767
MD5 aa261e237d6bf8ccf2e758e8d76eb44a
BLAKE2b-256 1184e69812bd0670e852f42a58ac7669d84c46ca081ee89f805ba290d73f8296

See more details on using hashes here.

File details

Details for the file tf_image_augment_layers-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for tf_image_augment_layers-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ee81a759274a5ad0b1ecb0be9ab193a0a30c48f63b3ad07adbad919bea3954b7
MD5 89e0fdea28685d8ec7082a8ef156c962
BLAKE2b-256 cf61a9a00d7d69d649ca7d6617b0fbfb9493e10c574d5b483206d393a3c3f8a7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page