sparseml.keras.datasets.classification package¶
Submodules¶
sparseml.keras.datasets.classification.imagefolder module¶
ImageFolder dataset implementations for the image classification field in computer vision.
-
class
sparseml.keras.datasets.classification.imagefolder.
ImageFolderDataset
(root: str, train: bool, image_size: Union[None, int, Tuple[int, int]] = 224, pre_resize_transforms: Optional[sparseml.keras.datasets.classification.imagefolder.SplitsTransforms] = SplitsTransforms(train=(<function random_scaling_crop.<locals>.rand_crop>, <function random_flip_left_right>), val=None), post_resize_transforms: Optional[sparseml.keras.datasets.classification.imagefolder.SplitsTransforms] = SplitsTransforms(train=(<function default_imagenet_normalizer.<locals>.normalizer>, ), val=(<function default_imagenet_normalizer.<locals>.normalizer>, )))[source]¶ Bases:
sparseml.keras.datasets.dataset.Dataset
Implementation for loading an image folder structure into a dataset. | Image folders should be of the form: | root/class_x/xxx.ext | root/class_x/xxy.ext | root/class_x/xxz.ext | | root/class_y/123.ext | root/class_y/nsdf3.ext | root/class_y/asd932_.ext :param root: the root location for the dataset’s images to load :param train: True to load the training dataset from the root,
False for validation
- Parameters
image_size – the size of the image to reshape to
pre_resize_transforms – transforms to be applied before resizing the image
post_resize_transforms – transforms to be applied after resizing the image
-
creator
()[source]¶ - Returns
a created dataset that gives the file_path and label for each image under self.root
-
property
image_size
¶ the size of the images to resize to
- Type
return
-
property
num_classes
¶ the number of classes found for the dataset
- Type
return
-
property
num_images
¶ the number of images found for the dataset
- Type
return
-
property
post_resize_transforms
¶ transforms to be applied after resizing the image
- Type
return
-
property
pre_resize_transforms
¶ transforms to be applied before resizing the image
- Type
return
-
processor
(file_path: tensorflow.python.framework.ops.Tensor, label: tensorflow.python.framework.ops.Tensor)[source]¶ - Parameters
file_path – the path to the file to load an image from
label – the label for the given image
- Returns
a tuple containing the processed image and label
-
property
root
¶ the root location for the dataset’s images to load
- Type
return
-
property
train
¶ True to load the training dataset from the root, False for validation
- Type
return
-
class
sparseml.keras.datasets.classification.imagefolder.
SplitsTransforms
(train, val)¶ Bases:
tuple
-
property
train
¶ Alias for field number 0
-
property
val
¶ Alias for field number 1
-
property
-
sparseml.keras.datasets.classification.imagefolder.
imagenet_normalizer
(img: tensorflow.python.framework.ops.Tensor, mode: str)[source]¶ Normalize an image using mean and std of the imagenet dataset :param img: The input image to normalize :param mode: either “tf”, “caffe”, “torch” :return: The normalized image
sparseml.keras.datasets.classification.imagenet module¶
Imagenet dataset implementations for the image classification field in computer vision. More info for the dataset can be found here.
-
class
sparseml.keras.datasets.classification.imagenet.
ImageNetDataset
(root: str = '~/.cache/nm_datasets/imagenet', train: bool = True, rand_trans: bool = False, image_size: Union[None, int, Tuple[int, int]] = 224, pre_resize_transforms=SplitsTransforms(train=(<function random_scaling_crop.<locals>.rand_crop>, <function random_flip_left_right>), val=(<function imagenet_pre_resize_processor.<locals>.processor>, )), post_resize_transforms=SplitsTransforms(train=(<function torch_imagenet_normalizer.<locals>.normalizer>, ), val=(<function torch_imagenet_normalizer.<locals>.normalizer>, )))[source]¶ Bases:
sparseml.keras.datasets.classification.imagefolder.ImageFolderDataset
Wrapper for the ImageNet dataset to apply standard transforms.
- Parameters
root – The root folder to find the dataset at
train – True if this is for the training distribution, False for the validation
rand_trans – True to apply RandomCrop and RandomHorizontalFlip to the data, False otherwise
image_size – the size of the image to output from the dataset
sparseml.keras.datasets.classification.imagenette module¶
Imagenette and Imagewoof dataset implementations for the image classification field in computer vision. More info for the dataset can be found here.
-
class
sparseml.keras.datasets.classification.imagenette.
ImagenetteDataset
(root: str = '~/.cache/nm_datasets/imagenette', train: bool = True, dataset_size: sparseml.utils.datasets.imagenette.ImagenetteSize = <ImagenetteSize.s320: 's320'>, image_size: Optional[int] = None, download: bool = True)[source]¶ Bases:
sparseml.keras.datasets.classification.imagefolder.ImageFolderDataset
,sparseml.utils.datasets.imagenette.ImagenetteDownloader
Wrapper for the imagenette (10 class) dataset that fastai created. Handles downloading and applying standard transforms. :param root: The root folder to find the dataset at,
if not found will download here if download=True
- Parameters
train – True if this is for the training distribution, False for the validation
dataset_size – The size of the dataset to use and download: See ImagenetteSize for options
image_size – The image size to output from the dataset
download – True to download the dataset, False otherwise
Module contents¶
Datasets related to image classification field in computer vision