cifar10-tools 0.3.0__tar.gz → 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,72 @@
1
+ Metadata-Version: 2.4
2
+ Name: cifar10_tools
3
+ Version: 0.4.0
4
+ Summary: Tools for training neural networks on the CIFAR-10 task with PyTorch and TensorFlow
5
+ License: GPLv3
6
+ License-File: LICENSE
7
+ Keywords: Python,Machine learning,Deep learning,CNNs,Computer vision,Image classification,CIFAR-10
8
+ Author: gperdrizet
9
+ Author-email: george@perdrizet.org
10
+ Requires-Python: >=3.10,<3.13
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Education
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
16
+ Classifier: License :: Other/Proprietary License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
23
+ Classifier: Topic :: Scientific/Engineering :: Image Recognition
24
+ Provides-Extra: tensorflow
25
+ Requires-Dist: numpy (>=1.24)
26
+ Requires-Dist: torch (>=2.0)
27
+ Requires-Dist: torchvision (>=0.15)
28
+ Project-URL: Documentation, https://gperdrizet.github.io/CIFAR10/README.md
29
+ Project-URL: Homepage, https://github.com/gperdrizet/CIFAR10
30
+ Project-URL: Issues, https://github.com/gperdrizet/CIFAR10/issues
31
+ Project-URL: PyPI, https://pypi.org/project/cifar10_tools
32
+ Project-URL: Repository, https://github.com/gperdrizet/CIFAR10
33
+ Description-Content-Type: text/markdown
34
+
35
+ # PyTorch: CIFAR-10 Demonstration
36
+
37
+ A progressive deep learning tutorial for image classification on the CIFAR-10 dataset using PyTorch. This project demonstrates the evolution from basic deep neural networks to optimized convolutional neural networks with data augmentation. It also provides a set of utility functions as a PyPI package for use in other projects.
38
+
39
+ [View on PyPI](https://pypi.org/project/cifar10_tools)
40
+
41
+ ## Installation
42
+
43
+ Install the helper tools package locally in editable mode:
44
+
45
+ ```bash
46
+ pip install -e .
47
+ ```
48
+
49
+ ## Project Overview
50
+
51
+ This repository contains a series of Jupyter notebooks that progressively build more sophisticated neural network architectures for the CIFAR-10 image classification task. Each notebook builds upon concepts from the previous one, demonstrating key deep learning techniques.
52
+
53
+ ## Notebooks
54
+
55
+ | Notebook | Description |
56
+ |----------|-------------|
57
+ | [01-DNN.ipynb](notebooks/01-DNN.ipynb) | **Deep Neural Network** - Baseline fully-connected DNN classifier using `nn.Sequential`. Establishes a performance baseline with a simple architecture. |
58
+ | [02-CNN.ipynb](notebooks/02-CNN.ipynb) | **Convolutional Neural Network** - Introduction to CNNs with convolutional and pooling layers using `nn.Sequential`. Demonstrates the advantage of CNNs over DNNs for image tasks. |
59
+ | [03-RGB-CNN.ipynb](notebooks/03-RGB-CNN.ipynb) | **RGB CNN** - CNN classifier that utilizes full RGB color information instead of grayscale, improving feature extraction from color images. |
60
+ | [04-optimized-CNN.ipynb](notebooks/04-optimized-CNN.ipynb) | **Hyperparameter Optimization** - Uses Optuna for automated hyperparameter tuning to find optimal network architecture and training parameters. |
61
+ | [05-augmented-CNN.ipynb](notebooks/05-augmented-CNN.ipynb) | **Data Augmentation** - Trains the optimized CNN architecture with image augmentation techniques for improved generalization and robustness. |
62
+
63
+ ## Requirements
64
+
65
+ - Python >=3.10, <3.13
66
+ - PyTorch >=2.0
67
+ - torchvision >=0.15
68
+ - numpy >=1.24
69
+
70
+ ## License
71
+
72
+ This project is licensed under the GPLv3 License - see the [LICENSE](LICENSE) file for details.
@@ -0,0 +1,38 @@
1
+ # PyTorch: CIFAR-10 Demonstration
2
+
3
+ A progressive deep learning tutorial for image classification on the CIFAR-10 dataset using PyTorch. This project demonstrates the evolution from basic deep neural networks to optimized convolutional neural networks with data augmentation. It also provides a set of utility functions as a PyPI package for use in other projects.
4
+
5
+ [View on PyPI](https://pypi.org/project/cifar10_tools)
6
+
7
+ ## Installation
8
+
9
+ Install the helper tools package locally in editable mode:
10
+
11
+ ```bash
12
+ pip install -e .
13
+ ```
14
+
15
+ ## Project Overview
16
+
17
+ This repository contains a series of Jupyter notebooks that progressively build more sophisticated neural network architectures for the CIFAR-10 image classification task. Each notebook builds upon concepts from the previous one, demonstrating key deep learning techniques.
18
+
19
+ ## Notebooks
20
+
21
+ | Notebook | Description |
22
+ |----------|-------------|
23
+ | [01-DNN.ipynb](notebooks/01-DNN.ipynb) | **Deep Neural Network** - Baseline fully-connected DNN classifier using `nn.Sequential`. Establishes a performance baseline with a simple architecture. |
24
+ | [02-CNN.ipynb](notebooks/02-CNN.ipynb) | **Convolutional Neural Network** - Introduction to CNNs with convolutional and pooling layers using `nn.Sequential`. Demonstrates the advantage of CNNs over DNNs for image tasks. |
25
+ | [03-RGB-CNN.ipynb](notebooks/03-RGB-CNN.ipynb) | **RGB CNN** - CNN classifier that utilizes full RGB color information instead of grayscale, improving feature extraction from color images. |
26
+ | [04-optimized-CNN.ipynb](notebooks/04-optimized-CNN.ipynb) | **Hyperparameter Optimization** - Uses Optuna for automated hyperparameter tuning to find optimal network architecture and training parameters. |
27
+ | [05-augmented-CNN.ipynb](notebooks/05-augmented-CNN.ipynb) | **Data Augmentation** - Trains the optimized CNN architecture with image augmentation techniques for improved generalization and robustness. |
28
+
29
+ ## Requirements
30
+
31
+ - Python >=3.10, <3.13
32
+ - PyTorch >=2.0
33
+ - torchvision >=0.15
34
+ - numpy >=1.24
35
+
36
+ ## License
37
+
38
+ This project is licensed under the GPLv3 License - see the [LICENSE](LICENSE) file for details.
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
4
4
 
5
5
  [tool.poetry]
6
6
  name = "cifar10_tools"
7
- version = "0.3.0"
7
+ version = "0.4.0"
8
8
  description = "Tools for training neural networks on the CIFAR-10 task with PyTorch and TensorFlow"
9
9
  authors = ["gperdrizet <george@perdrizet.org>"]
10
10
  readme = "README.md"
@@ -0,0 +1,135 @@
1
+ '''Data loading and preprocessing functions for CIFAR-10 dataset.'''
2
+
3
+ from pathlib import Path
4
+ import torch
5
+ from torchvision import datasets, transforms
6
+ from torch.utils.data import DataLoader
7
+
8
+
9
+ def download_cifar10_data(data_dir: str='data/pytorch/cifar10'):
10
+ '''Download CIFAR-10 dataset using torchvision.datasets.'''
11
+
12
+ data_dir = Path(data_dir)
13
+ data_dir.mkdir(parents=True, exist_ok=True)
14
+
15
+ _ = datasets.CIFAR10(
16
+ root=data_dir,
17
+ train=True,
18
+ download=True
19
+ )
20
+
21
+ _ = datasets.CIFAR10(
22
+ root=data_dir,
23
+ train=False,
24
+ download=True
25
+ )
26
+
27
+
28
+ def make_data_loaders(
29
+ data_dir: Path,
30
+ batch_size: int,
31
+ train_transform: transforms.Compose,
32
+ eval_transform: transforms.Compose,
33
+ device: torch.device | None = None,
34
+ download: bool = False,
35
+ ):
36
+ """
37
+ Loads CIFAR-10, applies preprocessing with separate train/eval transforms,
38
+ and returns DataLoaders.
39
+
40
+ Args:
41
+ data_dir: Path to CIFAR-10 data directory
42
+ batch_size: Batch size for DataLoaders
43
+ train_transform: Transform to apply to training data
44
+ eval_transform: Transform to apply to validation and test data
45
+ device: Device to preload tensors onto. If None, data stays on CPU
46
+ and transforms are applied on-the-fly during iteration.
47
+ download: Whether to download the dataset if not present
48
+
49
+ Returns:
50
+ Tuple of (train_loader, val_loader, test_loader)
51
+ """
52
+
53
+ # Load datasets with respective transforms
54
+ train_dataset_full = datasets.CIFAR10(
55
+ root=data_dir,
56
+ train=True,
57
+ download=download,
58
+ transform=train_transform,
59
+ )
60
+
61
+ val_test_dataset_full = datasets.CIFAR10(
62
+ root=data_dir,
63
+ train=True,
64
+ download=download,
65
+ transform=eval_transform,
66
+ )
67
+
68
+ test_dataset = datasets.CIFAR10(
69
+ root=data_dir,
70
+ train=False,
71
+ download=download,
72
+ transform=eval_transform,
73
+ )
74
+
75
+ if device is not None:
76
+ # Preload entire dataset to device for faster training
77
+ X_train_full = torch.stack([img for img, _ in train_dataset_full]).to(device)
78
+ y_train_full = torch.tensor([label for _, label in train_dataset_full]).to(device)
79
+
80
+ X_val_test_full = torch.stack([img for img, _ in val_test_dataset_full]).to(device)
81
+ y_val_test_full = torch.tensor([label for _, label in val_test_dataset_full]).to(device)
82
+
83
+ X_test = torch.stack([img for img, _ in test_dataset]).to(device)
84
+ y_test = torch.tensor([label for _, label in test_dataset]).to(device)
85
+
86
+ # Train/val split (80/20)
87
+ n_train = int(0.8 * len(X_train_full))
88
+ indices = torch.randperm(len(X_train_full))
89
+
90
+ X_train = X_train_full[indices[:n_train]]
91
+ y_train = y_train_full[indices[:n_train]]
92
+ X_val = X_val_test_full[indices[n_train:]]
93
+ y_val = y_val_test_full[indices[n_train:]]
94
+
95
+ # TensorDatasets
96
+ train_tensor_dataset = torch.utils.data.TensorDataset(X_train, y_train)
97
+ val_tensor_dataset = torch.utils.data.TensorDataset(X_val, y_val)
98
+ test_tensor_dataset = torch.utils.data.TensorDataset(X_test, y_test)
99
+
100
+ else:
101
+ # Don't preload - use datasets directly for on-the-fly transforms
102
+ # Train/val split (80/20) using Subset
103
+ n_train = int(0.8 * len(train_dataset_full))
104
+ indices = torch.randperm(len(train_dataset_full)).tolist()
105
+
106
+ train_indices = indices[:n_train]
107
+ val_indices = indices[n_train:]
108
+
109
+ train_tensor_dataset = torch.utils.data.Subset(train_dataset_full, train_indices)
110
+ val_tensor_dataset = torch.utils.data.Subset(val_test_dataset_full, val_indices)
111
+ test_tensor_dataset = test_dataset
112
+
113
+ # DataLoaders
114
+ train_loader = DataLoader(
115
+ train_tensor_dataset,
116
+ batch_size=batch_size,
117
+ shuffle=True,
118
+ )
119
+ val_loader = DataLoader(
120
+ val_tensor_dataset,
121
+ batch_size=batch_size,
122
+ shuffle=False,
123
+ )
124
+ test_loader = DataLoader(
125
+ test_tensor_dataset,
126
+ batch_size=batch_size,
127
+ shuffle=False,
128
+ )
129
+
130
+ return train_loader, val_loader, test_loader
131
+
132
+
133
+ if __name__ == '__main__':
134
+
135
+ download_cifar10_data()
@@ -12,13 +12,17 @@ import torch.nn as nn
12
12
  import torch.optim as optim
13
13
  from torch.utils.data import DataLoader
14
14
 
15
+ from cifar10_tools.pytorch.data import make_data_loaders
16
+
15
17
 
16
18
  def create_cnn(
17
19
  n_conv_blocks: int,
18
20
  initial_filters: int,
19
- fc_units_1: int,
20
- fc_units_2: int,
21
- dropout_rate: float,
21
+ n_fc_layers: int,
22
+ base_kernel_size: int,
23
+ conv_dropout_rate: float,
24
+ fc_dropout_rate: float,
25
+ pooling_strategy: str,
22
26
  use_batch_norm: bool,
23
27
  num_classes: int = 10,
24
28
  in_channels: int = 3,
@@ -29,9 +33,11 @@ def create_cnn(
29
33
  Args:
30
34
  n_conv_blocks: Number of convolutional blocks (1-5)
31
35
  initial_filters: Number of filters in first conv layer (doubles each block)
32
- fc_units_1: Number of units in first fully connected layer
33
- fc_units_2: Number of units in second fully connected layer
34
- dropout_rate: Dropout probability
36
+ n_fc_layers: Number of fully connected layers (1-8)
37
+ base_kernel_size: Base kernel size (decreases by 2 per block, min 3)
38
+ conv_dropout_rate: Dropout probability after convolutional blocks
39
+ fc_dropout_rate: Dropout probability in fully connected layers
40
+ pooling_strategy: Pooling type ('max' or 'avg')
35
41
  use_batch_norm: Whether to use batch normalization
36
42
  num_classes: Number of output classes (default: 10 for CIFAR-10)
37
43
  in_channels: Number of input channels (default: 3 for RGB)
@@ -44,11 +50,14 @@ def create_cnn(
44
50
  current_channels = in_channels
45
51
  current_size = input_size
46
52
 
53
+ # Convolutional blocks
47
54
  for block_idx in range(n_conv_blocks):
48
55
  out_channels = initial_filters * (2 ** block_idx)
56
+ kernel_size = max(3, base_kernel_size - 2 * block_idx)
57
+ padding = kernel_size // 2
49
58
 
50
59
  # First conv in block
51
- layers.append(nn.Conv2d(current_channels, out_channels, kernel_size=3, padding=1))
60
+ layers.append(nn.Conv2d(current_channels, out_channels, kernel_size=kernel_size, padding=padding))
52
61
 
53
62
  if use_batch_norm:
54
63
  layers.append(nn.BatchNorm2d(out_channels))
@@ -56,16 +65,20 @@ def create_cnn(
56
65
  layers.append(nn.ReLU())
57
66
 
58
67
  # Second conv in block
59
- layers.append(nn.Conv2d(out_channels, out_channels, kernel_size=3, padding=1))
68
+ layers.append(nn.Conv2d(out_channels, out_channels, kernel_size=kernel_size, padding=padding))
60
69
 
61
70
  if use_batch_norm:
62
71
  layers.append(nn.BatchNorm2d(out_channels))
63
72
 
64
73
  layers.append(nn.ReLU())
65
74
 
66
- # Pooling and dropout
67
- layers.append(nn.MaxPool2d(2, 2))
68
- layers.append(nn.Dropout(dropout_rate))
75
+ # Pooling
76
+ if pooling_strategy == 'max':
77
+ layers.append(nn.MaxPool2d(2, 2))
78
+ else: # avg
79
+ layers.append(nn.AvgPool2d(2, 2))
80
+
81
+ layers.append(nn.Dropout(conv_dropout_rate))
69
82
 
70
83
  current_channels = out_channels
71
84
  current_size //= 2
@@ -74,15 +87,26 @@ def create_cnn(
74
87
  final_channels = initial_filters * (2 ** (n_conv_blocks - 1))
75
88
  flattened_size = final_channels * current_size * current_size
76
89
 
77
- # Classifier (3 fully connected layers)
90
+ # Classifier - dynamic FC layers with halving pattern
78
91
  layers.append(nn.Flatten())
79
- layers.append(nn.Linear(flattened_size, fc_units_1))
80
- layers.append(nn.ReLU())
81
- layers.append(nn.Dropout(dropout_rate))
82
- layers.append(nn.Linear(fc_units_1, fc_units_2))
83
- layers.append(nn.ReLU())
84
- layers.append(nn.Dropout(dropout_rate))
85
- layers.append(nn.Linear(fc_units_2, num_classes))
92
+
93
+ # Generate FC layer sizes by halving from flattened_size
94
+ fc_sizes = []
95
+ current_fc_size = flattened_size // 2
96
+ for _ in range(n_fc_layers):
97
+ fc_sizes.append(max(10, current_fc_size)) # Minimum 10 units
98
+ current_fc_size //= 2
99
+
100
+ # Add FC layers
101
+ in_features = flattened_size
102
+ for fc_size in fc_sizes:
103
+ layers.append(nn.Linear(in_features, fc_size))
104
+ layers.append(nn.ReLU())
105
+ layers.append(nn.Dropout(fc_dropout_rate))
106
+ in_features = fc_size
107
+
108
+ # Output layer
109
+ layers.append(nn.Linear(in_features, num_classes))
86
110
 
87
111
  return nn.Sequential(*layers)
88
112
 
@@ -113,6 +137,7 @@ def train_trial(
113
137
  best_val_accuracy = 0.0
114
138
 
115
139
  for epoch in range(n_epochs):
140
+
116
141
  # Training phase
117
142
  model.train()
118
143
 
@@ -149,8 +174,9 @@ def train_trial(
149
174
 
150
175
 
151
176
  def create_objective(
152
- train_loader: DataLoader,
153
- val_loader: DataLoader,
177
+ data_dir,
178
+ train_transform,
179
+ eval_transform,
154
180
  n_epochs: int,
155
181
  device: torch.device,
156
182
  num_classes: int = 10,
@@ -158,12 +184,13 @@ def create_objective(
158
184
  ) -> Callable[[optuna.Trial], float]:
159
185
  '''Create an Optuna objective function for CNN hyperparameter optimization.
160
186
 
161
- This factory function creates a closure that captures the data loaders and
162
- training configuration, returning an objective function suitable for Optuna.
187
+ This factory function creates a closure that captures the data loading parameters
188
+ and training configuration, returning an objective function suitable for Optuna.
163
189
 
164
190
  Args:
165
- train_loader: DataLoader for training data
166
- val_loader: DataLoader for validation data
191
+ data_dir: Directory containing CIFAR-10 data
192
+ train_transform: Transform to apply to training data
193
+ eval_transform: Transform to apply to validation data
167
194
  n_epochs: Number of epochs per trial
168
195
  device: Device to train on (cuda or cpu)
169
196
  num_classes: Number of output classes (default: 10)
@@ -173,7 +200,7 @@ def create_objective(
173
200
  Objective function for optuna.Study.optimize()
174
201
 
175
202
  Example:
176
- >>> objective = create_objective(train_loader, val_loader, n_epochs=50, device=device)
203
+ >>> objective = create_objective(data_dir, transform, transform, n_epochs=50, device=device)
177
204
  >>> study = optuna.create_study(direction='maximize')
178
205
  >>> study.optimize(objective, n_trials=100)
179
206
  '''
@@ -182,22 +209,37 @@ def create_objective(
182
209
  '''Optuna objective function for CNN hyperparameter optimization.'''
183
210
 
184
211
  # Suggest hyperparameters
212
+ batch_size = trial.suggest_categorical('batch_size', [64, 128, 256, 512, 1024])
185
213
  n_conv_blocks = trial.suggest_int('n_conv_blocks', 1, 5)
186
214
  initial_filters = trial.suggest_categorical('initial_filters', [8, 16, 32, 64, 128])
187
- fc_units_1 = trial.suggest_categorical('fc_units_1', [128, 256, 512, 1024, 2048])
188
- fc_units_2 = trial.suggest_categorical('fc_units_2', [32, 64, 128, 256, 512])
189
- dropout_rate = trial.suggest_float('dropout_rate', 0.2, 0.75)
215
+ n_fc_layers = trial.suggest_int('n_fc_layers', 1, 8)
216
+ base_kernel_size = trial.suggest_int('base_kernel_size', 3, 7)
217
+ conv_dropout_rate = trial.suggest_float('conv_dropout_rate', 0.0, 0.5)
218
+ fc_dropout_rate = trial.suggest_float('fc_dropout_rate', 0.2, 0.75)
219
+ pooling_strategy = trial.suggest_categorical('pooling_strategy', ['max', 'avg'])
190
220
  use_batch_norm = trial.suggest_categorical('use_batch_norm', [True, False])
191
221
  learning_rate = trial.suggest_float('learning_rate', 1e-5, 1e-1, log=True)
192
222
  optimizer_name = trial.suggest_categorical('optimizer', ['Adam', 'SGD', 'RMSprop'])
193
223
 
224
+ # Create data loaders with suggested batch size
225
+ train_loader, val_loader, _ = make_data_loaders(
226
+ data_dir=data_dir,
227
+ batch_size=batch_size,
228
+ train_transform=train_transform,
229
+ eval_transform=eval_transform,
230
+ device=device,
231
+ download=False
232
+ )
233
+
194
234
  # Create model
195
235
  model = create_cnn(
196
236
  n_conv_blocks=n_conv_blocks,
197
237
  initial_filters=initial_filters,
198
- fc_units_1=fc_units_1,
199
- fc_units_2=fc_units_2,
200
- dropout_rate=dropout_rate,
238
+ n_fc_layers=n_fc_layers,
239
+ base_kernel_size=base_kernel_size,
240
+ conv_dropout_rate=conv_dropout_rate,
241
+ fc_dropout_rate=fc_dropout_rate,
242
+ pooling_strategy=pooling_strategy,
201
243
  use_batch_norm=use_batch_norm,
202
244
  num_classes=num_classes,
203
245
  in_channels=in_channels
@@ -222,7 +222,7 @@ def plot_evaluation_curves(
222
222
  roc_auc = auc(fpr, tpr)
223
223
  ax1.plot(fpr, tpr, label=class_name)
224
224
 
225
- ax1.plot([0, 1], [0, 1], 'k--', label='Random classifier')
225
+ ax1.plot([0, 1], [0, 1], 'k--', label='random classifier')
226
226
  ax1.set_xlabel('False positive rate')
227
227
  ax1.set_ylabel('True positive rate')
228
228
  ax1.legend(loc='lower right', fontsize=12)
@@ -115,6 +115,4 @@ def train_model(
115
115
  f'val_accuracy: {val_accuracy:.2f}%'
116
116
  )
117
117
 
118
- print('\nTraining complete.')
119
-
120
118
  return history
@@ -1,35 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: cifar10_tools
3
- Version: 0.3.0
4
- Summary: Tools for training neural networks on the CIFAR-10 task with PyTorch and TensorFlow
5
- License: GPLv3
6
- License-File: LICENSE
7
- Keywords: Python,Machine learning,Deep learning,CNNs,Computer vision,Image classification,CIFAR-10
8
- Author: gperdrizet
9
- Author-email: george@perdrizet.org
10
- Requires-Python: >=3.10,<3.13
11
- Classifier: Development Status :: 3 - Alpha
12
- Classifier: Intended Audience :: Developers
13
- Classifier: Intended Audience :: Education
14
- Classifier: Intended Audience :: Science/Research
15
- Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
16
- Classifier: License :: Other/Proprietary License
17
- Classifier: Operating System :: OS Independent
18
- Classifier: Programming Language :: Python :: 3
19
- Classifier: Programming Language :: Python :: 3.10
20
- Classifier: Programming Language :: Python :: 3.11
21
- Classifier: Programming Language :: Python :: 3.12
22
- Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
23
- Classifier: Topic :: Scientific/Engineering :: Image Recognition
24
- Provides-Extra: tensorflow
25
- Requires-Dist: numpy (>=1.24)
26
- Requires-Dist: torch (>=2.0)
27
- Requires-Dist: torchvision (>=0.15)
28
- Project-URL: Documentation, https://gperdrizet.github.io/CIFAR10/README.md
29
- Project-URL: Homepage, https://github.com/gperdrizet/CIFAR10
30
- Project-URL: Issues, https://github.com/gperdrizet/CIFAR10/issues
31
- Project-URL: PyPI, https://pypi.org/project/cifar10_tools
32
- Project-URL: Repository, https://github.com/gperdrizet/CIFAR10
33
- Description-Content-Type: text/markdown
34
-
35
- # PyTorch: CIFAR10 demonstration
@@ -1 +0,0 @@
1
- # PyTorch: CIFAR10 demonstration
@@ -1,27 +0,0 @@
1
- '''Data download function for CIFAR-10 dataset. Use to pre-download data
2
- during devcontainer creation'''
3
-
4
- from pathlib import Path
5
- from torchvision import datasets
6
-
7
- def download_cifar10_data(data_dir: str='data/pytorch/cifar10'):
8
- '''Download CIFAR-10 dataset using torchvision.datasets.'''
9
-
10
- data_dir = Path(data_dir)
11
- data_dir.mkdir(parents=True, exist_ok=True)
12
-
13
- _ = datasets.CIFAR10(
14
- root=data_dir,
15
- train=True,
16
- download=True
17
- )
18
-
19
- _ = datasets.CIFAR10(
20
- root=data_dir,
21
- train=False,
22
- download=True
23
- )
24
-
25
- if __name__ == '__main__':
26
-
27
- download_cifar10_data()
File without changes