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%|          | 65536/26421880 [00:00<01:11, 366290.45it/s]
  1%|          | 163840/26421880 [00:00<00:41, 638849.88it/s]
  2%|1         | 425984/26421880 [00:00<00:23, 1121398.14it/s]
  5%|5         | 1343488/26421880 [00:00<00:06, 3583652.91it/s]
 13%|#2        | 3375104/26421880 [00:00<00:03, 7221270.28it/s]
 30%|##9       | 7798784/26421880 [00:00<00:01, 17052458.82it/s]
 46%|####6     | 12222464/26421880 [00:00<00:00, 24527382.31it/s]
 60%|######    | 15958016/26421880 [00:01<00:00, 24317522.28it/s]
 75%|#######5  | 19857408/26421880 [00:01<00:00, 28004904.63it/s]
 91%|######### | 23986176/26421880 [00:01<00:00, 31573997.04it/s]
100%|##########| 26421880/26421880 [00:01<00:00, 19482809.65it/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, 343239.68it/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%|1         | 65536/4422102 [00:00<00:11, 368748.32it/s]
  4%|3         | 163840/4422102 [00:00<00:06, 620241.46it/s]
 10%|9         | 425984/4422102 [00:00<00:03, 1127167.98it/s]
 30%|##9       | 1310720/4422102 [00:00<00:00, 3413041.14it/s]
 79%|#######8  | 3473408/4422102 [00:00<00:00, 7527372.13it/s]
100%|##########| 4422102/4422102 [00:00<00:00, 6146212.34it/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, 27969270.72it/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:use_augmenter': False,
  'image_augmenter:GaussianNoise:sigma_offset': 0.792548037014256,
  'image_augmenter:GaussianNoise:use_augmenter': True,
  'image_augmenter:RandomAffine:rotate': 48,
  'image_augmenter:RandomAffine:scale_offset': 0.19272327038467085,
  'image_augmenter:RandomAffine:shear': 43,
  'image_augmenter:RandomAffine:translate_percent_offset': 0.0386268474262987,
  'image_augmenter:RandomAffine:use_augmenter': True,
  'image_augmenter:RandomCutout:use_augmenter': False,
  'image_augmenter:Resize:use_augmenter': False,
  'image_augmenter:ZeroPadAndCrop:percent': 0.15706347089750722,
  'normalizer:__choice__': 'ImageNormalizer',
})

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

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 5.757 seconds)

Gallery generated by Sphinx-Gallery