mindspore.dataset.Dataset.num_classes

mindspore.dataset.Dataset.num_classes()[源代码]

获取数据集对象中所有样本的类别数目。

返回:

int,类别的数目。

样例:

>>> import mindspore.dataset as ds
>>> # Read image files
>>> image_folder_dataset_dir = "/path/to/image_folder_dataset_directory"
>>> dataset = ds.ImageFolderDataset(dataset_dir=image_folder_dataset_dir)
>>> # Check how many classes exist in image folder
>>> num_classes = dataset.num_classes()