visionkit-pro 0.1.2__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 Hideaki Mizoue
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,291 @@
1
+ Metadata-Version: 2.4
2
+ Name: visionkit_pro
3
+ Version: 0.1.2
4
+ Summary: Reusable training, evaluation, and Grad-CAM utilities for CSV-backed image classification.
5
+ Requires-Python: >=3.9
6
+ Description-Content-Type: text/markdown
7
+ License-File: LICENSE
8
+ Requires-Dist: matplotlib>=3.7
9
+ Requires-Dist: numpy>=1.23
10
+ Requires-Dist: pandas>=1.5
11
+ Requires-Dist: pillow>=9.0
12
+ Requires-Dist: scikit-learn>=1.2
13
+ Requires-Dist: torch>=2.0
14
+ Requires-Dist: torchvision>=0.15
15
+ Requires-Dist: tqdm>=4.64
16
+ Dynamic: license-file
17
+
18
+ # visionkit
19
+
20
+ <p align="center">
21
+ <img src="doc/image/image.png" width="900">
22
+ </p>
23
+
24
+ `visionkit` is a small PyTorch package for image-classification projects where
25
+ image metadata is stored in a CSV file and the image files live in a directory.
26
+ It provides a reusable workflow for training, evaluation, prediction tables, and
27
+ Grad-CAM visualization.
28
+
29
+ It turns the notebook workflow into a package that can be reused with different
30
+ CSV files and image folders:
31
+
32
+ - Load image filenames, labels, and train/validation splits from a CSV
33
+ - Train torchvision models such as EfficientNet or ResNet
34
+ - Save checkpoints, training logs, prediction CSVs, and metric CSVs
35
+ - Generate Grad-CAM heatmaps and overlay images
36
+
37
+ ## Quick Start
38
+
39
+ Prepare an image directory and a CSV file.
40
+
41
+ ```text
42
+ your_project/
43
+ data/
44
+ images/
45
+ case001.png
46
+ case002.png
47
+ case003.png
48
+ meta.csv
49
+ outputs/
50
+ ```
51
+
52
+ The minimal `meta.csv` should look like this:
53
+
54
+ ```csv
55
+ filename,label,split
56
+ case001.png,F,train
57
+ case002.png,N,train
58
+ case003.png,F,validation
59
+ case004.png,N,validation
60
+ ```
61
+
62
+ Train a model:
63
+
64
+ ```bash
65
+ visionkit train \
66
+ --csv data/meta.csv \
67
+ --image-dir data/images \
68
+ --output-dir outputs/experiment_001 \
69
+ --classes F N \
70
+ --positive-class N \
71
+ --epochs 30
72
+ ```
73
+
74
+ Evaluate the validation split:
75
+
76
+ ```bash
77
+ visionkit evaluate \
78
+ --csv data/meta.csv \
79
+ --image-dir data/images \
80
+ --output-dir outputs/experiment_001 \
81
+ --checkpoint outputs/experiment_001/models/best.pt \
82
+ --classes F N \
83
+ --positive-class N \
84
+ --split validation
85
+ ```
86
+
87
+ Generate Grad-CAM overlays:
88
+
89
+ ```bash
90
+ visionkit gradcam \
91
+ --csv data/meta.csv \
92
+ --image-dir data/images \
93
+ --output-dir outputs/experiment_001 \
94
+ --checkpoint outputs/experiment_001/models/best.pt \
95
+ --classes F N \
96
+ --positive-class N \
97
+ --split validation \
98
+ --target-class N
99
+ ```
100
+
101
+ ## Required CSV
102
+
103
+ For CLI training, the CSV usually needs these three columns.
104
+
105
+ | column | required | example | meaning |
106
+ | --- | --- | --- | --- |
107
+ | `filename` | yes | `case001.png` | Image path relative to `--image-dir` |
108
+ | `label` | yes | `F` / `N` | Class label |
109
+ | `split` | yes | `train` / `validation` | Which split the row belongs to |
110
+
111
+ The default column names are `filename`, `label`, and `split`. If your CSV uses
112
+ different names, pass them explicitly:
113
+
114
+ ```bash
115
+ visionkit train \
116
+ --csv data/metadata.csv \
117
+ --image-dir data/fig \
118
+ --output-dir outputs/run_001 \
119
+ --filename-column image_name \
120
+ --label-column diagnosis \
121
+ --split-column fixed_family_level_split \
122
+ --train-split train \
123
+ --val-split validation
124
+ ```
125
+
126
+ Extra CSV columns are allowed. Columns such as `patient_id`, `family_id`, or
127
+ `age` are carried through into the prediction CSVs.
128
+
129
+ ```csv
130
+ filename,label,split,patient_id,family_id
131
+ case001.png,F,train,P001,A
132
+ case002.png,N,train,P002,B
133
+ case003.png,F,validation,P003,C
134
+ ```
135
+
136
+ ## Image Paths
137
+
138
+ `filename` is interpreted as a path relative to `--image-dir`.
139
+
140
+ If all images are in the same folder:
141
+
142
+ ```csv
143
+ filename,label,split
144
+ case001.png,F,train
145
+ case002.png,N,validation
146
+ ```
147
+
148
+ If images are stored in subfolders, include the subfolder in `filename`:
149
+
150
+ ```csv
151
+ filename,label,split
152
+ train/case001.png,F,train
153
+ validation/case002.png,N,validation
154
+ ```
155
+
156
+ This expects files like:
157
+
158
+ ```text
159
+ data/images/train/case001.png
160
+ data/images/validation/case002.png
161
+ ```
162
+
163
+ ## Classes And Positive Class
164
+
165
+ For binary classification, the order of `--classes` defines the class indices.
166
+
167
+ ```bash
168
+ --classes F N
169
+ ```
170
+
171
+ This means:
172
+
173
+ - `F` is class 0
174
+ - `N` is class 1
175
+
176
+ If you want AUC, sensitivity, specificity, and PR-AUC to use a specific positive
177
+ class, set it explicitly:
178
+
179
+ ```bash
180
+ --positive-class N
181
+ ```
182
+
183
+ If `--classes` is omitted, class names are inferred from the labels in the CSV.
184
+ For reproducible research or paper figures, it is better to pass `--classes`
185
+ explicitly because class order affects the numeric labels and positive class.
186
+
187
+ ## Outputs
188
+
189
+ With `--output-dir outputs/experiment_001`, the package creates files like:
190
+
191
+ ```text
192
+ outputs/experiment_001/
193
+ models/
194
+ best.pt
195
+ epoch_001.pt
196
+ epoch_002.pt
197
+ logs/
198
+ training_history.csv
199
+ predictions/
200
+ validation_predictions.csv
201
+ validation_predictions_metrics.csv
202
+ gradcam_validation.csv
203
+ gradcam_validation_metrics.csv
204
+ gradcam/
205
+ validation/
206
+ case001__pred-N.png
207
+ ```
208
+
209
+ By default, `best.pt` is the checkpoint from the epoch with the best `val_auc`.
210
+
211
+ ## Common Commands
212
+
213
+ Use a torchvision model other than EfficientNet-B3:
214
+
215
+ ```bash
216
+ visionkit train \
217
+ --csv data/meta.csv \
218
+ --image-dir data/images \
219
+ --output-dir outputs/resnet50_run \
220
+ --architecture resnet50 \
221
+ --image-size 224x224 \
222
+ --classes F N \
223
+ --positive-class N
224
+ ```
225
+
226
+ Use a CSV layout similar to the original notebook:
227
+
228
+ ```bash
229
+ visionkit train \
230
+ --csv train_val/data/meta/fixed/fixed_family_level_split.csv \
231
+ --image-dir train_val/data/fig \
232
+ --output-dir train_val/review_outputs/family_level_split_efficientnetb3_seed123 \
233
+ --filename-column filename \
234
+ --label-column label \
235
+ --split-column fixed_family_level_split \
236
+ --train-split train \
237
+ --val-split validation \
238
+ --classes F N \
239
+ --positive-class N \
240
+ --architecture efficientnet_b3 \
241
+ --image-size 300x300
242
+ ```
243
+
244
+ ## Python API
245
+
246
+ ```python
247
+ from pathlib import Path
248
+
249
+ from visionkit.config import ExperimentConfig
250
+ from visionkit.pipeline import run_training, run_evaluation, run_gradcam
251
+
252
+ config = ExperimentConfig(
253
+ csv_path=Path("data/meta.csv"),
254
+ image_dir=Path("data/images"),
255
+ output_dir=Path("outputs/experiment_001"),
256
+ class_names=["F", "N"],
257
+ positive_class="N",
258
+ split_column="split",
259
+ train_split="train",
260
+ val_split="validation",
261
+ architecture="efficientnet_b3",
262
+ image_size=(300, 300),
263
+ epochs=30,
264
+ )
265
+
266
+ model, history = run_training(config)
267
+
268
+ predictions, metrics = run_evaluation(
269
+ config,
270
+ checkpoint_path=config.output_dir / "models" / "best.pt",
271
+ split_name="validation",
272
+ )
273
+
274
+ gradcam_results, gradcam_metrics = run_gradcam(
275
+ config,
276
+ checkpoint_path=config.output_dir / "models" / "best.pt",
277
+ split_name="validation",
278
+ target_class="N",
279
+ )
280
+ ```
281
+
282
+ ## Install
283
+
284
+ Use the package locally in editable mode:
285
+
286
+ ```bash
287
+ pip install -e .
288
+ ```
289
+
290
+ If PyTorch is not installed yet, install `torch` and `torchvision` first using
291
+ the command appropriate for your CPU or CUDA environment.
@@ -0,0 +1,274 @@
1
+ # visionkit
2
+
3
+ <p align="center">
4
+ <img src="doc/image/image.png" width="900">
5
+ </p>
6
+
7
+ `visionkit` is a small PyTorch package for image-classification projects where
8
+ image metadata is stored in a CSV file and the image files live in a directory.
9
+ It provides a reusable workflow for training, evaluation, prediction tables, and
10
+ Grad-CAM visualization.
11
+
12
+ It turns the notebook workflow into a package that can be reused with different
13
+ CSV files and image folders:
14
+
15
+ - Load image filenames, labels, and train/validation splits from a CSV
16
+ - Train torchvision models such as EfficientNet or ResNet
17
+ - Save checkpoints, training logs, prediction CSVs, and metric CSVs
18
+ - Generate Grad-CAM heatmaps and overlay images
19
+
20
+ ## Quick Start
21
+
22
+ Prepare an image directory and a CSV file.
23
+
24
+ ```text
25
+ your_project/
26
+ data/
27
+ images/
28
+ case001.png
29
+ case002.png
30
+ case003.png
31
+ meta.csv
32
+ outputs/
33
+ ```
34
+
35
+ The minimal `meta.csv` should look like this:
36
+
37
+ ```csv
38
+ filename,label,split
39
+ case001.png,F,train
40
+ case002.png,N,train
41
+ case003.png,F,validation
42
+ case004.png,N,validation
43
+ ```
44
+
45
+ Train a model:
46
+
47
+ ```bash
48
+ visionkit train \
49
+ --csv data/meta.csv \
50
+ --image-dir data/images \
51
+ --output-dir outputs/experiment_001 \
52
+ --classes F N \
53
+ --positive-class N \
54
+ --epochs 30
55
+ ```
56
+
57
+ Evaluate the validation split:
58
+
59
+ ```bash
60
+ visionkit evaluate \
61
+ --csv data/meta.csv \
62
+ --image-dir data/images \
63
+ --output-dir outputs/experiment_001 \
64
+ --checkpoint outputs/experiment_001/models/best.pt \
65
+ --classes F N \
66
+ --positive-class N \
67
+ --split validation
68
+ ```
69
+
70
+ Generate Grad-CAM overlays:
71
+
72
+ ```bash
73
+ visionkit gradcam \
74
+ --csv data/meta.csv \
75
+ --image-dir data/images \
76
+ --output-dir outputs/experiment_001 \
77
+ --checkpoint outputs/experiment_001/models/best.pt \
78
+ --classes F N \
79
+ --positive-class N \
80
+ --split validation \
81
+ --target-class N
82
+ ```
83
+
84
+ ## Required CSV
85
+
86
+ For CLI training, the CSV usually needs these three columns.
87
+
88
+ | column | required | example | meaning |
89
+ | --- | --- | --- | --- |
90
+ | `filename` | yes | `case001.png` | Image path relative to `--image-dir` |
91
+ | `label` | yes | `F` / `N` | Class label |
92
+ | `split` | yes | `train` / `validation` | Which split the row belongs to |
93
+
94
+ The default column names are `filename`, `label`, and `split`. If your CSV uses
95
+ different names, pass them explicitly:
96
+
97
+ ```bash
98
+ visionkit train \
99
+ --csv data/metadata.csv \
100
+ --image-dir data/fig \
101
+ --output-dir outputs/run_001 \
102
+ --filename-column image_name \
103
+ --label-column diagnosis \
104
+ --split-column fixed_family_level_split \
105
+ --train-split train \
106
+ --val-split validation
107
+ ```
108
+
109
+ Extra CSV columns are allowed. Columns such as `patient_id`, `family_id`, or
110
+ `age` are carried through into the prediction CSVs.
111
+
112
+ ```csv
113
+ filename,label,split,patient_id,family_id
114
+ case001.png,F,train,P001,A
115
+ case002.png,N,train,P002,B
116
+ case003.png,F,validation,P003,C
117
+ ```
118
+
119
+ ## Image Paths
120
+
121
+ `filename` is interpreted as a path relative to `--image-dir`.
122
+
123
+ If all images are in the same folder:
124
+
125
+ ```csv
126
+ filename,label,split
127
+ case001.png,F,train
128
+ case002.png,N,validation
129
+ ```
130
+
131
+ If images are stored in subfolders, include the subfolder in `filename`:
132
+
133
+ ```csv
134
+ filename,label,split
135
+ train/case001.png,F,train
136
+ validation/case002.png,N,validation
137
+ ```
138
+
139
+ This expects files like:
140
+
141
+ ```text
142
+ data/images/train/case001.png
143
+ data/images/validation/case002.png
144
+ ```
145
+
146
+ ## Classes And Positive Class
147
+
148
+ For binary classification, the order of `--classes` defines the class indices.
149
+
150
+ ```bash
151
+ --classes F N
152
+ ```
153
+
154
+ This means:
155
+
156
+ - `F` is class 0
157
+ - `N` is class 1
158
+
159
+ If you want AUC, sensitivity, specificity, and PR-AUC to use a specific positive
160
+ class, set it explicitly:
161
+
162
+ ```bash
163
+ --positive-class N
164
+ ```
165
+
166
+ If `--classes` is omitted, class names are inferred from the labels in the CSV.
167
+ For reproducible research or paper figures, it is better to pass `--classes`
168
+ explicitly because class order affects the numeric labels and positive class.
169
+
170
+ ## Outputs
171
+
172
+ With `--output-dir outputs/experiment_001`, the package creates files like:
173
+
174
+ ```text
175
+ outputs/experiment_001/
176
+ models/
177
+ best.pt
178
+ epoch_001.pt
179
+ epoch_002.pt
180
+ logs/
181
+ training_history.csv
182
+ predictions/
183
+ validation_predictions.csv
184
+ validation_predictions_metrics.csv
185
+ gradcam_validation.csv
186
+ gradcam_validation_metrics.csv
187
+ gradcam/
188
+ validation/
189
+ case001__pred-N.png
190
+ ```
191
+
192
+ By default, `best.pt` is the checkpoint from the epoch with the best `val_auc`.
193
+
194
+ ## Common Commands
195
+
196
+ Use a torchvision model other than EfficientNet-B3:
197
+
198
+ ```bash
199
+ visionkit train \
200
+ --csv data/meta.csv \
201
+ --image-dir data/images \
202
+ --output-dir outputs/resnet50_run \
203
+ --architecture resnet50 \
204
+ --image-size 224x224 \
205
+ --classes F N \
206
+ --positive-class N
207
+ ```
208
+
209
+ Use a CSV layout similar to the original notebook:
210
+
211
+ ```bash
212
+ visionkit train \
213
+ --csv train_val/data/meta/fixed/fixed_family_level_split.csv \
214
+ --image-dir train_val/data/fig \
215
+ --output-dir train_val/review_outputs/family_level_split_efficientnetb3_seed123 \
216
+ --filename-column filename \
217
+ --label-column label \
218
+ --split-column fixed_family_level_split \
219
+ --train-split train \
220
+ --val-split validation \
221
+ --classes F N \
222
+ --positive-class N \
223
+ --architecture efficientnet_b3 \
224
+ --image-size 300x300
225
+ ```
226
+
227
+ ## Python API
228
+
229
+ ```python
230
+ from pathlib import Path
231
+
232
+ from visionkit.config import ExperimentConfig
233
+ from visionkit.pipeline import run_training, run_evaluation, run_gradcam
234
+
235
+ config = ExperimentConfig(
236
+ csv_path=Path("data/meta.csv"),
237
+ image_dir=Path("data/images"),
238
+ output_dir=Path("outputs/experiment_001"),
239
+ class_names=["F", "N"],
240
+ positive_class="N",
241
+ split_column="split",
242
+ train_split="train",
243
+ val_split="validation",
244
+ architecture="efficientnet_b3",
245
+ image_size=(300, 300),
246
+ epochs=30,
247
+ )
248
+
249
+ model, history = run_training(config)
250
+
251
+ predictions, metrics = run_evaluation(
252
+ config,
253
+ checkpoint_path=config.output_dir / "models" / "best.pt",
254
+ split_name="validation",
255
+ )
256
+
257
+ gradcam_results, gradcam_metrics = run_gradcam(
258
+ config,
259
+ checkpoint_path=config.output_dir / "models" / "best.pt",
260
+ split_name="validation",
261
+ target_class="N",
262
+ )
263
+ ```
264
+
265
+ ## Install
266
+
267
+ Use the package locally in editable mode:
268
+
269
+ ```bash
270
+ pip install -e .
271
+ ```
272
+
273
+ If PyTorch is not installed yet, install `torch` and `torchvision` first using
274
+ the command appropriate for your CPU or CUDA environment.
@@ -0,0 +1,26 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "visionkit_pro"
7
+ version = "0.1.2"
8
+ description = "Reusable training, evaluation, and Grad-CAM utilities for CSV-backed image classification."
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ dependencies = [
12
+ "matplotlib>=3.7",
13
+ "numpy>=1.23",
14
+ "pandas>=1.5",
15
+ "pillow>=9.0",
16
+ "scikit-learn>=1.2",
17
+ "torch>=2.0",
18
+ "torchvision>=0.15",
19
+ "tqdm>=4.64",
20
+ ]
21
+
22
+ [project.scripts]
23
+ visionkit = "visionkit.cli:main"
24
+
25
+ [tool.setuptools.packages.find]
26
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,23 @@
1
+ """Reusable image-classification training, evaluation, and Grad-CAM tools."""
2
+
3
+ from visionkit.config import ExperimentConfig
4
+ from visionkit.data import CSVImageDataset, build_dataloaders, build_transforms
5
+ from visionkit.gradcam import GradCAM, generate_gradcam_report
6
+ from visionkit.models import build_model, load_checkpoint
7
+ from visionkit.pipeline import run_evaluation, run_gradcam, run_training
8
+ from visionkit.train import train_model
9
+
10
+ __all__ = [
11
+ "CSVImageDataset",
12
+ "ExperimentConfig",
13
+ "GradCAM",
14
+ "build_dataloaders",
15
+ "build_model",
16
+ "build_transforms",
17
+ "generate_gradcam_report",
18
+ "load_checkpoint",
19
+ "run_evaluation",
20
+ "run_gradcam",
21
+ "run_training",
22
+ "train_model",
23
+ ]