Image ClassificationΒΆ

Downloading http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-images-idx3-ubyte.gz
Downloading http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-images-idx3-ubyte.gz to ../datasets/FashionMNIST/raw/train-images-idx3-ubyte.gz

  0%|          | 0/26421880 [00:00<?, ?it/s]
  0%|          | 32768/26421880 [00:00<01:51, 236445.57it/s]
  0%|          | 65536/26421880 [00:00<01:52, 234808.83it/s]
  0%|          | 131072/26421880 [00:00<01:17, 341431.84it/s]
  1%|          | 229376/26421880 [00:00<00:54, 483668.83it/s]
  2%|1         | 425984/26421880 [00:00<00:31, 815346.34it/s]
  3%|3         | 884736/26421880 [00:00<00:15, 1651167.69it/s]
  7%|6         | 1736704/26421880 [00:00<00:07, 3098176.51it/s]
 13%|#3        | 3473408/26421880 [00:01<00:03, 6053558.15it/s]
 25%|##4       | 6520832/26421880 [00:01<00:01, 10955469.82it/s]
 36%|###5      | 9502720/26421880 [00:01<00:01, 14135848.45it/s]
 47%|####6     | 12353536/26421880 [00:01<00:00, 16012286.53it/s]
 59%|#####8    | 15466496/26421880 [00:01<00:00, 17895771.35it/s]
 70%|#######   | 18579456/26421880 [00:01<00:00, 19202670.77it/s]
 82%|########1 | 21659648/26421880 [00:01<00:00, 20038729.44it/s]
 94%|#########3| 24707072/26421880 [00:02<00:00, 20540653.50it/s]
100%|##########| 26421880/26421880 [00:02<00:00, 12493718.77it/s]
Extracting ../datasets/FashionMNIST/raw/train-images-idx3-ubyte.gz to ../datasets/FashionMNIST/raw

Downloading http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-labels-idx1-ubyte.gz
Downloading http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-labels-idx1-ubyte.gz to ../datasets/FashionMNIST/raw/train-labels-idx1-ubyte.gz

  0%|          | 0/29515 [00:00<?, ?it/s]
100%|##########| 29515/29515 [00:00<00:00, 216269.98it/s]
100%|##########| 29515/29515 [00:00<00:00, 215769.39it/s]
Extracting ../datasets/FashionMNIST/raw/train-labels-idx1-ubyte.gz to ../datasets/FashionMNIST/raw

Downloading http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-images-idx3-ubyte.gz
Downloading http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-images-idx3-ubyte.gz to ../datasets/FashionMNIST/raw/t10k-images-idx3-ubyte.gz

  0%|          | 0/4422102 [00:00<?, ?it/s]
  1%|          | 32768/4422102 [00:00<00:18, 235859.65it/s]
  1%|1         | 65536/4422102 [00:00<00:18, 235542.93it/s]
  3%|2         | 131072/4422102 [00:00<00:12, 342772.89it/s]
  5%|5         | 229376/4422102 [00:00<00:08, 485751.87it/s]
 10%|#         | 458752/4422102 [00:00<00:04, 904252.33it/s]
 21%|##1       | 950272/4422102 [00:00<00:01, 1795827.14it/s]
 42%|####2     | 1867776/4422102 [00:00<00:00, 3361340.10it/s]
 85%|########5 | 3768320/4422102 [00:01<00:00, 6633015.81it/s]
100%|##########| 4422102/4422102 [00:01<00:00, 3960860.46it/s]
Extracting ../datasets/FashionMNIST/raw/t10k-images-idx3-ubyte.gz to ../datasets/FashionMNIST/raw

Downloading http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-labels-idx1-ubyte.gz
Downloading http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-labels-idx1-ubyte.gz to ../datasets/FashionMNIST/raw/t10k-labels-idx1-ubyte.gz

  0%|          | 0/5148 [00:00<?, ?it/s]
100%|##########| 5148/5148 [00:00<00:00, 37551786.07it/s]
Extracting ../datasets/FashionMNIST/raw/t10k-labels-idx1-ubyte.gz to ../datasets/FashionMNIST/raw

Pipeline CS:
 ________________________________________
Configuration space object:
  Hyperparameters:
    image_augmenter:GaussianBlur:sigma_min, Type: UniformFloat, Range: [0.0, 3.0], Default: 0.0
    image_augmenter:GaussianBlur:sigma_offset, Type: UniformFloat, Range: [0.0, 3.0], Default: 0.5
    image_augmenter:GaussianBlur:use_augmenter, Type: Categorical, Choices: {True, False}, Default: True
    image_augmenter:GaussianNoise:sigma_offset, Type: UniformFloat, Range: [0.0, 3.0], Default: 0.3
    image_augmenter:GaussianNoise:use_augmenter, Type: Categorical, Choices: {True, False}, Default: True
    image_augmenter:RandomAffine:rotate, Type: UniformInteger, Range: [0, 360], Default: 45
    image_augmenter:RandomAffine:scale_offset, Type: UniformFloat, Range: [0.0, 0.4], Default: 0.2
    image_augmenter:RandomAffine:shear, Type: UniformInteger, Range: [0, 45], Default: 30
    image_augmenter:RandomAffine:translate_percent_offset, Type: UniformFloat, Range: [0.0, 0.4], Default: 0.2
    image_augmenter:RandomAffine:use_augmenter, Type: Categorical, Choices: {True, False}, Default: True
    image_augmenter:RandomCutout:p, Type: UniformFloat, Range: [0.2, 1.0], Default: 0.5
    image_augmenter:RandomCutout:use_augmenter, Type: Categorical, Choices: {True, False}, Default: True
    image_augmenter:Resize:use_augmenter, Type: Categorical, Choices: {True, False}, Default: True
    image_augmenter:ZeroPadAndCrop:percent, Type: UniformFloat, Range: [0.0, 0.5], Default: 0.1
    normalizer:__choice__, Type: Categorical, Choices: {ImageNormalizer, NoNormalizer}, Default: ImageNormalizer
  Conditions:
    image_augmenter:GaussianBlur:sigma_min | image_augmenter:GaussianBlur:use_augmenter == True
    image_augmenter:GaussianBlur:sigma_offset | image_augmenter:GaussianBlur:use_augmenter == True
    image_augmenter:GaussianNoise:sigma_offset | image_augmenter:GaussianNoise:use_augmenter == True
    image_augmenter:RandomAffine:rotate | image_augmenter:RandomAffine:use_augmenter == True
    image_augmenter:RandomAffine:scale_offset | image_augmenter:RandomAffine:use_augmenter == True
    image_augmenter:RandomAffine:shear | image_augmenter:RandomAffine:use_augmenter == True
    image_augmenter:RandomAffine:translate_percent_offset | image_augmenter:RandomAffine:use_augmenter == True
    image_augmenter:RandomCutout:p | image_augmenter:RandomCutout:use_augmenter == True

Pipeline Random Config:
 ________________________________________
Configuration(values={
  'image_augmenter:GaussianBlur:sigma_min': 2.312887380869346,
  'image_augmenter:GaussianBlur:sigma_offset': 0.8251033245136351,
  'image_augmenter:GaussianBlur:use_augmenter': True,
  'image_augmenter:GaussianNoise:use_augmenter': False,
  'image_augmenter:RandomAffine:rotate': 110,
  'image_augmenter:RandomAffine:scale_offset': 0.11439592322068953,
  'image_augmenter:RandomAffine:shear': 6,
  'image_augmenter:RandomAffine:translate_percent_offset': 0.3407850766387634,
  'image_augmenter:RandomAffine:use_augmenter': True,
  'image_augmenter:RandomCutout:use_augmenter': False,
  'image_augmenter:Resize:use_augmenter': True,
  'image_augmenter:ZeroPadAndCrop:percent': 0.07516526218770092,
  'normalizer:__choice__': 'NoNormalizer',
})

Fitting the pipeline...
________________________________________
        ImageClassificationPipeline
________________________________________
0-) normalizer:
        NoNormalizer

1-) preprocessing:
        EarlyPreprocessing

2-) image_augmenter:
        ImageAugmenter

________________________________________

import numpy as np

import sklearn.model_selection

import torchvision.datasets

from autoPyTorch.pipeline.image_classification import ImageClassificationPipeline

# Get the training data for tabular classification
trainset = torchvision.datasets.FashionMNIST(root='../datasets/', train=True, download=True)
data = trainset.data.numpy()
data = np.expand_dims(data, axis=3)
# Create a proof of concept pipeline!
dataset_properties = dict()
pipeline = ImageClassificationPipeline(dataset_properties=dataset_properties)

# Train and test split
train_indices, val_indices = sklearn.model_selection.train_test_split(
    list(range(data.shape[0])),
    random_state=1,
    test_size=0.25,
)

# Configuration space
pipeline_cs = pipeline.get_hyperparameter_search_space()
print("Pipeline CS:\n", '_' * 40, f"\n{pipeline_cs}")
config = pipeline_cs.sample_configuration()
print("Pipeline Random Config:\n", '_' * 40, f"\n{config}")
pipeline.set_hyperparameters(config)

# Fit the pipeline
print("Fitting the pipeline...")

pipeline.fit(X=dict(X_train=data,
                    is_small_preprocess=True,
                    dataset_properties=dict(mean=np.array([np.mean(data[:, :, :, i]) for i in range(1)]),
                                            std=np.array([np.std(data[:, :, :, i]) for i in range(1)]),
                                            num_classes=10,
                                            num_features=data.shape[1] * data.shape[2],
                                            image_height=data.shape[1],
                                            image_width=data.shape[2],
                                            is_small_preprocess=True),
                    train_indices=train_indices,
                    val_indices=val_indices,
                    )
             )

# Showcase some components of the pipeline
print(pipeline)

Total running time of the script: ( 0 minutes 7.097 seconds)

Gallery generated by Sphinx-Gallery