kcai-data-sampling 0.0.6__tar.gz → 0.7__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.
- kcai_data_sampling-0.7/.gitignore +265 -0
- kcai_data_sampling-0.7/PKG-INFO +27 -0
- {kcai_data_sampling-0.0.6 → kcai_data_sampling-0.7}/pyproject.toml +2 -10
- {kcai_data_sampling-0.0.6 → kcai_data_sampling-0.7}/requirements.txt +5 -9
- kcai_data_sampling-0.7/src/kcai_data_sampling/Description_artefacts.md +62 -0
- kcai_data_sampling-0.7/src/kcai_data_sampling/_version_.py +34 -0
- {kcai_data_sampling-0.0.6 → kcai_data_sampling-0.7}/src/kcai_data_sampling/adversarial_run.py +11 -20
- {kcai_data_sampling-0.0.6 → kcai_data_sampling-0.7}/src/kcai_data_sampling/augment_run.py +1 -11
- {kcai_data_sampling-0.0.6 → kcai_data_sampling-0.7}/src/kcai_data_sampling/kc_inference.py +1 -5
- {kcai_data_sampling-0.0.6 → kcai_data_sampling-0.7}/src/kcai_data_sampling/run_augment_pipeline.py +0 -10
- kcai_data_sampling-0.7/src/kcai_data_sampling.egg-info/PKG-INFO +27 -0
- {kcai_data_sampling-0.0.6 → kcai_data_sampling-0.7}/src/kcai_data_sampling.egg-info/SOURCES.txt +4 -1
- {kcai_data_sampling-0.0.6 → kcai_data_sampling-0.7}/src/kcai_data_sampling.egg-info/requires.txt +4 -8
- kcai_data_sampling-0.7/test.ipynb +1060 -0
- kcai_data_sampling-0.0.6/PKG-INFO +0 -83
- kcai_data_sampling-0.0.6/README.md +0 -51
- kcai_data_sampling-0.0.6/src/kcai_data_sampling.egg-info/PKG-INFO +0 -83
- {kcai_data_sampling-0.0.6 → kcai_data_sampling-0.7}/setup.cfg +0 -0
- {kcai_data_sampling-0.0.6 → kcai_data_sampling-0.7}/src/kcai_data_sampling/__init__.py +0 -0
- {kcai_data_sampling-0.0.6 → kcai_data_sampling-0.7}/src/kcai_data_sampling.egg-info/dependency_links.txt +0 -0
- {kcai_data_sampling-0.0.6 → kcai_data_sampling-0.7}/src/kcai_data_sampling.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py,cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# poetry
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
102
|
+
#poetry.lock
|
|
103
|
+
|
|
104
|
+
# pdm
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
106
|
+
#pdm.lock
|
|
107
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
108
|
+
# in version control.
|
|
109
|
+
# https://pdm.fming.dev/#use-with-ide
|
|
110
|
+
.pdm.toml
|
|
111
|
+
|
|
112
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
113
|
+
__pypackages__/
|
|
114
|
+
|
|
115
|
+
# Celery stuff
|
|
116
|
+
celerybeat-schedule
|
|
117
|
+
celerybeat.pid
|
|
118
|
+
|
|
119
|
+
# SageMath parsed files
|
|
120
|
+
*.sage.py
|
|
121
|
+
|
|
122
|
+
# Environments
|
|
123
|
+
.env
|
|
124
|
+
.venv
|
|
125
|
+
env/
|
|
126
|
+
venv/
|
|
127
|
+
ENV/
|
|
128
|
+
env.bak/
|
|
129
|
+
venv.bak/
|
|
130
|
+
|
|
131
|
+
# Spyder project settings
|
|
132
|
+
.spyderproject
|
|
133
|
+
.spyproject
|
|
134
|
+
|
|
135
|
+
# Rope project settings
|
|
136
|
+
.ropeproject
|
|
137
|
+
|
|
138
|
+
# mkdocs documentation
|
|
139
|
+
/site
|
|
140
|
+
|
|
141
|
+
# mypy
|
|
142
|
+
.mypy_cache/
|
|
143
|
+
.dmypy.json
|
|
144
|
+
dmypy.json
|
|
145
|
+
|
|
146
|
+
# Pyre type checker
|
|
147
|
+
.pyre/
|
|
148
|
+
|
|
149
|
+
# pytype static type analyzer
|
|
150
|
+
.pytype/
|
|
151
|
+
|
|
152
|
+
# Cython debug symbols
|
|
153
|
+
cython_debug/
|
|
154
|
+
|
|
155
|
+
# PyCharm
|
|
156
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
157
|
+
# be added to the global gitignore or merged into this project gitignore. For a PyCharm
|
|
158
|
+
# project, it is recommended to include the following files:
|
|
159
|
+
# .idea/
|
|
160
|
+
# *.iml
|
|
161
|
+
# *.ipr
|
|
162
|
+
# *.iws
|
|
163
|
+
|
|
164
|
+
# VS Code
|
|
165
|
+
.vscode/
|
|
166
|
+
|
|
167
|
+
# macOS
|
|
168
|
+
.DS_Store
|
|
169
|
+
.AppleDouble
|
|
170
|
+
.LSOverride
|
|
171
|
+
|
|
172
|
+
# Icon must end with two \r
|
|
173
|
+
Icon
|
|
174
|
+
|
|
175
|
+
# Thumbnails
|
|
176
|
+
._*
|
|
177
|
+
|
|
178
|
+
# Files that might appear in the root of a volume
|
|
179
|
+
.DocumentRevisions-V100
|
|
180
|
+
.fseventsd
|
|
181
|
+
.Spotlight-V100
|
|
182
|
+
.TemporaryItems
|
|
183
|
+
.Trashes
|
|
184
|
+
.VolumeIcon.icns
|
|
185
|
+
.com.apple.timemachine.donotpresent
|
|
186
|
+
|
|
187
|
+
# Directories potentially created on remote AFP share
|
|
188
|
+
.AppleDB
|
|
189
|
+
.AppleDesktop
|
|
190
|
+
Network Trash Folder
|
|
191
|
+
Temporary Items
|
|
192
|
+
.apdisk
|
|
193
|
+
|
|
194
|
+
# Windows
|
|
195
|
+
Thumbs.db
|
|
196
|
+
Thumbs.db:encryptable
|
|
197
|
+
ehthumbs.db
|
|
198
|
+
ehthumbs_vista.db
|
|
199
|
+
|
|
200
|
+
# Dump file
|
|
201
|
+
*.stackdump
|
|
202
|
+
|
|
203
|
+
# Folder config file
|
|
204
|
+
[Dd]esktop.ini
|
|
205
|
+
|
|
206
|
+
# Recycle Bin used on file shares
|
|
207
|
+
$RECYCLE.BIN/
|
|
208
|
+
|
|
209
|
+
# Windows Installer files
|
|
210
|
+
*.cab
|
|
211
|
+
*.msi
|
|
212
|
+
*.msix
|
|
213
|
+
*.msm
|
|
214
|
+
*.msp
|
|
215
|
+
|
|
216
|
+
# Windows shortcuts
|
|
217
|
+
*.lnk
|
|
218
|
+
|
|
219
|
+
# Linux
|
|
220
|
+
*~
|
|
221
|
+
|
|
222
|
+
# temporary files which can be created if a process still has a handle open of a deleted file
|
|
223
|
+
.fuse_hidden*
|
|
224
|
+
|
|
225
|
+
# KDE directory preferences
|
|
226
|
+
.directory
|
|
227
|
+
|
|
228
|
+
# Linux trash folder which might appear on any partition or disk
|
|
229
|
+
.Trash-*
|
|
230
|
+
|
|
231
|
+
# .nfs files are created when an open file is removed but is still being accessed
|
|
232
|
+
.nfs*
|
|
233
|
+
|
|
234
|
+
# uv specific
|
|
235
|
+
.uv/
|
|
236
|
+
|
|
237
|
+
# Project specific
|
|
238
|
+
# Uncomment if you want to ignore these directories
|
|
239
|
+
# input/
|
|
240
|
+
# output/
|
|
241
|
+
# examples/
|
|
242
|
+
|
|
243
|
+
# Temporary files
|
|
244
|
+
*.tmp
|
|
245
|
+
*.temp
|
|
246
|
+
*.swp
|
|
247
|
+
*.swo
|
|
248
|
+
*~
|
|
249
|
+
|
|
250
|
+
# Logs
|
|
251
|
+
*.log
|
|
252
|
+
logs/
|
|
253
|
+
|
|
254
|
+
# IDE specific
|
|
255
|
+
.idea/
|
|
256
|
+
*.iml
|
|
257
|
+
*.ipr
|
|
258
|
+
*.iws
|
|
259
|
+
|
|
260
|
+
# Data files (uncomment if you don't want to track data)
|
|
261
|
+
*.parquet
|
|
262
|
+
*.csv
|
|
263
|
+
# *.json
|
|
264
|
+
*.pkl
|
|
265
|
+
*.pickle
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: kcai-data-sampling
|
|
3
|
+
Version: 0.7
|
|
4
|
+
Summary: Samples generation utilities managed with uv
|
|
5
|
+
Author-email: Safenai <support@safenai.io>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Requires-Python: >=3.11
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
Requires-Dist: pyarrow>=22.0.0
|
|
10
|
+
Requires-Dist: numpy>=1.20.0
|
|
11
|
+
Requires-Dist: pillow>=8.0.0
|
|
12
|
+
Requires-Dist: scikit-learn>=1.0.0
|
|
13
|
+
Requires-Dist: torch>=2.8.0
|
|
14
|
+
Requires-Dist: ipykernel>=6.29.5
|
|
15
|
+
Requires-Dist: torchvision>=0.20.1
|
|
16
|
+
Requires-Dist: captum==0.7.0
|
|
17
|
+
Requires-Dist: torch_pruning>=1.3.7
|
|
18
|
+
Requires-Dist: tqdm==4.66.5
|
|
19
|
+
Requires-Dist: click==8.1.7
|
|
20
|
+
Requires-Dist: pyyaml
|
|
21
|
+
Requires-Dist: numpy<2
|
|
22
|
+
Requires-Dist: neural-compressor==3.1.1
|
|
23
|
+
Requires-Dist: thop
|
|
24
|
+
Requires-Dist: tabulate
|
|
25
|
+
Requires-Dist: albumentations>=2.0.8
|
|
26
|
+
Requires-Dist: pyautoattack>=0.1.1
|
|
27
|
+
Requires-Dist: boto3>=1.40.51
|
|
@@ -4,24 +4,16 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "kcai-data-sampling"
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
description = "Samples generation utilities managed with uv"
|
|
9
|
-
dynamic = ["dependencies"
|
|
9
|
+
dynamic = ["dependencies", "version"]
|
|
10
10
|
authors = [
|
|
11
11
|
{name = "Safenai", email="support@safenai.io"},
|
|
12
|
-
{name = "IRT SystemX", email="support@irt-systemx.fr"},
|
|
13
12
|
]
|
|
14
13
|
readme = "README.md"
|
|
15
14
|
requires-python = ">=3.11"
|
|
16
15
|
license ="Apache-2.0"
|
|
17
16
|
|
|
18
|
-
[tool.pytest.ini_options]
|
|
19
|
-
addopts = "-q"
|
|
20
|
-
|
|
21
|
-
[tool.ruff]
|
|
22
|
-
line-length = 100
|
|
23
|
-
|
|
24
|
-
|
|
25
17
|
[tool.setuptools.dynamic]
|
|
26
18
|
dependencies = {file = ["requirements.txt"]}
|
|
27
19
|
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
# Main dependencies for kc-dataset
|
|
2
|
-
pyarrow>=
|
|
2
|
+
pyarrow>=22.0.0
|
|
3
3
|
numpy>=1.20.0
|
|
4
4
|
pillow>=8.0.0
|
|
5
5
|
scikit-learn>=1.0.0
|
|
6
|
-
torch>=
|
|
6
|
+
torch>=2.8.0
|
|
7
7
|
ipykernel>=6.29.5
|
|
8
8
|
torchvision>=0.20.1
|
|
9
|
-
|
|
10
|
-
torch==2.5.1
|
|
11
|
-
torchvision==0.20.1
|
|
12
9
|
captum==0.7.0
|
|
13
|
-
torch_pruning
|
|
10
|
+
torch_pruning>=1.3.7
|
|
14
11
|
tqdm==4.66.5
|
|
15
12
|
click==8.1.7
|
|
16
13
|
pyyaml
|
|
@@ -18,8 +15,7 @@ numpy<2
|
|
|
18
15
|
neural-compressor==3.1.1
|
|
19
16
|
thop
|
|
20
17
|
tabulate
|
|
21
|
-
pyarrow==17.0.0
|
|
22
18
|
albumentations>=2.0.8
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
pyautoattack>=0.1.1
|
|
20
|
+
|
|
25
21
|
boto3>=1.40.51
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Description artefacts
|
|
2
|
+
|
|
3
|
+
## Samples
|
|
4
|
+
|
|
5
|
+
Raw_samples
|
|
6
|
+
- samples_raw.parquet : table de référence unique avec colonne split (train/val/test). Clés minimales : sample_id, split, class_name, transform_name, transform_id, image_path|image_bytes.
|
|
7
|
+
- samples_train.parquet, samples_val.parquet, samples_test.parquet : mêmes colonnes que samples_raw mais filtrées par split, pour des traitements cibles (calcule de métriques separement)
|
|
8
|
+
|
|
9
|
+
Perturbed_samples
|
|
10
|
+
- Corrupted sample (augmentations/corruptions classiques)
|
|
11
|
+
- Colonnes: sample_id , class_name, transform_name, transform_level, transform_param, split, model_name, orig_pred, perturbed_pred, image_bytes.
|
|
12
|
+
- Adversarial sample (attaques adverses)
|
|
13
|
+
- Colonnes : sample_id, class_name, transform_name (attack_name), transform_level, transform_param (epsilon|steps), split, model_name , class_name, image_bytes.
|
|
14
|
+
|
|
15
|
+
## Features (based on image_byte) : garder les colonnes et enlever les différentes images.
|
|
16
|
+
|
|
17
|
+
- By sample
|
|
18
|
+
- raw_sample : une ligne par sample_id, features dérivées de image_bytes .
|
|
19
|
+
- Corrupted sample + colonnes de features (luminosité, contrast, blur, entropy),
|
|
20
|
+
- retirer image_bytes.
|
|
21
|
+
- perturbed_sample : Corrupted sample + features (luminosité, contrast, blur, entropy) ;
|
|
22
|
+
- retirer image_bytes.
|
|
23
|
+
|
|
24
|
+
## Métriques
|
|
25
|
+
### dqm-ml
|
|
26
|
+
#### Representativness [chi-2 goodness, grte, ks, shannon]
|
|
27
|
+
- By feature
|
|
28
|
+
- By split: train/test/val
|
|
29
|
+
- By class name
|
|
30
|
+
- By models
|
|
31
|
+
- By transform_name
|
|
32
|
+
|
|
33
|
+
### autres métriques
|
|
34
|
+
|
|
35
|
+
#### Classification (à envoyer directement sur klarity ? )
|
|
36
|
+
- Accuracy globale et par classe
|
|
37
|
+
- Precision / Recall / F1 ...
|
|
38
|
+
- ROC-AUC et PR-AUC one-vs-rest (macro / weighted)
|
|
39
|
+
- Matrices de confusion (par split et par transform_name)
|
|
40
|
+
|
|
41
|
+
#### Robustesse (corruptions/augmentations)
|
|
42
|
+
- Robust accuracy par transform_name et transform_level
|
|
43
|
+
- Moyenne sur niveaux de sévérité
|
|
44
|
+
- Worst-case accuracy sur l'ensemble des corruptions: trouver le couple (transform_name, transform_level) qui minimise l’accuracy.
|
|
45
|
+
- Flip rate (taux de changement de prédiction vs original)
|
|
46
|
+
- Consistency orig_pred vs perturbed_pred (accord modèle)
|
|
47
|
+
- Degradation relative vs baseline propre: (acc_clean - acc_corrupted) / acc_clean
|
|
48
|
+
|
|
49
|
+
#### Robustesse (adversarial)
|
|
50
|
+
- Robust accuracy par attaque (transform_name) et intensité (epsilon/steps)
|
|
51
|
+
- Courbes accuracy vs epsilon et Aire Sous la Courbe (AUC)
|
|
52
|
+
- Worst-case accuracy sur l'ensemble des attaques
|
|
53
|
+
- Degradation relative vs baseline propre
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
### Agrégations / découpages
|
|
58
|
+
- By split: train / val / test
|
|
59
|
+
- By model_name
|
|
60
|
+
- By class_name
|
|
61
|
+
- By transform_name et transform_level (sévérité)
|
|
62
|
+
- Moyennes pondérées par fréquence de classe si pertinent
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# file generated by setuptools-scm
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
|
|
4
|
+
__all__ = [
|
|
5
|
+
"__version__",
|
|
6
|
+
"__version_tuple__",
|
|
7
|
+
"version",
|
|
8
|
+
"version_tuple",
|
|
9
|
+
"__commit_id__",
|
|
10
|
+
"commit_id",
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
TYPE_CHECKING = False
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from typing import Tuple
|
|
16
|
+
from typing import Union
|
|
17
|
+
|
|
18
|
+
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
|
19
|
+
COMMIT_ID = Union[str, None]
|
|
20
|
+
else:
|
|
21
|
+
VERSION_TUPLE = object
|
|
22
|
+
COMMIT_ID = object
|
|
23
|
+
|
|
24
|
+
version: str
|
|
25
|
+
__version__: str
|
|
26
|
+
__version_tuple__: VERSION_TUPLE
|
|
27
|
+
version_tuple: VERSION_TUPLE
|
|
28
|
+
commit_id: COMMIT_ID
|
|
29
|
+
__commit_id__: COMMIT_ID
|
|
30
|
+
|
|
31
|
+
__version__ = version = '0.7'
|
|
32
|
+
__version_tuple__ = version_tuple = (0, 7)
|
|
33
|
+
|
|
34
|
+
__commit_id__ = commit_id = 'g96ad968d8'
|
{kcai_data_sampling-0.0.6 → kcai_data_sampling-0.7}/src/kcai_data_sampling/adversarial_run.py
RENAMED
|
@@ -21,7 +21,7 @@ from cleverhans.torch.attacks.fast_gradient_method import fast_gradient_method
|
|
|
21
21
|
from cleverhans.torch.attacks.projected_gradient_descent import projected_gradient_descent # PGD
|
|
22
22
|
from cleverhans.torch.attacks.carlini_wagner_l2 import carlini_wagner_l2 # C&W (L2)
|
|
23
23
|
# AutoAttack / APGD
|
|
24
|
-
from
|
|
24
|
+
from pyautoattack import AutoAttack
|
|
25
25
|
|
|
26
26
|
# def _seed32(*parts, base_seed: int = 0) -> int:
|
|
27
27
|
# h = hashlib.blake2b(digest_size=8)
|
|
@@ -196,11 +196,12 @@ def run_apgd(model, x, y, eps, n_restarts=1):
|
|
|
196
196
|
def run_pipeline(cfg: Dict[str, Any]) -> str:
|
|
197
197
|
ap = cfg["adversarial_pipeline"]
|
|
198
198
|
|
|
199
|
-
# model
|
|
199
|
+
# model & préproc
|
|
200
200
|
mcfg = ap["model"]
|
|
201
201
|
resize_hw = mcfg.get("resize")
|
|
202
202
|
mean = mcfg.get("mean", [0.0,0.0,0.0])
|
|
203
203
|
std = mcfg.get("std", [1.0,1.0,1.0])
|
|
204
|
+
|
|
204
205
|
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
205
206
|
if device.type == "cuda":
|
|
206
207
|
try:
|
|
@@ -276,7 +277,7 @@ def run_pipeline(cfg: Dict[str, Any]) -> str:
|
|
|
276
277
|
|
|
277
278
|
attacks = ap["attacks"]
|
|
278
279
|
all_records: List[Dict[str, Any]] = [] # Pour les métriques finales
|
|
279
|
-
|
|
280
|
+
|
|
280
281
|
# Calcul des bornes de clipping dans l'espace normalisé
|
|
281
282
|
# Si input_range est [0,1] et on applique (x - mean) / std :
|
|
282
283
|
# clip_min = (0 - mean) / std, clip_max = (1 - mean) / std
|
|
@@ -297,24 +298,24 @@ def run_pipeline(cfg: Dict[str, Any]) -> str:
|
|
|
297
298
|
n = len(full_df)
|
|
298
299
|
num_batches = (n + batch_size - 1) // batch_size
|
|
299
300
|
total_operations = num_batches * len(attacks)
|
|
300
|
-
|
|
301
|
+
|
|
301
302
|
print(f"\n{'='*60}")
|
|
302
303
|
print(f" --- Starting adversarial pipeline ---")
|
|
303
304
|
print(f" 📊 {n} images | {len(attacks)} attacks | {num_batches} batches")
|
|
304
305
|
print(f" ⚙️ Total: {total_operations} operations")
|
|
305
306
|
print(f"{'='*60}\n")
|
|
306
|
-
|
|
307
|
+
|
|
307
308
|
pbar = tqdm(total=total_operations, desc="Global pipeline", unit="op", ncols=100)
|
|
308
|
-
|
|
309
|
+
|
|
309
310
|
# loop on attacks (for incremental writing)
|
|
310
311
|
for attack_idx, a_cfg in enumerate(attacks):
|
|
311
312
|
alias = a_cfg.get("alias", a_cfg["name"])
|
|
312
313
|
aid = int(a_cfg.get("id", 0))
|
|
313
|
-
|
|
314
|
+
|
|
314
315
|
print(f"\n🎯 Attack {attack_idx+1}/{len(attacks)}: {alias} (id={aid})")
|
|
315
|
-
|
|
316
|
+
|
|
316
317
|
records: List[Dict[str, Any]] = [] # Records for this attack
|
|
317
|
-
|
|
318
|
+
|
|
318
319
|
# loop on batch for this attack
|
|
319
320
|
for start in range(0, n, batch_size):
|
|
320
321
|
part = full_df.iloc[start:start+batch_size]
|
|
@@ -371,7 +372,7 @@ def run_pipeline(cfg: Dict[str, Any]) -> str:
|
|
|
371
372
|
lr_cw = float(params.get("lr", 5e-3))
|
|
372
373
|
# C&W expects normalized input and works in the normalized space
|
|
373
374
|
x_adv_n = run_cw(model, x_in, y, steps=steps, c=c, k=k, lr=lr_cw, clip_min=clip_min, clip_max=clip_max)
|
|
374
|
-
elif alias.startswith("apgd") and lib == "
|
|
375
|
+
elif alias.startswith("apgd") and lib == "pyautoattack":
|
|
375
376
|
eps = float(params["eps"])
|
|
376
377
|
n_restarts = int(params.get("n_restarts", 1))
|
|
377
378
|
# AutoAttack returns already preprocessed pixels for the model → here it's in the normalized space
|
|
@@ -512,13 +513,3 @@ def run_pipeline(cfg: Dict[str, Any]) -> str:
|
|
|
512
513
|
else: mdf.to_parquet(mp, index=False, compression=mc)
|
|
513
514
|
|
|
514
515
|
return out["table_output"]["path"]
|
|
515
|
-
|
|
516
|
-
if __name__ == "__main__":
|
|
517
|
-
import argparse
|
|
518
|
-
parser = argparse.ArgumentParser()
|
|
519
|
-
parser.add_argument("--config", required=True, help="Path to adversarial_pipeline.yaml")
|
|
520
|
-
args = parser.parse_args()
|
|
521
|
-
with open(args.config, "r") as f:
|
|
522
|
-
cfg = yaml.safe_load(f)
|
|
523
|
-
out_path = run_pipeline(cfg)
|
|
524
|
-
print("Wrote:", out_path)
|
|
@@ -48,7 +48,7 @@ def _predict_class(model, img_arr: np.ndarray, device, mean, std, resize):
|
|
|
48
48
|
t = _to_tensor_for_model(img_arr, resize)
|
|
49
49
|
t = t.unsqueeze(0).to(device) # Add batch dimension
|
|
50
50
|
t = _normalize_tensor(t, mean, std)
|
|
51
|
-
|
|
51
|
+
|
|
52
52
|
with torch.no_grad():
|
|
53
53
|
logits = model(t)
|
|
54
54
|
pred = logits.argmax(1).item()
|
|
@@ -795,13 +795,3 @@ def run_pipeline(cfg: Dict[str, Any]) -> str:
|
|
|
795
795
|
|
|
796
796
|
mon.finish_all()
|
|
797
797
|
return table_out_path
|
|
798
|
-
|
|
799
|
-
if __name__ == "__main__":
|
|
800
|
-
import argparse
|
|
801
|
-
|
|
802
|
-
parser = argparse.ArgumentParser()
|
|
803
|
-
parser.add_argument("--config", required=True, help="Path to augment_pipeline.yaml")
|
|
804
|
-
args = parser.parse_args()
|
|
805
|
-
with open(args.config, "r") as f:
|
|
806
|
-
cfg = yaml.safe_load(f)
|
|
807
|
-
out_path = run_pipeline(cfg)
|
|
@@ -14,7 +14,7 @@ from PIL import Image
|
|
|
14
14
|
from tqdm import tqdm
|
|
15
15
|
import yaml
|
|
16
16
|
|
|
17
|
-
from augment_run import _to_tensor_for_model, _normalize_tensor
|
|
17
|
+
from .augment_run import _to_tensor_for_model, _normalize_tensor
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
def _pil_from_bytes(b: bytes) -> Image.Image:
|
|
@@ -351,7 +351,3 @@ def main():
|
|
|
351
351
|
print("\nDone!")
|
|
352
352
|
print(f"Output columns: {list(df_out.columns)}")
|
|
353
353
|
|
|
354
|
-
|
|
355
|
-
if __name__ == "__main__":
|
|
356
|
-
main()
|
|
357
|
-
|
{kcai_data_sampling-0.0.6 → kcai_data_sampling-0.7}/src/kcai_data_sampling/run_augment_pipeline.py
RENAMED
|
@@ -646,13 +646,3 @@ def run_pipeline(cfg: Dict[str, Any]) -> str:
|
|
|
646
646
|
|
|
647
647
|
mon.finish_all()
|
|
648
648
|
return table_out_path
|
|
649
|
-
|
|
650
|
-
if __name__ == "__main__":
|
|
651
|
-
import argparse
|
|
652
|
-
|
|
653
|
-
parser = argparse.ArgumentParser()
|
|
654
|
-
parser.add_argument("--config", required=True, help="Path to augment_pipeline.yaml")
|
|
655
|
-
args = parser.parse_args()
|
|
656
|
-
with open(args.config, "r") as f:
|
|
657
|
-
cfg = yaml.safe_load(f)
|
|
658
|
-
out_path = run_pipeline(cfg)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: kcai-data-sampling
|
|
3
|
+
Version: 0.7
|
|
4
|
+
Summary: Samples generation utilities managed with uv
|
|
5
|
+
Author-email: Safenai <support@safenai.io>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Requires-Python: >=3.11
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
Requires-Dist: pyarrow>=22.0.0
|
|
10
|
+
Requires-Dist: numpy>=1.20.0
|
|
11
|
+
Requires-Dist: pillow>=8.0.0
|
|
12
|
+
Requires-Dist: scikit-learn>=1.0.0
|
|
13
|
+
Requires-Dist: torch>=2.8.0
|
|
14
|
+
Requires-Dist: ipykernel>=6.29.5
|
|
15
|
+
Requires-Dist: torchvision>=0.20.1
|
|
16
|
+
Requires-Dist: captum==0.7.0
|
|
17
|
+
Requires-Dist: torch_pruning>=1.3.7
|
|
18
|
+
Requires-Dist: tqdm==4.66.5
|
|
19
|
+
Requires-Dist: click==8.1.7
|
|
20
|
+
Requires-Dist: pyyaml
|
|
21
|
+
Requires-Dist: numpy<2
|
|
22
|
+
Requires-Dist: neural-compressor==3.1.1
|
|
23
|
+
Requires-Dist: thop
|
|
24
|
+
Requires-Dist: tabulate
|
|
25
|
+
Requires-Dist: albumentations>=2.0.8
|
|
26
|
+
Requires-Dist: pyautoattack>=0.1.1
|
|
27
|
+
Requires-Dist: boto3>=1.40.51
|
{kcai_data_sampling-0.0.6 → kcai_data_sampling-0.7}/src/kcai_data_sampling.egg-info/SOURCES.txt
RENAMED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
.gitignore
|
|
2
2
|
pyproject.toml
|
|
3
3
|
requirements.txt
|
|
4
|
+
test.ipynb
|
|
5
|
+
src/kcai_data_sampling/Description_artefacts.md
|
|
4
6
|
src/kcai_data_sampling/__init__.py
|
|
7
|
+
src/kcai_data_sampling/_version_.py
|
|
5
8
|
src/kcai_data_sampling/adversarial_run.py
|
|
6
9
|
src/kcai_data_sampling/augment_run.py
|
|
7
10
|
src/kcai_data_sampling/kc_inference.py
|
{kcai_data_sampling-0.0.6 → kcai_data_sampling-0.7}/src/kcai_data_sampling.egg-info/requires.txt
RENAMED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
pyarrow>=
|
|
1
|
+
pyarrow>=22.0.0
|
|
2
2
|
numpy>=1.20.0
|
|
3
3
|
pillow>=8.0.0
|
|
4
4
|
scikit-learn>=1.0.0
|
|
5
|
-
torch>=
|
|
5
|
+
torch>=2.8.0
|
|
6
6
|
ipykernel>=6.29.5
|
|
7
7
|
torchvision>=0.20.1
|
|
8
|
-
torch==2.5.1
|
|
9
|
-
torchvision==0.20.1
|
|
10
8
|
captum==0.7.0
|
|
11
|
-
torch_pruning
|
|
9
|
+
torch_pruning>=1.3.7
|
|
12
10
|
tqdm==4.66.5
|
|
13
11
|
click==8.1.7
|
|
14
12
|
pyyaml
|
|
@@ -16,8 +14,6 @@ numpy<2
|
|
|
16
14
|
neural-compressor==3.1.1
|
|
17
15
|
thop
|
|
18
16
|
tabulate
|
|
19
|
-
pyarrow==17.0.0
|
|
20
17
|
albumentations>=2.0.8
|
|
21
|
-
|
|
22
|
-
cleverhans>=4.0.0
|
|
18
|
+
pyautoattack>=0.1.1
|
|
23
19
|
boto3>=1.40.51
|