labelflipping
labelFlipping(dataset, indices, poisoned_persent=0, targeted=False, target_label=4, target_changed_label=7)
¶
Flips the labels of a specified portion of a dataset to random values or to a specific target label.
This function modifies the labels of selected samples in the dataset based on the specified poisoning percentage. Labels can be flipped either randomly or targeted to change from a specific label to another specified label.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset
|
Dataset
|
The dataset containing training data, expected to be a PyTorch dataset
with a |
required |
indices
|
list of int
|
The list of indices in the dataset to consider for label flipping. |
required |
poisoned_percent
|
float
|
The ratio of labels to change, expressed as a fraction (0 <= poisoned_percent <= 1). Default is 0. |
required |
targeted
|
bool
|
If True, flips only labels matching |
False
|
target_label
|
int
|
The label to change when |
4
|
target_changed_label
|
int
|
The label to which |
7
|
Returns:
Name | Type | Description |
---|---|---|
Dataset |
A deep copy of the original dataset with modified labels in |
Raises:
Type | Description |
---|---|
ValueError
|
If |
Notes
- When not in targeted mode, labels are flipped for a random selection of indices based on the specified
poisoned_percent
. The new label is chosen randomly from the existing classes. - In targeted mode, labels that match
target_label
are directly changed totarget_changed_label
.
Source code in nebula/addons/attacks/poisoning/labelflipping.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 64 65 66 67 68 69 70 |
|