Keras 3 API 文件 / KerasCV / / 預處理層 / 灰階圖層

灰階圖層

[來源]

Grayscale 類別

keras_cv.layers.Grayscale(output_channels=1, **kwargs)

灰階圖層是一種預處理層,可將 RGB 影像轉換為灰階影像。輸入影像的值應該在 [0, 255] 範圍內。

輸入形狀

形狀為 (..., 高度, 寬度, 通道數) 的 3D(未批次化)或 4D(批次化)張量,採用 "channels_last" 格式

輸出形狀

形狀為 (..., 高度, 寬度, 通道數) 的 3D(未批次化)或 4D(批次化)張量,採用 "channels_last" 格式

參數

output_channels。輸出影像中存在的色彩通道數。output_channels 可以是 1 或 3。形狀為 (..., 高度, 寬度, 3) 的 RGB 影像在 Grayscale 操作後將具有以下形狀:a. (..., 高度, 寬度, 1)(如果 output_channels = 1)b. (..., 高度, 寬度, 3)(如果 output_channels = 3)。

範例

(images, labels), _ = keras.datasets.cifar10.load_data()
to_grayscale = keras_cv.layers.preprocessing.Grayscale()
augmented_images = to_grayscale(images)