快捷方式

灰度

class torchvision.transforms.Grayscale(num_output_channels=1)[原始碼]

將影像轉換為灰度圖。如果影像是 torch Tensor,則其形狀應為 […, 3, H, W],其中 … 表示任意數量的前導維度

引數:

num_output_channels (int) – (1 或 3) 輸出影像所需的通道數

返回:

輸入的灰度版本。

  • 如果 num_output_channels == 1 : 返回的影像為單通道

  • 如果 num_output_channels == 3 : 返回的影像為 3 通道,其中 r == g == b

返回型別:

PIL Image

使用 Grayscale 的示例

變換示例

變換示例
forward(img)[原始碼]
引數:

img (PIL ImageTensor) – 要轉換為灰度的影像。

返回:

灰度影像。

返回型別:

PIL Image 或 Tensor

文件

訪問 PyTorch 的全面開發者文件

檢視文件

教程

獲取面向初學者和高階開發者的深入教程

檢視教程

資源

查詢開發資源並獲得問題解答

檢視資源