image-classification-tools 0.5.6__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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 George Perdrizet
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,187 @@
1
+ Metadata-Version: 2.4
2
+ Name: image-classification-tools
3
+ Version: 0.5.6
4
+ Summary: A lightweight PyTorch toolkit for building and training image classification models
5
+ License: GPLv3
6
+ License-File: LICENSE
7
+ Keywords: Python,Machine learning,Deep learning,CNNs,Computer vision,Image classification,PyTorch,Neural networks
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
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/image-classification-tools
32
+ Project-URL: Repository, https://github.com/gperdrizet/CIFAR10
33
+ Description-Content-Type: text/markdown
34
+
35
+ # Image Classification Tools
36
+
37
+ A lightweight PyTorch toolkit for building and training image classification models.
38
+
39
+ ## Overview
40
+
41
+ This package provides utilities for common image classification tasks:
42
+
43
+ - **Data loading**: Flexible data loaders for torchvision datasets and custom image folders
44
+ - **Model training**: Training loops with progress tracking and validation
45
+ - **Evaluation**: Accuracy metrics, confusion matrices, and performance analysis
46
+ - **Visualization**: Learning curves, probability distributions, and evaluation plots
47
+ - **Hyperparameter optimization**: Optuna integration for automated model tuning
48
+
49
+ ## Installation
50
+
51
+ ```bash
52
+ pip install image-classification-tools
53
+ ```
54
+
55
+ ## Quick start
56
+
57
+ ### Basic usage
58
+
59
+ ```python
60
+ import torch
61
+ from pathlib import Path
62
+ from torchvision import datasets, transforms
63
+ from image_classification_tools.pytorch.data import (
64
+ load_datasets, prepare_splits, create_dataloaders
65
+ )
66
+ from image_classification_tools.pytorch.training import train_model
67
+ from image_classification_tools.pytorch.evaluation import evaluate_model
68
+
69
+ # Define transforms
70
+ transform = transforms.Compose([
71
+ transforms.ToTensor(),
72
+ transforms.Normalize((0.5,), (0.5,))
73
+ ])
74
+
75
+ # Load datasets
76
+ train_dataset, test_dataset = load_datasets(
77
+ data_source=datasets.MNIST,
78
+ train_transform=transform,
79
+ eval_transform=transform,
80
+ download=True,
81
+ root=Path('./data/mnist')
82
+ )
83
+
84
+ # Prepare splits
85
+ train_dataset, val_dataset, test_dataset = prepare_splits(
86
+ train_dataset=train_dataset,
87
+ test_dataset=test_dataset,
88
+ train_val_split=0.8
89
+ )
90
+
91
+ # Create dataloaders
92
+ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
93
+ train_loader, val_loader, test_loader = create_dataloaders(
94
+ train_dataset, val_dataset, test_dataset,
95
+ batch_size=64,
96
+ preload_to_memory=True,
97
+ device=device
98
+ )
99
+
100
+ # Define model, criterion, optimizer
101
+ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
102
+
103
+ model = torch.nn.Sequential(
104
+ torch.nn.Flatten(),
105
+ torch.nn.Linear(784, 128),
106
+ torch.nn.ReLU(),
107
+ torch.nn.Linear(128, 10)
108
+ ).to(device)
109
+
110
+ criterion = torch.nn.CrossEntropyLoss()
111
+ optimizer = torch.optim.Adam(model.parameters(), lr=1e-3)
112
+
113
+ # Train with lazy loading (moves batches to device during training)
114
+ history = train_model(
115
+ model=model,
116
+ train_loader=train_loader,
117
+ val_loader=val_loader,
118
+ criterion=criterion,
119
+ optimizer=optimizer,
120
+ device=device,
121
+ lazy_loading=True, # Set False if data already on device
122
+ epochs=10
123
+ )
124
+
125
+ # Evaluate
126
+ accuracy, predictions, labels = evaluate_model(model, test_loader)
127
+ print(f'Test accuracy: {accuracy:.2f}%')
128
+ ```
129
+
130
+ ### Hyperparameter optimization
131
+
132
+ ```python
133
+ from image_classification_tools.pytorch.hyperparameter_optimization import create_objective
134
+ import optuna
135
+
136
+ # Define search space
137
+ search_space = {
138
+ 'batch_size': [32, 64, 128],
139
+ 'n_conv_blocks': (1, 3),
140
+ 'initial_filters': [16, 32, 64],
141
+ 'n_fc_layers': (1, 3),
142
+ 'conv_dropout_rate': (0.1, 0.5),
143
+ 'fc_dropout_rate': (0.3, 0.7),
144
+ 'learning_rate': (1e-4, 1e-2, 'log'),
145
+ 'optimizer': ['Adam', 'SGD'],
146
+ 'weight_decay': (1e-6, 1e-3, 'log')
147
+ }
148
+
149
+ # Create objective function
150
+ objective = create_objective(
151
+ data_dir='./data',
152
+ train_transform=transform,
153
+ eval_transform=transform,
154
+ n_epochs=20,
155
+ device=device,
156
+ num_classes=10,
157
+ in_channels=1,
158
+ search_space=search_space
159
+ )
160
+
161
+ # Run optimization
162
+ study = optuna.create_study(direction='maximize')
163
+ study.optimize(objective, n_trials=50)
164
+ ```
165
+
166
+ ## Requirements
167
+
168
+ - Python ≥ 3.10
169
+ - PyTorch ≥ 2.0.0
170
+ - torchvision ≥ 0.15.0
171
+ - numpy
172
+ - matplotlib
173
+ - optuna (optional, for hyperparameter optimization)
174
+
175
+ ## Documentation
176
+
177
+ Full documentation is available at: https://gperdrizet.github.io/CIFAR10/
178
+
179
+ ## Demo project
180
+
181
+ See a complete example of using this package for CIFAR-10 classification:
182
+ https://github.com/gperdrizet/CIFAR10
183
+
184
+ ## License
185
+
186
+ GPLv3
187
+
@@ -0,0 +1,55 @@
1
+ [build-system]
2
+ requires = ["poetry-core>=1.9.0"]
3
+ build-backend = "poetry.core.masonry.api"
4
+
5
+ [tool.poetry]
6
+ name = "image-classification-tools"
7
+ version = "0.5.6"
8
+ description = "A lightweight PyTorch toolkit for building and training image classification models"
9
+ authors = ["gperdrizet <george@perdrizet.org>"]
10
+ readme = "src/image_classification_tools/README.md"
11
+ license = "GPLv3"
12
+ packages = [{include = "image_classification_tools", from = "src"}]
13
+ exclude = ["notebooks", "models", "logs"]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Intended Audience :: Developers",
17
+ "Intended Audience :: Education",
18
+ "Intended Audience :: Science/Research",
19
+ "License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
20
+ "Operating System :: OS Independent",
21
+ "Programming Language :: Python :: 3",
22
+ "Programming Language :: Python :: 3.10",
23
+ "Programming Language :: Python :: 3.11",
24
+ "Programming Language :: Python :: 3.12",
25
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
26
+ "Topic :: Scientific/Engineering :: Image Recognition",
27
+ ]
28
+ keywords = ["Python", "Machine learning", "Deep learning", "CNNs", "Computer vision", "Image classification", "PyTorch", "Neural networks"]
29
+
30
+ [tool.poetry.dependencies]
31
+ python = ">=3.10,<3.13"
32
+ torch = ">=2.0"
33
+ torchvision = ">=0.15"
34
+ numpy = ">=1.24"
35
+
36
+ [tool.poetry.group.docs]
37
+ optional = true
38
+
39
+ [tool.poetry.group.docs.dependencies]
40
+ sphinx = ">=7.0"
41
+ sphinx-rtd-theme = ">=2.0"
42
+ nbsphinx = ">=0.9"
43
+ sphinx-autodoc-typehints = ">=1.25"
44
+ ipykernel = ">=6.0"
45
+ pandoc = ">=2.0"
46
+
47
+ [tool.poetry.extras]
48
+ tensorflow = ["tensorflow"]
49
+
50
+ [tool.poetry.urls]
51
+ Homepage = "https://github.com/gperdrizet/CIFAR10"
52
+ Documentation = "https://gperdrizet.github.io/CIFAR10"
53
+ Repository = "https://github.com/gperdrizet/CIFAR10"
54
+ Issues = "https://github.com/gperdrizet/CIFAR10/issues"
55
+ PyPI = "https://pypi.org/project/image-classification-tools"
@@ -0,0 +1,152 @@
1
+ # Image Classification Tools
2
+
3
+ A lightweight PyTorch toolkit for building and training image classification models.
4
+
5
+ ## Overview
6
+
7
+ This package provides utilities for common image classification tasks:
8
+
9
+ - **Data loading**: Flexible data loaders for torchvision datasets and custom image folders
10
+ - **Model training**: Training loops with progress tracking and validation
11
+ - **Evaluation**: Accuracy metrics, confusion matrices, and performance analysis
12
+ - **Visualization**: Learning curves, probability distributions, and evaluation plots
13
+ - **Hyperparameter optimization**: Optuna integration for automated model tuning
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ pip install image-classification-tools
19
+ ```
20
+
21
+ ## Quick start
22
+
23
+ ### Basic usage
24
+
25
+ ```python
26
+ import torch
27
+ from pathlib import Path
28
+ from torchvision import datasets, transforms
29
+ from image_classification_tools.pytorch.data import (
30
+ load_datasets, prepare_splits, create_dataloaders
31
+ )
32
+ from image_classification_tools.pytorch.training import train_model
33
+ from image_classification_tools.pytorch.evaluation import evaluate_model
34
+
35
+ # Define transforms
36
+ transform = transforms.Compose([
37
+ transforms.ToTensor(),
38
+ transforms.Normalize((0.5,), (0.5,))
39
+ ])
40
+
41
+ # Load datasets
42
+ train_dataset, test_dataset = load_datasets(
43
+ data_source=datasets.MNIST,
44
+ train_transform=transform,
45
+ eval_transform=transform,
46
+ download=True,
47
+ root=Path('./data/mnist')
48
+ )
49
+
50
+ # Prepare splits
51
+ train_dataset, val_dataset, test_dataset = prepare_splits(
52
+ train_dataset=train_dataset,
53
+ test_dataset=test_dataset,
54
+ train_val_split=0.8
55
+ )
56
+
57
+ # Create dataloaders
58
+ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
59
+ train_loader, val_loader, test_loader = create_dataloaders(
60
+ train_dataset, val_dataset, test_dataset,
61
+ batch_size=64,
62
+ preload_to_memory=True,
63
+ device=device
64
+ )
65
+
66
+ # Define model, criterion, optimizer
67
+ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
68
+
69
+ model = torch.nn.Sequential(
70
+ torch.nn.Flatten(),
71
+ torch.nn.Linear(784, 128),
72
+ torch.nn.ReLU(),
73
+ torch.nn.Linear(128, 10)
74
+ ).to(device)
75
+
76
+ criterion = torch.nn.CrossEntropyLoss()
77
+ optimizer = torch.optim.Adam(model.parameters(), lr=1e-3)
78
+
79
+ # Train with lazy loading (moves batches to device during training)
80
+ history = train_model(
81
+ model=model,
82
+ train_loader=train_loader,
83
+ val_loader=val_loader,
84
+ criterion=criterion,
85
+ optimizer=optimizer,
86
+ device=device,
87
+ lazy_loading=True, # Set False if data already on device
88
+ epochs=10
89
+ )
90
+
91
+ # Evaluate
92
+ accuracy, predictions, labels = evaluate_model(model, test_loader)
93
+ print(f'Test accuracy: {accuracy:.2f}%')
94
+ ```
95
+
96
+ ### Hyperparameter optimization
97
+
98
+ ```python
99
+ from image_classification_tools.pytorch.hyperparameter_optimization import create_objective
100
+ import optuna
101
+
102
+ # Define search space
103
+ search_space = {
104
+ 'batch_size': [32, 64, 128],
105
+ 'n_conv_blocks': (1, 3),
106
+ 'initial_filters': [16, 32, 64],
107
+ 'n_fc_layers': (1, 3),
108
+ 'conv_dropout_rate': (0.1, 0.5),
109
+ 'fc_dropout_rate': (0.3, 0.7),
110
+ 'learning_rate': (1e-4, 1e-2, 'log'),
111
+ 'optimizer': ['Adam', 'SGD'],
112
+ 'weight_decay': (1e-6, 1e-3, 'log')
113
+ }
114
+
115
+ # Create objective function
116
+ objective = create_objective(
117
+ data_dir='./data',
118
+ train_transform=transform,
119
+ eval_transform=transform,
120
+ n_epochs=20,
121
+ device=device,
122
+ num_classes=10,
123
+ in_channels=1,
124
+ search_space=search_space
125
+ )
126
+
127
+ # Run optimization
128
+ study = optuna.create_study(direction='maximize')
129
+ study.optimize(objective, n_trials=50)
130
+ ```
131
+
132
+ ## Requirements
133
+
134
+ - Python ≥ 3.10
135
+ - PyTorch ≥ 2.0.0
136
+ - torchvision ≥ 0.15.0
137
+ - numpy
138
+ - matplotlib
139
+ - optuna (optional, for hyperparameter optimization)
140
+
141
+ ## Documentation
142
+
143
+ Full documentation is available at: https://gperdrizet.github.io/CIFAR10/
144
+
145
+ ## Demo project
146
+
147
+ See a complete example of using this package for CIFAR-10 classification:
148
+ https://github.com/gperdrizet/CIFAR10
149
+
150
+ ## License
151
+
152
+ GPLv3
@@ -0,0 +1,6 @@
1
+ """Image Classification Tools - General-purpose PyTorch image classification utilities.
2
+
3
+ This package provides tools for building, training, and evaluating image classification
4
+ models with PyTorch. It includes utilities for data loading, model training, evaluation,
5
+ hyperparameter optimization, and visualization.
6
+ """
@@ -0,0 +1,46 @@
1
+ '''PyTorch utilities for image classification.'''
2
+
3
+ from image_classification_tools.pytorch.data import (
4
+ load_dataset,
5
+ prepare_splits,
6
+ create_dataloaders,
7
+ generate_augmented_data
8
+ )
9
+ from image_classification_tools.pytorch.evaluation import evaluate_model
10
+ from image_classification_tools.pytorch.training import train_model
11
+ from image_classification_tools.pytorch.plotting import (
12
+ plot_sample_images,
13
+ plot_learning_curves,
14
+ plot_confusion_matrix,
15
+ plot_class_probability_distributions,
16
+ plot_evaluation_curves,
17
+ plot_optimization_results
18
+ )
19
+ from image_classification_tools.pytorch.hyperparameter_optimization import (
20
+ create_cnn,
21
+ train_trial,
22
+ create_objective
23
+ )
24
+
25
+ __all__ = [
26
+ # Data loading and preprocessing
27
+ 'load_dataset',
28
+ 'prepare_splits',
29
+ 'create_dataloaders',
30
+ 'generate_augmented_data',
31
+ # Model evaluation
32
+ 'evaluate_model',
33
+ # Model training
34
+ 'train_model',
35
+ # Plotting and visualization
36
+ 'plot_sample_images',
37
+ 'plot_learning_curves',
38
+ 'plot_confusion_matrix',
39
+ 'plot_class_probability_distributions',
40
+ 'plot_evaluation_curves',
41
+ 'plot_optimization_results',
42
+ # Hyperparameter optimization
43
+ 'create_cnn',
44
+ 'train_trial',
45
+ 'create_objective'
46
+ ]