modelpoison
modelpoison(model, poisoned_ratio, noise_type='gaussian')
¶
Adds random noise to the parameters of a model for the purpose of data poisoning.
This function modifies the model's parameters by injecting noise according to the specified noise type and ratio. Various types of noise can be applied, including salt noise, Gaussian noise, and salt-and-pepper noise.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
OrderedDict
|
The model's parameters organized as an |
required |
poisoned_ratio
|
float
|
The proportion of noise to apply, expressed as a fraction (0 <= poisoned_ratio <= 1). |
required |
noise_type
|
str
|
The type of noise to apply to the model parameters. Supported types are: - "salt": Applies salt noise, replacing random elements with 1. - "gaussian": Applies Gaussian-distributed additive noise. - "s&p": Applies salt-and-pepper noise, replacing random elements with either 1 or low_val. Default is "gaussian". |
'gaussian'
|
Returns:
Name | Type | Description |
---|---|---|
OrderedDict |
A new |
Raises:
Type | Description |
---|---|
ValueError
|
If |
Notes
- If a layer's tensor is a single point (0-dimensional), it will be reshaped for processing.
- Unsupported noise types will result in an error message, and the original tensor will be retained.
Source code in nebula/addons/attacks/poisoning/modelpoison.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|