|
| 1 | +# Changelog |
| 2 | + |
| 3 | +All notable changes to DeepDefend are documented here. The format loosely |
| 4 | +follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and this |
| 5 | +project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). |
| 6 | + |
| 7 | +## [0.2.0] |
| 8 | + |
| 9 | +This release is a correctness and security pass over the whole package. Many |
| 10 | +functions that previously returned *silently wrong* results (or crashed) now do |
| 11 | +what their name and documentation claim. Because the numerical output of several |
| 12 | +attacks and defenses changes, the minor version was bumped. |
| 13 | + |
| 14 | +### Fixed — attacks |
| 15 | + |
| 16 | +- **`jsma`** no longer raises on every call (it indexed a rank-4 Jacobian with |
| 17 | + five indices and mutated an eager tensor in place). It is now a real |
| 18 | + saliency-map attack that works on any input rank. |
| 19 | +- **`spsa`** no longer raises on every call (it passed a tensor, not a |
| 20 | + `tf.Variable`, to the optimizer and hard-coded rank-4 inputs). The gradient |
| 21 | + estimate now uses the correct finite difference |
| 22 | + `(L(x+δd) − L(x−δd)) / (2δ)`, the optimiser is Adam, and any number of |
| 23 | + samples and dimensions is accepted. |
| 24 | +- **`ead`** no longer returns the input unchanged with its default arguments. |
| 25 | + It now performs a proper ISTA/proximal step on the elastic-net objective. |
| 26 | +- **`cw`** is now the Carlini & Wagner L2 attack: the tanh-space optimisation |
| 27 | + actually minimises distortion and the `c` / `kappa` parameters change the |
| 28 | + result (previously they were inert). The untargeted target class is fixed at |
| 29 | + the runner-up class instead of being recomputed every step. |
| 30 | +- **`deepfool`** is now DeepFool: per-class decision boundaries, an optional |
| 31 | + L∞ budget, and output that stays inside the valid data range (it used to |
| 32 | + return values such as `-0.90` and `2.08` for `[0, 1]` inputs). |
| 33 | +- **`fgsm`** output is clipped to the valid data range instead of overshooting |
| 34 | + to `-0.01` / `1.007`. |
| 35 | +- **All attacks** now accept sparse integer labels, one-hot labels and binary |
| 36 | + targets; previously every attack rejected the sparse-label format used by most |
| 37 | + Keras examples. |
| 38 | +- **All attacks** now auto-detect `from_logits` (with an override), call the |
| 39 | + model with `training=False`, and support an explicit `clip_min` / `clip_max` |
| 40 | + for normalised inputs. |
| 41 | +- **Targeted attacks** no longer freeze at step 0 (the early-stop mask had the |
| 42 | + logic inverted for targeted mode). |
| 43 | +- **`pgd`** gained `random_start` and no longer duplicates `bim`. |
| 44 | +- **DeepFool / JSMA / SPSA** no longer project against the whole batch inside |
| 45 | + their per-sample loops. |
| 46 | +- **`word_swap` / `char_swap`** preserve whitespace, newlines and punctuation, |
| 47 | + accept a `seed`, and `word_swap` no longer silently returns the input when |
| 48 | + `swap_dict` is missing. |
| 49 | + |
| 50 | +### Fixed — defenses |
| 51 | + |
| 52 | +- **All preprocessing defenses** can now be saved and reloaded. Their layers |
| 53 | + were previously defined inside the function body, so every defended model |
| 54 | + failed at `model.save()` / `load_model()`. |
| 55 | +- **`jpeg_compression`**, **`feature_squeezing`** and |
| 56 | + **`total_variation_minimization`** no longer break the gradient: attacks |
| 57 | + against a defended model used to raise `ValueError` (JPEG) or silently return |
| 58 | + a zero perturbation (TV, quantisation). They now use a straight-through |
| 59 | + gradient. |
| 60 | +- **`median_smoothing`** is a real median filter again (it was calling |
| 61 | + `avg_pool2d`). |
| 62 | +- **`gaussian_blur`** builds an actual Gaussian kernel and honours `sigma` |
| 63 | + (the parameter was previously ignored). |
| 64 | +- **`pixel_deflection`** no longer raises on every call, works inside |
| 65 | + `tf.function`, and is reproducible when a `seed` is given. |
| 66 | +- **`adversarial_training`** generates adversarial examples in batches instead |
| 67 | + of one sample at a time (~500× fewer model calls), honours the caller's |
| 68 | + optimiser and loss instead of forcing Adam + categorical cross-entropy, and |
| 69 | + accepts `epochs`, `batch_size`, `verbose` and a custom `attack`. |
| 70 | +- **`defensive_distillation`** no longer applies softmax twice, scales the |
| 71 | + distillation term by `T²`, evaluates the teacher in inference mode, and works |
| 72 | + for both probability and logit outputs. |
| 73 | +- **`adversarial_logit_pairing`** generates adversarial examples inside the |
| 74 | + training step; the previous implementation paired two models on clean inputs. |
| 75 | +- **`randomized_smoothing`** clips the noisy input, is reproducible when |
| 76 | + seeded, and ships with `smooth_predict()` for Monte-Carlo prediction and a |
| 77 | + certified-radius estimate. |
| 78 | +- **`feature_denoising`** has an explicit `method` (`median` / `gaussian`) and a |
| 79 | + new `FeatureDenoisingBlock` layer for feature-level denoising. |
| 80 | +- **`input_transformation`** raises instead of silently returning an |
| 81 | + undefended model when no transformation is given. |
| 82 | +- **`word_masking`** preserves whitespace and accepts a `seed`. |
| 83 | +- **All defenses** raise a clear `TypeError` for subclassed or multi-input |
| 84 | + models instead of an obscure `AttributeError`, and reject invalid parameters |
| 85 | + (`bit_depth` outside 1-8, `num_bins < 2`, `quality` outside 1-100, even kernel |
| 86 | + sizes, negative noise levels, ...) instead of producing `NaN`. |
| 87 | + |
| 88 | +### Added |
| 89 | + |
| 90 | +- `deepdefend.__version__`, `deepdefend.__all__`, and lazy imports: every public |
| 91 | + function is reachable as `deepdefend.<name>`, and `import deepdefend` no |
| 92 | + longer imports TensorFlow. |
| 93 | +- `deepdefend/smooth_predict` for Monte-Carlo randomized smoothing. |
| 94 | +- 170 tests covering attacks, defenses, serialisation, gradients, label |
| 95 | + formats, input validation and the public API. |
| 96 | +- CI: lint + test matrix (3.10-3.12) + reproducible build on every push and PR. |
| 97 | +- `SECURITY.md`, `CODE_OF_CONDUCT.md`, Dependabot, pre-commit and |
| 98 | + `pyproject.toml`. |
| 99 | + |
| 100 | +### Changed |
| 101 | + |
| 102 | +- `setup.py` was replaced by `pyproject.toml`; the version is now static and |
| 103 | + `pip install .` works from a checkout (it previously failed because the |
| 104 | + version was a `{{VERSION_PLACEHOLDER}}`). |
| 105 | +- Dependencies are bounded (`numpy<3`, `tensorflow>=2.13,<3`) and |
| 106 | + `python_requires` is `>=3.9` (TensorFlow 2.x is not available on 3.6-3.8). |
| 107 | +- `pgd` / `bim` / `mim` default `alpha` is now `epsilon / 4` (previously |
| 108 | + `0.01`, which equals `epsilon` for the default settings). |
| 109 | +- `jsma` defaults are `theta=0.0`, `gamma=0.2`. |
| 110 | +- `cw` defaults are `epsilon=None` (unconstrained), `c=10.0`. |
| 111 | +- `spsa` defaults are `num_steps=50`, `learning_rate=0.05`, `spsa_samples=32` |
| 112 | + probe directions, `delta=epsilon/5`. |
| 113 | +- `median_smoothing` is documented as an alias of `spatial_smoothing`. |
| 114 | +- The publish workflow uses SHA-pinned actions, a tag/version consistency check, |
| 115 | + a test gate, `python -m build`, `twine check`, PyPI Trusted Publishing (OIDC) |
| 116 | + and a protected `pypi` environment. |
| 117 | + |
| 118 | +### Removed |
| 119 | + |
| 120 | +- **`gradient_masking`** (and the `GradientMaskingModel` wrapper) has been |
| 121 | + deleted. It only masked *training* gradients and had no effect on the |
| 122 | + gradients an attacker computes at inference time — attacks against a wrapped |
| 123 | + model were bit-identical to attacks against the base model. Gradient masking |
| 124 | + is a documented false defense (Athalye et al., 2018) that makes a model look |
| 125 | + robust while leaving it vulnerable, so it does not belong in a robustness |
| 126 | + library. Mask gradients in your own `train_step` if you want the training |
| 127 | + regulariser, and never report it as a security measure. |
| 128 | +- The `setup.py`-based `{{VERSION_PLACEHOLDER}}` release mechanism. |
| 129 | + |
| 130 | +## [0.1.5] |
| 131 | + |
| 132 | +- Added MIM and EAD attacks, word/character swap attacks, pixel deflection, |
| 133 | + Gaussian blur, TV minimisation and median smoothing defenses, word masking, |
| 134 | + and a support table. |
| 135 | + |
| 136 | +## [0.1.4] |
| 137 | + |
| 138 | +- Added the SPSA attack and the JPEG compression defense. |
| 139 | + |
| 140 | +## [0.1.3] |
| 141 | + |
| 142 | +- Added randomized smoothing, feature denoising, thermometer encoding, |
| 143 | + adversarial logit pairing and spatial smoothing. |
| 144 | + |
| 145 | +## [0.1.2] |
| 146 | + |
| 147 | +- Three new attacks and three new defenses. |
0 commit comments