快捷方式

Cityscapes

class torchvision.datasets.Cityscapes(root: Union[str, Path], split: str = 'train', mode: str = 'fine', target_type: Union[List[str], str] = 'instance', transform: Optional[Callable] = None, target_transform: Optional[Callable] = None, transforms: Optional[Callable] = None)[source]

Cityscapes 資料集。

引數:
  • root (str or pathlib.Path) – 資料集的根目錄,其中包含目錄 leftImg8bitgtFinegtCoarse

  • split (string, optional) – 要使用的影像分割,如果 mode=”fine” 則為 traintestval,否則為 traintrain_extraval

  • mode (string, optional) – 要使用的質量模式,finecoarse

  • target_type (string or list, optional) – 要使用的目標型別,instancesemanticpolygoncolor。也可以是列表,用於輸出包含所有指定目標型別的元組。

  • transform (callable, optional) – 一個函式/轉換,它接收一個 PIL 影像並返回轉換後的版本。例如,transforms.RandomCrop

  • target_transform (callable, optional) – 一個函式/轉換,它接收目標並對其進行轉換。

  • transforms (callable, optional) – 一個函式/轉換,它接收輸入樣本及其目標作為輸入並返回轉換後的版本。

示例

獲取語義分割目標

dataset = Cityscapes('./data/cityscapes', split='train', mode='fine',
                     target_type='semantic')

img, smnt = dataset[0]

獲取多個目標

dataset = Cityscapes('./data/cityscapes', split='train', mode='fine',
                     target_type=['instance', 'color', 'polygon'])

img, (inst, col, poly) = dataset[0]

在“粗略”集上驗證

dataset = Cityscapes('./data/cityscapes', split='val', mode='coarse',
                     target_type='semantic')

img, smnt = dataset[0]
特殊成員:

__getitem__(index: int) Tuple[Any, Any][source]
引數:

index (int) – 索引

返回:

(影像, 目標),如果 target_type 是一個包含多個項的列表,則目標是一個包含所有目標型別的元組。否則,如果 target_type=”polygon”,目標是一個 json 物件,否則是影像分割。

返回型別:

tuple

文件

查閱全面的 PyTorch 開發者文件

檢視文件

教程

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

檢視教程

資源

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

檢視資源