Keras 3 API 文件 / KerasCV / / 預處理層 / 色調簡化層

色調簡化層

[來源]

Posterization 類別

keras_cv.layers.Posterization(value_range, bits, **kwargs)

減少每個顏色通道的位元數。

參考

參數

  • value_range:一個元組或兩個元素的列表。第一個值表示傳遞影像中值的最小值,第二個值表示最大值。傳遞給該層的影像的值應在 value_range 範圍內。預設值為 (0, 255)
  • bits:整數,要保留每個通道的位元數。必須是 1-8 之間的值。

範例

(images, labels), _ = keras.datasets.cifar10.load_data()
print(images[0, 0, 0])
# [59 62 63]
# Note that images are Tensors with values in the range [0, 255] and uint8
dtype
posterization = Posterization(bits=4, value_range=[0, 255])
images = posterization(images)
print(images[0, 0, 0])
# [48., 48., 48.]
# NOTE: the layer will output values in tf.float32, regardless of input
    dtype.

呼叫參數

  • inputs:輸入張量,可以是以下兩種格式
    1. 單個 3D (HWC) 影像或 4D (NHWC) 影像批次。
    2. 一個張量字典,其中影像位於 "images" 鍵下。