The CIFAR-10 dataset consists of 60000 32x32 colour images in 10 classes, with 6000 images per class.

To train with an example CNN classification model:

mantra train cnn_example --dataset cifar10 --image-dim 32 32


To import this dataset to your project, run:

mantra import RJT1990/data/cifar10


Example usage in code:

from import CIFAR10 d = CIFAR10() print(d.X.__class__) ## <class 'numpy.ndarray'> print(d.y.__class__) ## <class 'numpy.ndarray'>

Data processing
import numpy as np from import Dataset, cachedata from import ImageDataset class CIFAR10(ImageDataset): # These class variables contain metadata on the Dataset data_name = 'CIFAR-10' data_tags = ['cifar', 'cifar10'] data_image = 'cifar.jpeg' files = ['cifar.tar.gz'] has_labels = True image_dim = (32, 32) # default - can override with command line @cachedata def y(self): """ This method extracts inputs from the data. The output should be an np.ndarray that can be processed by the model. Returns -------- np.ndarray - of data inputs (y vector) """ # if X isn't extracted, then extract it if self._X is None: self.X # calling will extract labels = [file_name.split('_')[1].split('.png')[0] for file_name in self.image_file_names] self.label_names = list(set(labels)) self.label_col_dict = dict(zip(self.label_names, range(len(self.label_names)))) numeric_labels = np.array([self.label_col_dict[name] for name in labels]) result = np.zeros((numeric_labels.size, 10), dtype=int) result[np.arange(numeric_labels.size), numeric_labels] = 1 return result
All files
cifar10 /
1 lines | 49 bytes