secml.data.loader

CDataLoader

class secml.data.loader.c_dataloader.CDataLoader[source]

Bases: secml.core.c_creator.CCreator

Interface for Dataset loaders.

Attributes
class_type

Defines class type.

logger

Logger for current object.

verbose

Verbosity level of logger output.

Methods

copy(self)

Returns a shallow copy of current class.

create([class_item])

This method creates an instance of a class with given type.

deepcopy(self)

Returns a deep copy of current class.

get_class_from_type(class_type)

Return the class associated with input type.

get_params(self)

Returns the dictionary of class hyperparameters.

get_state(self, **kwargs)

Returns the object state dictionary.

get_subclasses()

Get all the subclasses of the calling class.

list_class_types()

This method lists all types of available subclasses of calling one.

load(self, *args, **kwargs)

Loads a dataset.

load_state(self, path)

Sets the object state from file.

save(self, path)

Save class object to file.

save_state(self, path, **kwargs)

Store the object state to file.

set(self, param_name, param_value[, copy])

Set a parameter of the class.

set_params(self, params_dict[, copy])

Set all parameters passed as a dictionary {key: value}.

set_state(self, state_dict[, copy])

Sets the object state using input dictionary.

timed([msg])

Timer decorator.

abstract load(self, *args, **kwargs)[source]

Loads a dataset.

This method should return a .CDataset object.

CDataLoaderCIFAR

class secml.data.loader.c_dataloader_cifar.CDataLoaderCIFAR[source]

Bases: secml.data.loader.c_dataloader.CDataLoader

Loads the CIFAR tiny images datasets.

Available at: https://www.cs.toronto.edu/~kriz/cifar.html

Attributes
class_type

Defines class type.

data_md5

MD5 digest of the datafile.

data_path

URL of the data directory.

data_url

URL of the datafile.

logger

Logger for current object.

verbose

Verbosity level of logger output.

Methods

copy(self)

Returns a shallow copy of current class.

create([class_item])

This method creates an instance of a class with given type.

deepcopy(self)

Returns a deep copy of current class.

get_class_from_type(class_type)

Return the class associated with input type.

get_params(self)

Returns the dictionary of class hyperparameters.

get_state(self, **kwargs)

Returns the object state dictionary.

get_subclasses()

Get all the subclasses of the calling class.

list_class_types()

This method lists all types of available subclasses of calling one.

load(self[, val_size])

Load all images of the dataset.

load_state(self, path)

Sets the object state from file.

save(self, path)

Save class object to file.

save_state(self, path, **kwargs)

Store the object state to file.

set(self, param_name, param_value[, copy])

Set a parameter of the class.

set_params(self, params_dict[, copy])

Set all parameters passed as a dictionary {key: value}.

set_state(self, state_dict[, copy])

Sets the object state using input dictionary.

timed([msg])

Timer decorator.

abstract property data_md5

MD5 digest of the datafile. Specific for each dataset type.

Returns
str

Expected MD5 digest of the dataset file.

abstract property data_path

URL of the data directory. Specific for each dataset type.

Returns
str

Path to the folder where dataset data is stored.

abstract property data_url

URL of the datafile. Specific for each dataset type.

Returns
str

URL of the remote datafile with dataset data.

abstract load(self, val_size=0)[source]

Load all images of the dataset.

Each image is flattened. The first 1024 entries contain the red channel values, the next 1024 the green, and the final 1024 the blue. The image is stored in row-major order, so that the first 32 entries of the array are the red channel values of the first row of the image. Dtype of images is uint8. Dtype of labels is int32.

Extra dataset attributes:
  • ‘img_w’, ‘img_h’: size of the images in pixels.

  • ‘class_names’: dictionary with the original name of each class.

Parameters
val_sizeint, optional

Size of the validation set. Default 0, so no validation dataset will be returned.

Returns
training_setCDataset

Training set.

test_setCDataset

Test set.

validation_setCDataset, optional

Validation set. Returned only if val_size > 0.

class secml.data.loader.c_dataloader_cifar.CDataLoaderCIFAR10[source]

Bases: secml.data.loader.c_dataloader_cifar.CDataLoaderCIFAR

Loads the CIFAR-10 tiny images dataset.

The CIFAR-10 dataset consists of 60000 32x32 colour images in 10 classes, with 6000 images per class. There are 50000 training images and 10000 test images.

Available at: https://www.cs.toronto.edu/~kriz/cifar.html

Attributes
class_type‘CIFAR-10’

Defines class type.

Methods

copy(self)

Returns a shallow copy of current class.

create([class_item])

This method creates an instance of a class with given type.

deepcopy(self)

Returns a deep copy of current class.

get_class_from_type(class_type)

Return the class associated with input type.

get_params(self)

Returns the dictionary of class hyperparameters.

get_state(self, **kwargs)

Returns the object state dictionary.

get_subclasses()

Get all the subclasses of the calling class.

list_class_types()

This method lists all types of available subclasses of calling one.

load(self[, val_size])

Load all images of the dataset.Load all images of the dataset.

load_state(self, path)

Sets the object state from file.

save(self, path)

Save class object to file.

save_state(self, path, **kwargs)

Store the object state to file.

set(self, param_name, param_value[, copy])

Set a parameter of the class.

set_params(self, params_dict[, copy])

Set all parameters passed as a dictionary {key: value}.

set_state(self, state_dict[, copy])

Sets the object state using input dictionary.

timed([msg])

Timer decorator.

property data_md5

MD5 digest of the datafile.

Returns
str

Expected MD5 digest of the dataset file.

property data_path

URL of the data directory.

Returns
str

Path to the folder where dataset data is stored.

property data_url

URL of the remote datafile.

Returns
str

URL of the remote datafile with dataset data.

load(self, val_size=0)[source]

Load all images of the dataset.Load all images of the dataset.

Each image is flattened. The first 1024 entries contain the red channel values, the next 1024 the green, and the final 1024 the blue. The image is stored in row-major order, so that the first 32 entries of the array are the red channel values of the first row of the image. Dtype of images is uint8. Dtype of labels is int32.

Extra dataset attributes:
  • ‘img_w’, ‘img_h’: size of the images in pixels.

  • ‘class_names’: dictionary with the original name of each class.

Parameters
val_sizeint, optional

Size of the validation set. Default 0, so no validation dataset will be returned.

Returns
training_setCDataset

Training set.

test_setCDataset

Test set.

validation_setCDataset, optional

Validation set. Returned only if val_size > 0.

class secml.data.loader.c_dataloader_cifar.CDataLoaderCIFAR100[source]

Bases: secml.data.loader.c_dataloader_cifar.CDataLoaderCIFAR

Loads the CIFAR-100 tiny images dataset.

The CIFAR-100 dataset consists of 60000 32x32 colour images in 100 classes, containing 600 images each. There are 500 training images and 100 testing images per class. The 100 classes in the CIFAR-100 are grouped into 20 superclasses. Each image comes with a “fine” label (the class to which it belongs) and a “coarse” label (the superclass to which it belongs).

Available at: https://www.cs.toronto.edu/~kriz/cifar.html

Attributes
class_type‘CIFAR-100’

Defines class type.

Methods

copy(self)

Returns a shallow copy of current class.

create([class_item])

This method creates an instance of a class with given type.

deepcopy(self)

Returns a deep copy of current class.

get_class_from_type(class_type)

Return the class associated with input type.

get_params(self)

Returns the dictionary of class hyperparameters.

get_state(self, **kwargs)

Returns the object state dictionary.

get_subclasses()

Get all the subclasses of the calling class.

list_class_types()

This method lists all types of available subclasses of calling one.

load(self[, val_size])

Load all images of the dataset.

load_state(self, path)

Sets the object state from file.

save(self, path)

Save class object to file.

save_state(self, path, **kwargs)

Store the object state to file.

set(self, param_name, param_value[, copy])

Set a parameter of the class.

set_params(self, params_dict[, copy])

Set all parameters passed as a dictionary {key: value}.

set_state(self, state_dict[, copy])

Sets the object state using input dictionary.

timed([msg])

Timer decorator.

property data_md5

MD5 digest of the datafile.

Returns
str

Expected MD5 digest of the dataset file.

property data_path

URL of the data directory.

Returns
str

Path to the folder where dataset data is stored.

property data_url

URL of the remote datafile.

Returns
str

URL of the remote datafile with dataset data.

load(self, val_size=0)[source]

Load all images of the dataset.

Each image is flattened. The first 1024 entries contain the red channel values, the next 1024 the green, and the final 1024 the blue. The image is stored in row-major order, so that the first 32 entries of the array are the red channel values of the first row of the image. Dtype of images is uint8. Dtype of labels is int32.

Extra dataset attributes:
  • ‘img_w’, ‘img_h’: size of the images in pixels.

  • ‘class_names’: dictionary with the original name of each class.

Parameters
val_sizeint, optional

Size of the validation set. Default 0, so no validation dataset will be returned.

Returns
training_setCDataset

Training set.

test_setCDataset

Test set.

validation_setCDataset, optional

Validation set. Returned only if val_size > 0.

CDataLoaderICubWorld

class secml.data.loader.c_dataloader_icubworld.CDataLoaderICubWorld[source]

Bases: secml.data.loader.c_dataloader.CDataLoader

Interface for loaders of iCubWorld datasets.

iCubWorld is a set of computer vision datasets for robotic applications, developed by Istituto Italiano di Tecnologia (IIT), Genova, Italy.

REF: https://robotology.github.io/iCubWorld

Attributes
class_type

Defines class type.

logger

Logger for current object.

verbose

Verbosity level of logger output.

Methods

copy(self)

Returns a shallow copy of current class.

create([class_item])

This method creates an instance of a class with given type.

deepcopy(self)

Returns a deep copy of current class.

get_class_from_type(class_type)

Return the class associated with input type.

get_params(self)

Returns the dictionary of class hyperparameters.

get_state(self, **kwargs)

Returns the object state dictionary.

get_subclasses()

Get all the subclasses of the calling class.

list_class_types()

This method lists all types of available subclasses of calling one.

load(self, *args, **kwargs)

Loads a dataset.

load_state(self, path)

Sets the object state from file.

save(self, path)

Save class object to file.

save_state(self, path, **kwargs)

Store the object state to file.

set(self, param_name, param_value[, copy])

Set a parameter of the class.

set_params(self, params_dict[, copy])

Set all parameters passed as a dictionary {key: value}.

set_state(self, state_dict[, copy])

Sets the object state using input dictionary.

timed([msg])

Timer decorator.

abstract load(self, *args, **kwargs)[source]

Loads a dataset.

This method should return a .CDataset object.

class secml.data.loader.c_dataloader_icubworld.CDataLoaderICubWorld28[source]

Bases: secml.data.loader.c_dataloader_icubworld.CDataLoaderICubWorld

Loader for iCubWorld28 dataset.

The dataset consists in 28 objects divided in 7 categories, where each category includes 4 objects. For each object there are 4 different acquisition days for training and 4 for testing, with ~150 frames per acquisition.

Attributes
class_type‘icubworld28’

Defines class type.

Methods

copy(self)

Returns a shallow copy of current class.

create([class_item])

This method creates an instance of a class with given type.

deepcopy(self)

Returns a deep copy of current class.

get_class_from_type(class_type)

Return the class associated with input type.

get_params(self)

Returns the dictionary of class hyperparameters.

get_state(self, **kwargs)

Returns the object state dictionary.

get_subclasses()

Get all the subclasses of the calling class.

list_class_types()

This method lists all types of available subclasses of calling one.

load(self, ds_type[, day, icub7, …])

Load the dataset.

load_state(self, path)

Sets the object state from file.

save(self, path)

Save class object to file.

save_state(self, path, **kwargs)

Store the object state to file.

set(self, param_name, param_value[, copy])

Set a parameter of the class.

set_params(self, params_dict[, copy])

Set all parameters passed as a dictionary {key: value}.

set_state(self, state_dict[, copy])

Sets the object state using input dictionary.

timed([msg])

Timer decorator.

load(self, ds_type, day='day4', icub7=False, resize_shape=(128, 128), crop_shape=None, normalize=True)[source]

Load the dataset.

The pre-cropped version of the images is loaded, with size 128 x 128. An additional resize/crop shape could be passed as input if needed.

Extra dataset attributes:
  • ‘img_w’, ‘img_h’: size of the images in pixels.

  • ‘y_orig’: CArray with the original labels of the objects.

Parameters
ds_typestr

Identifier of the dataset to download, either ‘train’ or ‘test’.

daystr, optional

Acquisition day from which to load the images. Default ‘day4’. The available options are: ‘day1’, ‘day2’, ‘day3’, ‘day4’.

icub7bool or int, optional

If True, load a reduced dataset with 7 objects by taking the 3rd object for each category. Default False. If int, the Nth object for each category will be loaded.

resize_shapetuple, optional

Images will be resized to (height, width) shape. Default (128, 128).

crop_shapetuple or None, optional

If a tuple, a crop of (height, width) shape will be extracted from the center of each image. Default None.

normalizebool, optional

If True, images are normalized between 0-1. Default True.

Returns
CDataset

Output dataset.

CDataLoaderImgClients

class secml.data.loader.c_dataloader_imgclients.CDataLoaderImgClients[source]

Bases: secml.data.loader.c_dataloader.CDataLoader

Loads a dataset of images and corresponding labels from ‘clients.txt’.

Attributes
class_type‘img-clients’

Defines class type.

Methods

copy(self)

Returns a shallow copy of current class.

create([class_item])

This method creates an instance of a class with given type.

deepcopy(self)

Returns a deep copy of current class.

get_class_from_type(class_type)

Return the class associated with input type.

get_params(self)

Returns the dictionary of class hyperparameters.

get_state(self, **kwargs)

Returns the object state dictionary.

get_subclasses()

Get all the subclasses of the calling class.

list_class_types()

This method lists all types of available subclasses of calling one.

load(self, ds_path, img_format[, …])

Load all images of specified format inside given path.

load_state(self, path)

Sets the object state from file.

save(self, path)

Save class object to file.

save_state(self, path, **kwargs)

Store the object state to file.

set(self, param_name, param_value[, copy])

Set a parameter of the class.

set_params(self, params_dict[, copy])

Set all parameters passed as a dictionary {key: value}.

set_state(self, state_dict[, copy])

Sets the object state using input dictionary.

timed([msg])

Timer decorator.

load(self, ds_path, img_format, label_dtype=None, load_data=True)[source]

Load all images of specified format inside given path.

Extra dataset attributes:
  • ‘id’: last ds_path folder.

  • ‘img_w’, ‘img_h’: size of the images in pixels.

  • ‘img_c’: images number of channels.

  • Any other custom attribute is retrieved from ‘attributes.txt’ file. Only attributes of str type are currently supported.

Parameters
ds_pathstr

Full path to dataset folder.

img_formatstr

Format of the files to load.

label_dtypestr or dtype, optional

Datatype of the labels. If None, labels will be strings.

load_databool, optional

If True (default) features will be stored. Otherwise store the paths to the files with dtype=object.

CDataLoaderImgFolders

class secml.data.loader.c_dataloader_imgfolders.CDataLoaderImgFolders[source]

Bases: secml.data.loader.c_dataloader.CDataLoader

Loads a dataset of images where clients are specified as different folders.

Attributes
class_type‘img-folders’

Defines class type.

Methods

copy(self)

Returns a shallow copy of current class.

create([class_item])

This method creates an instance of a class with given type.

deepcopy(self)

Returns a deep copy of current class.

get_class_from_type(class_type)

Return the class associated with input type.

get_params(self)

Returns the dictionary of class hyperparameters.

get_state(self, **kwargs)

Returns the object state dictionary.

get_subclasses()

Get all the subclasses of the calling class.

list_class_types()

This method lists all types of available subclasses of calling one.

load(self, ds_path, img_format[, label_re, …])

Load all images of specified format inside given path.

load_state(self, path)

Sets the object state from file.

save(self, path)

Save class object to file.

save_state(self, path, **kwargs)

Store the object state to file.

set(self, param_name, param_value[, copy])

Set a parameter of the class.

set_params(self, params_dict[, copy])

Set all parameters passed as a dictionary {key: value}.

set_state(self, state_dict[, copy])

Sets the object state using input dictionary.

timed([msg])

Timer decorator.

load(self, ds_path, img_format, label_re=None, label_dtype=None, load_data=True)[source]

Load all images of specified format inside given path.

The following custom CDataset attributes are available:
  • ‘id’: last ds_path folder.

  • ‘img_w’, ‘img_h’: size of the images in pixels.

  • ‘img_c’: images number of channels.

  • Any other custom attribute is retrieved from ‘attributes.txt’ file. Only attributes of str type are currently supported.

Any other custom attribute is retrieved from ‘attributes.txt’ file.

Parameters
ds_pathstr

Full path to dataset folder.

img_formatstr

Format of the files to load.

label_rere, optional

Regular expression that identify the correct label. If None, the whole name of the leaf folder will be used as label.

label_dtypestr or dtype, optional

Datatype of the labels. If None, labels will be strings.

load_databool, optional

If True (default) features will be stored. Otherwise store the paths to the files with dtype=object.

CDataLoaderLFW

class secml.data.loader.c_dataloader_lfw.CDataLoaderLFW[source]

Bases: secml.data.loader.c_dataloader.CDataLoader

Loads the LFW Labeled Faces in the Wild dataset.

This dataset is a collection of JPEG pictures of famous people collected on the internet, all details are available on the official website:

Each picture is centered on a single face. Each pixel of each channel (color in RGB) is encoded by a float in range 0.0 - 1.0.

The task is called Face Recognition (or Identification):

given the picture of a face, find the name of the person given a training set (gallery).

This implementation uses sklearn.datasets.fetch_lfw_people module.

Attributes
class_type‘lfw’

Defines class type.

Methods

clean_tmp()

Cleans temporary files created by the DB loader.

copy(self)

Returns a shallow copy of current class.

create([class_item])

This method creates an instance of a class with given type.

deepcopy(self)

Returns a deep copy of current class.

get_class_from_type(class_type)

Return the class associated with input type.

get_params(self)

Returns the dictionary of class hyperparameters.

get_state(self, **kwargs)

Returns the object state dictionary.

get_subclasses()

Get all the subclasses of the calling class.

list_class_types()

This method lists all types of available subclasses of calling one.

load(self[, min_faces_per_person, funneled, …])

Load LFW dataset.

load_state(self, path)

Sets the object state from file.

save(self, path)

Save class object to file.

save_state(self, path, **kwargs)

Store the object state to file.

set(self, param_name, param_value[, copy])

Set a parameter of the class.

set_params(self, params_dict[, copy])

Set all parameters passed as a dictionary {key: value}.

set_state(self, state_dict[, copy])

Sets the object state using input dictionary.

timed([msg])

Timer decorator.

static clean_tmp()[source]

Cleans temporary files created by the DB loader.

This method deletes the joblib-related files created while loading the database.

Does not delete the downloaded database archive.

load(self, min_faces_per_person=None, funneled=True, color=False)[source]

Load LFW dataset.

Extra dataset attributes:
  • ‘img_w’, ‘img_h’: size of the images in pixels.

  • ‘y_names’: tuple with the name string for each class.

Parameters
min_faces_per_personint or None, optional

The extracted dataset will only retain pictures of people that have at least min_faces_per_person different pictures. Default None, so all db images are returned.

funneledbool, optional

Download and use the images aligned with deep funneling. Default True.

colorbool, optional

Keep the 3 RGB channels instead of averaging them to a single gray level channel. Default False.

CDataLoaderMNIST

class secml.data.loader.c_dataloader_mnist.CDataLoaderMNIST[source]

Bases: secml.data.loader.c_dataloader.CDataLoader

Loads the MNIST Handwritten Digits dataset.

This dataset has a training set of 60,000 examples, and a test set of 10,000 examples. All images are 28 x 28 black and white 8bit (0 - 255).

Available at: http://yann.lecun.com/exdb/mnist/

Attributes
class_type‘mnist’

Defines class type.

Methods

copy(self)

Returns a shallow copy of current class.

create([class_item])

This method creates an instance of a class with given type.

deepcopy(self)

Returns a deep copy of current class.

get_class_from_type(class_type)

Return the class associated with input type.

get_params(self)

Returns the dictionary of class hyperparameters.

get_state(self, **kwargs)

Returns the object state dictionary.

get_subclasses()

Get all the subclasses of the calling class.

list_class_types()

This method lists all types of available subclasses of calling one.

load(self, ds[, digits, num_samples])

Load all images of specified format inside given path.

load_state(self, path)

Sets the object state from file.

save(self, path)

Save class object to file.

save_state(self, path, **kwargs)

Store the object state to file.

set(self, param_name, param_value[, copy])

Set a parameter of the class.

set_params(self, params_dict[, copy])

Set all parameters passed as a dictionary {key: value}.

set_state(self, state_dict[, copy])

Sets the object state using input dictionary.

timed([msg])

Timer decorator.

load(self, ds, digits=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9), num_samples=None)[source]

Load all images of specified format inside given path.

Adapted from: http://cvxopt.org/_downloads/mnist.py

Extra dataset attributes:
  • ‘img_w’, ‘img_h’: size of the images in pixels.

  • ‘y_original’: array with the original labels (before renumbering)

Parameters
dsstr

Identifier of the dataset to download, either ‘training’ or ‘testing’.

digitstuple

Tuple with the digits to load. By default all digits are loaded.

num_samplesint or None, optional

Number of expected samples in resulting ds. If int, an equal number of samples will be taken from each class until num_samples have been loaded. If None, all samples will be loaded.

CDataLoaderPyTorch

class secml.data.loader.c_dataloader_pytorch.CDataLoaderPyTorch(data, labels=None, batch_size=4, shuffle=False, transform=None, num_workers=0)[source]

Bases: object

Methods

get_loader

get_loader(self)[source]

CDataLoaderSkLearn

class secml.data.loader.c_dataloader_sklearn.CDLRandom(n_samples=100, n_features=20, n_informative=2, n_redundant=2, n_repeated=0, n_classes=2, n_clusters_per_class=2, weights=None, flip_y=0.01, class_sep=1.0, hypercube=True, shift=0.0, scale=1.0, random_state=None)[source]

Bases: secml.data.loader.c_dataloader.CDataLoader

Class for loading random data.

Generate a random n-class classification problem.

This initially creates clusters of points normally distributed (std=1) about vertices of a 2 * class_sep-sided hypercube, and assigns an equal number of clusters to each class.

It introduces interdependence between these features and adds various types of further noise to the data.

Prior to shuffling, X stacks a number of these primary “informative” features, “redundant” linear combinations of these, “repeated” duplicates of sampled features, and arbitrary noise for and remaining features.

Parameters
n_samplesint, optional (default=100)

The number of samples.

n_featuresint, optional (default=20)

The total number of features. These comprise n_informative informative features, n_redundant redundant features, n_repeated duplicated features and n_features - n_informative - n_redundant - n_repeated useless features drawn at random.

n_informativeint, optional (default=2)

The number of informative features. Each class is composed of a number of gaussian clusters each located around the vertices of a hypercube in a subspace of dimension n_informative. For each cluster, informative features are drawn independently from N(0, 1) and then randomly linearly combined within each cluster in order to add covariance. The clusters are then placed on the vertices of the hypercube.

n_redundantint, optional (default=2)

The number of redundant features. These features are generated as random linear combinations of the informative features.

n_repeatedint, optional (default=0)

The number of duplicated features, drawn randomly from the informative and the redundant features.

n_classesint, optional (default=2)

The number of classes (or labels) of the classification problem.

n_clusters_per_classint, optional (default=2)

The number of clusters per class.

weightslist of floats or None (default=None)

The proportions of samples assigned to each class. If None, then classes are balanced. Note that if len(weights) == n_classes - 1, then the last class weight is automatically inferred. More than n_samples samples may be returned if the sum of weights exceeds 1.

flip_yfloat, optional (default=0.01)

The fraction of samples whose class are randomly exchanged.

class_sepfloat, optional (default=1.0)

The factor multiplying the hypercube dimension.

hypercubebool, optional (default=True)

If True, the clusters are put on the vertices of a hypercube. If False, the clusters are put on the vertices of a random polytope.

shiftfloat, array of shape [n_features] or None, optional (default=0.0)

Shift features by the specified value. If None, then features are shifted by a random value drawn in [-class_sep, class_sep].

scalefloat, array of shape [n_features] or None, optional (default=1.0)

Multiply features by the specified value. If None, then features are scaled by a random value drawn in [1, 100]. Note that scaling happens after shifting.

random_stateint, RandomState instance or None, optional (default=None)

If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, is the RandomState instance used by np.random.

Attributes
class_type‘classification’

Defines class type.

Methods

copy(self)

Returns a shallow copy of current class.

create([class_item])

This method creates an instance of a class with given type.

deepcopy(self)

Returns a deep copy of current class.

get_class_from_type(class_type)

Return the class associated with input type.

get_params(self)

Returns the dictionary of class hyperparameters.

get_state(self, **kwargs)

Returns the object state dictionary.

get_subclasses()

Get all the subclasses of the calling class.

list_class_types()

This method lists all types of available subclasses of calling one.

load(self)

Loads the dataset.

load_state(self, path)

Sets the object state from file.

save(self, path)

Save class object to file.

save_state(self, path, **kwargs)

Store the object state to file.

set(self, param_name, param_value[, copy])

Set a parameter of the class.

set_params(self, params_dict[, copy])

Set all parameters passed as a dictionary {key: value}.

set_state(self, state_dict[, copy])

Sets the object state using input dictionary.

timed([msg])

Timer decorator.

load(self)[source]

Loads the dataset.

Returns
datasetCDataset

The randomly generated dataset.

class secml.data.loader.c_dataloader_sklearn.CDLRandomRegression(n_samples=100, n_features=100, n_informative=10, n_targets=1, bias=0.0, effective_rank=None, tail_strength=0.5, noise=0.0, random_state=None)[source]

Bases: secml.data.loader.c_dataloader.CDataLoader

Generate a random regression problem.

The input set can either be well conditioned (by default) or have a low rank-fat tail singular profile.

The output is generated by applying a (potentially biased) random linear regression model with n_informative nonzero regressors to the previously generated input and some gaussian centered noise with some adjustable scale.

Parameters
n_samplesint, optional (default=100)

The number of samples.

n_featuresint, optional (default=100)

The number of features.

n_informativeint, optional (default=10)

The number of informative features, i.e., the number of features used to build the linear model used to generate the output.

n_targetsint, optional (default=1)

The number of regression targets, i.e., the dimension of the y output vector associated with a sample. By default, the output is a scalar.

biasfloat, optional (default=0.0)

The bias term in the underlying linear model.

effective_rankint or None, optional (default=None)
if not None:

The approximate number of singular vectors required to explain most of the input data by linear combinations. Using this kind ofsingular spectrum in the input allows the generator to reproduce the correlations often observed in practice.

if None:

The input set is well conditioned, centered and gaussian with unit variance.

tail_strengthfloat between 0.0 and 1.0, optional (default=0.5)

The relative importance of the fat noisy tail of the singular values profile if effective_rank is not None.

noisefloat, optional (default=0.0)

The standard deviation of the gaussian noise applied to the output.

random_stateint, RandomState instance or None, optional (default=None)

If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, is the RandomState instance used by np.random.

Attributes
class_type‘regression’

Defines class type.

Methods

copy(self)

Returns a shallow copy of current class.

create([class_item])

This method creates an instance of a class with given type.

deepcopy(self)

Returns a deep copy of current class.

get_class_from_type(class_type)

Return the class associated with input type.

get_params(self)

Returns the dictionary of class hyperparameters.

get_state(self, **kwargs)

Returns the object state dictionary.

get_subclasses()

Get all the subclasses of the calling class.

list_class_types()

This method lists all types of available subclasses of calling one.

load(self)

Loads the dataset.

load_state(self, path)

Sets the object state from file.

save(self, path)

Save class object to file.

save_state(self, path, **kwargs)

Store the object state to file.

set(self, param_name, param_value[, copy])

Set a parameter of the class.

set_params(self, params_dict[, copy])

Set all parameters passed as a dictionary {key: value}.

set_state(self, state_dict[, copy])

Sets the object state using input dictionary.

timed([msg])

Timer decorator.

load(self)[source]

Loads the dataset.

Returns
datasetCDataset

The randomly generated dataset.

class secml.data.loader.c_dataloader_sklearn.CDLRandomBlobs(n_samples=100, n_features=2, centers=3, cluster_std=1.0, center_box=(-10.0, 10.0), random_state=None)[source]

Bases: secml.data.loader.c_dataloader.CDataLoader

Generate isotropic Gaussian blobs for clustering.

Parameters
n_samplesint, optional (default=100)

The total number of points equally divided among clusters.

n_featuresint, optional (default=2)

The number of features for each sample. This parameter will not be considered if centers is different from None

centersint or array of shape [n_centers, n_features]

The number of centers to generate (default=3), or the fixed center locations as list of tuples

cluster_std: float or sequence of floats, optional (default=1.0)

The standard deviation of the clusters.

center_boxpair of floats (min, max), optional (default=(-10.0, 10.0))

The bounding box for each cluster center when centers are generated at random.

random_stateint, RandomState instance or None, optional (default=None)

If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, is the RandomState instance used by np.random.

Attributes
class_type‘blobs’

Defines class type.

Methods

copy(self)

Returns a shallow copy of current class.

create([class_item])

This method creates an instance of a class with given type.

deepcopy(self)

Returns a deep copy of current class.

get_class_from_type(class_type)

Return the class associated with input type.

get_params(self)

Returns the dictionary of class hyperparameters.

get_state(self, **kwargs)

Returns the object state dictionary.

get_subclasses()

Get all the subclasses of the calling class.

list_class_types()

This method lists all types of available subclasses of calling one.

load(self)

Loads the dataset.

load_state(self, path)

Sets the object state from file.

save(self, path)

Save class object to file.

save_state(self, path, **kwargs)

Store the object state to file.

set(self, param_name, param_value[, copy])

Set a parameter of the class.

set_params(self, params_dict[, copy])

Set all parameters passed as a dictionary {key: value}.

set_state(self, state_dict[, copy])

Sets the object state using input dictionary.

timed([msg])

Timer decorator.

load(self)[source]

Loads the dataset.

Returns
datasetCDataset

The randomly generated dataset.

class secml.data.loader.c_dataloader_sklearn.CDLRandomBlobsRegression(n_samples=100, cluster_std=(1.0, 1.0), bias=1.0, w=(2.0, -1.0), centers=([0, 0], [-1, -1]), random_state=None)[source]

Bases: secml.data.loader.c_dataloader.CDataLoader

This class loads blobs regression.

Parameters
n_samplesint, optional (default=100)

The total number of points equally divided among clusters.

centersint or array of shape [n_centers, n_features], optional (default=3)

The number of centers to generate, or the fixed center locations.

cluster_std: list of floats, optional (default=(1.0,1.0))

The standard deviation of the clusters.

biasbias that will sum to the function
wthe height of every gaussian
centers: list of tuple optional (default=([1,1],[-1,-1]))

The bounding box for each cluster center when centers are generated at random.

random_stateint, RandomState instance or None, optional (default=None)

If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, is the RandomState instance used by np.random.

Attributes
class_type‘blobs-regression’

Defines class type.

Methods

copy(self)

Returns a shallow copy of current class.

create([class_item])

This method creates an instance of a class with given type.

deepcopy(self)

Returns a deep copy of current class.

get_class_from_type(class_type)

Return the class associated with input type.

get_params(self)

Returns the dictionary of class hyperparameters.

get_state(self, **kwargs)

Returns the object state dictionary.

get_subclasses()

Get all the subclasses of the calling class.

list_class_types()

This method lists all types of available subclasses of calling one.

load(self)

Loads the dataset.

load_state(self, path)

Sets the object state from file.

save(self, path)

Save class object to file.

save_state(self, path, **kwargs)

Store the object state to file.

set(self, param_name, param_value[, copy])

Set a parameter of the class.

set_params(self, params_dict[, copy])

Set all parameters passed as a dictionary {key: value}.

set_state(self, state_dict[, copy])

Sets the object state using input dictionary.

timed([msg])

Timer decorator.

load(self)[source]

Loads the dataset.

Returns
datasetCDataset

The randomly generated dataset.

class secml.data.loader.c_dataloader_sklearn.CDLRandomCircles(n_samples=100, noise=None, factor=0.8, random_state=None)[source]

Bases: secml.data.loader.c_dataloader.CDataLoader

Make a large circle containing a smaller circle in 2d.

Parameters
n_samplesint, optional (default=100)

The total number of points generated.

noisedouble or None (default=None)

Standard deviation of Gaussian noise added to the data.

factordouble < 1 (default=.8)

Scale factor between inner and outer circle.

random_stateint, RandomState instance or None, optional (default=None)

If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, is the RandomState instance used by np.random.

Attributes
class_type‘circles’

Defines class type.

Methods

copy(self)

Returns a shallow copy of current class.

create([class_item])

This method creates an instance of a class with given type.

deepcopy(self)

Returns a deep copy of current class.

get_class_from_type(class_type)

Return the class associated with input type.

get_params(self)

Returns the dictionary of class hyperparameters.

get_state(self, **kwargs)

Returns the object state dictionary.

get_subclasses()

Get all the subclasses of the calling class.

list_class_types()

This method lists all types of available subclasses of calling one.

load(self)

Loads the dataset.

load_state(self, path)

Sets the object state from file.

save(self, path)

Save class object to file.

save_state(self, path, **kwargs)

Store the object state to file.

set(self, param_name, param_value[, copy])

Set a parameter of the class.

set_params(self, params_dict[, copy])

Set all parameters passed as a dictionary {key: value}.

set_state(self, state_dict[, copy])

Sets the object state using input dictionary.

timed([msg])

Timer decorator.

load(self)[source]

Loads the dataset.

Returns
datasetCDataset

The randomly generated dataset.

class secml.data.loader.c_dataloader_sklearn.CDLRandomCircleRegression(n_samples=100, noise=None, factor=0.8, random_state=None)[source]

Bases: secml.data.loader.c_dataloader.CDataLoader

Make a large circle containing a smaller circle in 2d.

Parameters
n_samplesint, optional (default=100)

The total number of points generated.

noisedouble or None (default=None)

Standard deviation of Gaussian noise added to the data.

factordouble < 1 (default=.8)

Scale factor between inner and outer circle.

random_stateint, RandomState instance or None, optional (default=None)

If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, is the RandomState instance used by np.random.

Attributes
class_type‘circles-regression’

Defines class type.

Methods

copy(self)

Returns a shallow copy of current class.

create([class_item])

This method creates an instance of a class with given type.

deepcopy(self)

Returns a deep copy of current class.

get_class_from_type(class_type)

Return the class associated with input type.

get_params(self)

Returns the dictionary of class hyperparameters.

get_state(self, **kwargs)

Returns the object state dictionary.

get_subclasses()

Get all the subclasses of the calling class.

list_class_types()

This method lists all types of available subclasses of calling one.

load(self)

Loads the dataset.

load_state(self, path)

Sets the object state from file.

save(self, path)

Save class object to file.

save_state(self, path, **kwargs)

Store the object state to file.

set(self, param_name, param_value[, copy])

Set a parameter of the class.

set_params(self, params_dict[, copy])

Set all parameters passed as a dictionary {key: value}.

set_state(self, state_dict[, copy])

Sets the object state using input dictionary.

timed([msg])

Timer decorator.

load(self)[source]

Loads the dataset.

Returns
datasetCDataset

The randomly generated dataset.

class secml.data.loader.c_dataloader_sklearn.CDLRandomMoons(n_samples=100, noise=None, random_state=None)[source]

Bases: secml.data.loader.c_dataloader.CDataLoader

Make two interleaving half circles.

Parameters
n_samplesint, optional (default=100)

The total number of points generated.

noisedouble or None (default=None)

Standard deviation of Gaussian noise added to the data.

random_stateint, RandomState instance or None, optional (default=None)

If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, is the RandomState instance used by np.random.

Attributes
class_type‘moons’

Defines class type.

Methods

copy(self)

Returns a shallow copy of current class.

create([class_item])

This method creates an instance of a class with given type.

deepcopy(self)

Returns a deep copy of current class.

get_class_from_type(class_type)

Return the class associated with input type.

get_params(self)

Returns the dictionary of class hyperparameters.

get_state(self, **kwargs)

Returns the object state dictionary.

get_subclasses()

Get all the subclasses of the calling class.

list_class_types()

This method lists all types of available subclasses of calling one.

load(self)

Loads the dataset.

load_state(self, path)

Sets the object state from file.

save(self, path)

Save class object to file.

save_state(self, path, **kwargs)

Store the object state to file.

set(self, param_name, param_value[, copy])

Set a parameter of the class.

set_params(self, params_dict[, copy])

Set all parameters passed as a dictionary {key: value}.

set_state(self, state_dict[, copy])

Sets the object state using input dictionary.

timed([msg])

Timer decorator.

load(self)[source]

Loads the dataset.

Returns
datasetCDataset

The randomly generated dataset.

class secml.data.loader.c_dataloader_sklearn.CDLRandomBinary(n_samples=100, n_features=2)[source]

Bases: secml.data.loader.c_dataloader.CDataLoader

Generate random binary data.

Parameters
n_samplesint, optional (default=100)

The total number of points generated.

n_featuresint, optional (default=2)

The total number of features

Attributes
class_type‘binary’

Defines class type.

Methods

copy(self)

Returns a shallow copy of current class.

create([class_item])

This method creates an instance of a class with given type.

deepcopy(self)

Returns a deep copy of current class.

get_class_from_type(class_type)

Return the class associated with input type.

get_params(self)

Returns the dictionary of class hyperparameters.

get_state(self, **kwargs)

Returns the object state dictionary.

get_subclasses()

Get all the subclasses of the calling class.

list_class_types()

This method lists all types of available subclasses of calling one.

load(self)

Loads the dataset.

load_state(self, path)

Sets the object state from file.

save(self, path)

Save class object to file.

save_state(self, path, **kwargs)

Store the object state to file.

set(self, param_name, param_value[, copy])

Set a parameter of the class.

set_params(self, params_dict[, copy])

Set all parameters passed as a dictionary {key: value}.

set_state(self, state_dict[, copy])

Sets the object state using input dictionary.

timed([msg])

Timer decorator.

load(self)[source]

Loads the dataset.

Returns
datasetCDataset

The randomly generated dataset.

class secml.data.loader.c_dataloader_sklearn.CDLIris(class_list=None, zero_one=False)[source]

Bases: secml.data.loader.c_dataloader_sklearn.CDLRandomToy

Loads Iris dataset.

The iris dataset is a classic and very easy multi-class classification dataset.

Classes

3

Samples per class

50

Samples total

150

Dimensionality

4

Features

real, positive

Parameters
class_listlist of str (default None)

Each string is the name of data’s class that we want in the new dataset. If None every class will be keep

zero_onebool

If is true, and class list is equal to two, will be assigned 0 at the label with lower value, 1 to the other.

Attributes
class_type‘iris’

Defines class type.

Methods

copy(self)

Returns a shallow copy of current class.

create([class_item])

This method creates an instance of a class with given type.

deepcopy(self)

Returns a deep copy of current class.

get_class_from_type(class_type)

Return the class associated with input type.

get_params(self)

Returns the dictionary of class hyperparameters.

get_state(self, **kwargs)

Returns the object state dictionary.

get_subclasses()

Get all the subclasses of the calling class.

list_class_types()

This method lists all types of available subclasses of calling one.

load(self)

Loads the dataset.

load_state(self, path)

Sets the object state from file.

save(self, path)

Save class object to file.

save_state(self, path, **kwargs)

Store the object state to file.

set(self, param_name, param_value[, copy])

Set a parameter of the class.

set_params(self, params_dict[, copy])

Set all parameters passed as a dictionary {key: value}.

set_state(self, state_dict[, copy])

Sets the object state using input dictionary.

timed([msg])

Timer decorator.

toy = 'iris'
class secml.data.loader.c_dataloader_sklearn.CDLDigits(class_list=None, zero_one=False)[source]

Bases: secml.data.loader.c_dataloader_sklearn.CDLRandomToy

Loads Digits dataset.

The digits dataset is a classic and very easy multi-class classification dataset. Each datapoint is a 8x8 image of a digit.

Classes

10

Samples per class

~180

Samples total

1797

Dimensionality

64

Features

integers 0-16

Parameters
class_listlist of str (default None)

Each string is the name of data’s class that we want in the new dataset. If None every class will be keep

zero_onebool

If is true, and class list is equal to two, will be assigned 0 at the label with lower value, 1 to the other.

Attributes
class_type‘digits’

Defines class type.

Methods

copy(self)

Returns a shallow copy of current class.

create([class_item])

This method creates an instance of a class with given type.

deepcopy(self)

Returns a deep copy of current class.

get_class_from_type(class_type)

Return the class associated with input type.

get_params(self)

Returns the dictionary of class hyperparameters.

get_state(self, **kwargs)

Returns the object state dictionary.

get_subclasses()

Get all the subclasses of the calling class.

list_class_types()

This method lists all types of available subclasses of calling one.

load(self)

Loads the dataset.

load_state(self, path)

Sets the object state from file.

save(self, path)

Save class object to file.

save_state(self, path, **kwargs)

Store the object state to file.

set(self, param_name, param_value[, copy])

Set a parameter of the class.

set_params(self, params_dict[, copy])

Set all parameters passed as a dictionary {key: value}.

set_state(self, state_dict[, copy])

Sets the object state using input dictionary.

timed([msg])

Timer decorator.

toy = 'digits'
class secml.data.loader.c_dataloader_sklearn.CDLBoston(class_list=None, zero_one=False)[source]

Bases: secml.data.loader.c_dataloader_sklearn.CDLRandomToy

Loads Boston dataset.

Boston house-prices dataset, useful for regression.

Samples total

506

Dimensionality

13

Features

real, positive

Targets

real 5. - 50.

Parameters
class_listlist of str (default None)

Each string is the name of data’s class that we want in the new dataset. If None every class will be keep

zero_onebool

If is true, and class list is equal to two, will be assigned 0 at the label with lower value, 1 to the other.

Attributes
class_type‘boston’

Defines class type.

Methods

copy(self)

Returns a shallow copy of current class.

create([class_item])

This method creates an instance of a class with given type.

deepcopy(self)

Returns a deep copy of current class.

get_class_from_type(class_type)

Return the class associated with input type.

get_params(self)

Returns the dictionary of class hyperparameters.

get_state(self, **kwargs)

Returns the object state dictionary.

get_subclasses()

Get all the subclasses of the calling class.

list_class_types()

This method lists all types of available subclasses of calling one.

load(self)

Loads the dataset.

load_state(self, path)

Sets the object state from file.

save(self, path)

Save class object to file.

save_state(self, path, **kwargs)

Store the object state to file.

set(self, param_name, param_value[, copy])

Set a parameter of the class.

set_params(self, params_dict[, copy])

Set all parameters passed as a dictionary {key: value}.

set_state(self, state_dict[, copy])

Sets the object state using input dictionary.

timed([msg])

Timer decorator.

toy = 'boston'
class secml.data.loader.c_dataloader_sklearn.CDLDiabetes(class_list=None, zero_one=False)[source]

Bases: secml.data.loader.c_dataloader_sklearn.CDLRandomToy

Loads Diabetes dataset.

Diabetes dataset, useful for regression.

Samples total

442

Dimensionality

10

Features

real, -.2 < x < .2

Targets

integer 25 - 346

Parameters
class_listlist of str (default None)

Each string is the name of data’s class that we want in the new dataset. If None every class will be keep

zero_onebool

If is true, and class list is equal to two, will be assigned 0 at the label with lower value, 1 to the other.

Attributes
class_type‘diabetes’

Defines class type.

Methods

copy(self)

Returns a shallow copy of current class.

create([class_item])

This method creates an instance of a class with given type.

deepcopy(self)

Returns a deep copy of current class.

get_class_from_type(class_type)

Return the class associated with input type.

get_params(self)

Returns the dictionary of class hyperparameters.

get_state(self, **kwargs)

Returns the object state dictionary.

get_subclasses()

Get all the subclasses of the calling class.

list_class_types()

This method lists all types of available subclasses of calling one.

load(self)

Loads the dataset.

load_state(self, path)

Sets the object state from file.

save(self, path)

Save class object to file.

save_state(self, path, **kwargs)

Store the object state to file.

set(self, param_name, param_value[, copy])

Set a parameter of the class.

set_params(self, params_dict[, copy])

Set all parameters passed as a dictionary {key: value}.

set_state(self, state_dict[, copy])

Sets the object state using input dictionary.

timed([msg])

Timer decorator.

toy = 'diabetes'

CDataLoaderSvmLight

class secml.data.loader.c_dataloader_svmlight.CDataLoaderSvmLight[source]

Bases: secml.data.loader.c_dataloader.CDataLoader

Loads and Saves data in svmlight / libsvm format.

Attributes
class_type‘svmlight’

Defines class type.

Methods

copy(self)

Returns a shallow copy of current class.

create([class_item])

This method creates an instance of a class with given type.

deepcopy(self)

Returns a deep copy of current class.

dump(d, f[, zero_based, comment])

Dumps a dataset in the svmlight / libsvm file format.

get_class_from_type(class_type)

Return the class associated with input type.

get_params(self)

Returns the dictionary of class hyperparameters.

get_state(self, **kwargs)

Returns the object state dictionary.

get_subclasses()

Get all the subclasses of the calling class.

list_class_types()

This method lists all types of available subclasses of calling one.

load(self, file_path[, dtype_samples, …])

Loads a dataset from the svmlight / libsvm format and returns a sparse dataset.

load_state(self, path)

Sets the object state from file.

save(self, path)

Save class object to file.

save_state(self, path, **kwargs)

Store the object state to file.

set(self, param_name, param_value[, copy])

Set a parameter of the class.

set_params(self, params_dict[, copy])

Set all parameters passed as a dictionary {key: value}.

set_state(self, state_dict[, copy])

Sets the object state using input dictionary.

timed([msg])

Timer decorator.

static dump(d, f, zero_based=True, comment=None)[source]

Dumps a dataset in the svmlight / libsvm file format.

This format is a text-based format, with one sample per line. It does not store zero valued features hence is suitable for sparse dataset.

The first element of each line can be used to store a target variable to predict.

Parameters
dCDataset

Contain dataset with patterns and labels that we want store.

fString

Path to file were we want store dataset into format svmlight or libsvm.

zero_basedbool, optional

Whether column indices should be written zero-based (True, default) or one-based (False).

commentstring, optional

Comment to insert at the top of the file. This should be either a Unicode string, which will be encoded as UTF-8, or an ASCII byte string. If a comment is given, then it will be preceded by one that identifies the file as having been dumped by scikit-learn. Note that not all tools grok comments in SVMlight files.

Examples

>>> from secml.data.loader import CDataLoaderSvmLight
>>> from secml.array import CArray
>>> patterns = CArray([[1,0,2], [4,0,5]])
>>> labels = CArray([0,1])
>>> CDataLoaderSvmLight.dump(CDataset(patterns,labels), "myfile.libsvm")
load(self, file_path, dtype_samples=<class 'float'>, dtype_labels=<class 'float'>, n_features=None, zero_based=True, remove_all_zero=False, multilabel=False, load_infos=False)[source]

Loads a dataset from the svmlight / libsvm format and returns a sparse dataset.

Datasets must have only numerical feature indices and for every pattern indices must be ordered.

Extra dataset attributes:
  • ‘infos’, CArray with inline comment for each sample.

Parameters
file_pathString

Path to file were dataset are stored into format svmlight or libsvm.

dtype_samplesstr or dtype, optional

Data-type to which the samples should be casted. Default is float.

dtype_labelsstr or dtype, optional

Data-type to which the labels should be casted. Default is float.

n_featuresNone or int, optional

The number of features to use. If None (default), it will be inferred. This argument is useful to load several files that are subsets of a bigger sliced dataset: each subset might not have examples of every feature, hence the inferred shape might vary from one slice to another.

zero_based: bool, optional

Whether column indices are zero-based (True, default) or one-based (False). If column indices are set to be one-based, they are transformed to zero-based to match Python/NumPy conventions.

remove_all_zero: boolean, optional, default True

If True every feature which is zero for every pattern will be removed from dataset.

multilabelboolean, optional

True if every sample can have more than one label. Default False. (see http://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/multilabel.html)

load_infosbool, optional

If True, inline comments will be loaded from the svmlight file and stored in the infos CDataset parameter (as CArray). Default False.

Returns
datasetCDataset

Dataset object that contain patterns and labels. If remove_all_zero is set to True, the returned dataset will have the new argument idx_mapping with the mapping of the returned features to the original features’s indices.

Examples

>>> from secml.data.loader import CDataLoaderSvmLight
>>> from secml.array import CArray
>>> patterns = CArray ([[1,0,2], [4,0,5]])
>>> labels = CArray ([0, 1])
>>> CDataLoaderSvmLight().dump(CDataset(patterns,labels), "myfile.libsvm")
>>> new_dataset = CDataLoaderSvmLight().load("myfile.libsvm", remove_all_zero=True)
>>> print(new_dataset.X)  
CArray(  (0, 1) 2.0
  (0, 0)        1.0
  (1, 1)        5.0
  (1, 0)        4.0)
>>> print(new_dataset.Y)
CArray([0. 1.])
>>> print(new_dataset.header.idx_mapping)
CArray([0 2])

CDataLoaderTorchDataset

loader_utils

secml.data.loader.loader_utils.resize_img(img, shape)[source]

Resize input image to desired shape.

If the input image is bigger than desired, the LANCZOS filter will be used. If calculates the output pixel value using a truncated sinc filter on all pixels that may contribute to the output value.

Otherwise, a LINEAR filter will be used. It calculates the output pixel value using linear interpolation on all pixels that may contribute to the output value.

Parameters
imgPIL.Image.Image

Image to be resized.

shapetuple

Desired output image dimensions (height, width).

Returns
PIL.Image

Resized image.

secml.data.loader.loader_utils.crop_img(img, crop)[source]

Extract a center crop of the input image.

Parameters
imgPIL.Image.Image

Image to be cropped.

croptuple

Dimensions of the desired crop (height, width).

Returns
PIL.Image

Cropped image.

Notes

The image center will be computed by rounding the coordinates if necessary. Python round default behavior is toward the closest even decimal.