Skip to content

Commit 2686420

Browse files
committed
added architecture tag
1 parent 193852d commit 2686420

27 files changed

Lines changed: 3427 additions & 187 deletions

manuscripts/Poison26/00_train_models.sh

Lines changed: 68 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -13,75 +13,71 @@ SIF=/work/hdd/bbse/wklai/AdversarialData/APSO_Poison/manuscripts/POISON25/pytorc
1313
cd /work/hdd/bbse/wklai/AdversarialData/APSO_Poison/manuscripts/POISON25
1414
mkdir -p models
1515

16-
# Train MNIST prediction models
17-
# # Basic 2D CNN
18-
# TRAIN=bin/train/MNIST/train_MNIST_basic-model_standard.py
19-
# singularity exec $SIF python $TRAIN --output MNIST_basic-standard.pt
20-
#
21-
# # Basic 2D CNN with augementation
22-
# TRAIN=bin/train/MNIST/train_MNIST_basic-model_aug.py
23-
# singularity exec $SIF python $TRAIN --output MNIST_basic-aug.pt
24-
#
25-
# # Basic 2D CNN with FGSM hardening
26-
# TRAIN=bin/train/MNIST/train_MNIST_basic-model_FGSM.py
27-
# singularity exec $SIF python $TRAIN --output MNIST_basic-FGSM.pt
28-
#
29-
# # Basic 2D CNN with PGD hardening
30-
# TRAIN=bin/train/MNIST/train_MNIST_basic-model_PGD.py
31-
# singularity exec $SIF python $TRAIN --output MNIST_basic-PGD.pt
32-
#
33-
# 2D CNN model with additional layers and dropout
34-
# TRAIN=bin/train/MNIST/train_MNIST_adv-model_standard.py
35-
# singularity exec $SIF python $TRAIN --output MNIST_adv-standard.pt
36-
#
37-
# # 2D CNN model with additional layers and dropout with augmentation
38-
# TRAIN=bin/train/MNIST/train_MNIST_adv-model_aug.py
39-
# singularity exec $SIF python $TRAIN --output MNIST_adv-aug.pt
40-
#
41-
# # 2D CNN model with additional layers and dropout with FGSM hardening
42-
# TRAIN=bin/train/MNIST/train_MNIST_adv-model_FGSM.py
43-
# singularity exec $SIF python $TRAIN --output MNIST_adv-FGSM.pt
44-
#
45-
# # 2D CNN model with additional layers and dropout with PGD hardening
46-
# TRAIN=bin/train/MNIST/train_MNIST_adv-model_PGD.py
47-
# singularity exec $SIF python $TRAIN --output MNIST_adv-PGD.pt
48-
49-
mv MNIST_*pt models/
50-
51-
# # Train CIFAR10 prediction models
52-
# # Simple 2D CNN
53-
# TRAIN1=bin/train/train_CIFAR10_model1.py
54-
# # 2D CNN model with additional layers and dropout
55-
# TRAIN2=bin/train/train_CIFAR10_model2.py
56-
# # Same architecture as model 2 but with augmented input
57-
# TRAIN3=bin/train/train_CIFAR10_model3.py
58-
# # Same architecture as model 2 but with FGSM hardening
59-
# TRAIN4=bin/train/train_CIFAR10_model4.py
60-
# # Same architecture as model 2 but with PGD hardening
61-
# TRAIN5=bin/train/train_CIFAR10_model5.py
62-
#
63-
# python $TRAIN1 --output CIFAR10_model1.pt --epochs 20
64-
# python $TRAIN2 --output CIFAR10_model2.pt --epochs 20
65-
# python $TRAIN3 --output CIFAR10_model3.pt --epochs 20
66-
# python $TRAIN4 --output CIFAR10_model4.pt --epochs 20
67-
# python $TRAIN5 --output CIFAR10_model5.pt --epochs 20
68-
#
69-
# mv CIFAR10_model*pt models/
70-
#
71-
# TRAIN1=bin/train/train_audioMNIST_model1.py
72-
# # 2D CNN model with additional layers and dropout
73-
# TRAIN2=bin/train/train_audioMNIST_model2.py
74-
# # Same architecture as model 2 but with augmented input
75-
# TRAIN3=bin/train/train_audioMNIST_model3.py
76-
# # Same architecture as model 2 but with FGSM hardening
77-
# TRAIN4=bin/train/train_audioMNIST_model4.py
78-
# # Same architecture as model 2 but with PGD hardening
79-
# TRAIN5=bin/train/train_audioMNIST_model5.py
80-
#
81-
# singularity exec $SIF python $TRAIN1 --output audioMNIST_model1.pt --epochs 10
82-
# singularity exec $SIF python $TRAIN2 --output audioMNIST_model2.pt --epochs 10
83-
# singularity exec $SIF python $TRAIN3 --output audioMNIST_model3.pt --epochs 10
84-
# singularity exec $SIF python $TRAIN4 --output audioMNIST_model4.pt --epochs 10
85-
# singularity exec $SIF python $TRAIN5 --output audioMNIST_model5.pt --epochs 10
86-
#
87-
#mv audioMNIST_model* models/
16+
# ==========================================
17+
# 1. Train MNIST Prediction Models (Epochs: Default/5)
18+
# ==========================================
19+
echo "Starting MNIST Training..."
20+
21+
# Basic 2D CNN
22+
singularity exec $SIF python bin/train/MNIST/basic/model_standard.py --output mnist_basic_standard.pt
23+
singularity exec $SIF python bin/train/MNIST/basic/model_aug.py --output mnist_basic_aug.pt
24+
singularity exec $SIF python bin/train/MNIST/basic/model_fgsm.py --output mnist_basic_fgsm.pt --adv-train
25+
singularity exec $SIF python bin/train/MNIST/basic/model_pgd.py --output mnist_basic_pgd.pt --adv-train
26+
27+
# Advanced 2D CNN (VGG-style)
28+
singularity exec $SIF python bin/train/MNIST/adv/model_standard.py --output mnist_adv_standard.pt
29+
singularity exec $SIF python bin/train/MNIST/adv/model_aug.py --output mnist_adv_aug.pt
30+
singularity exec $SIF python bin/train/MNIST/adv/model_fgsm.py --output mnist_adv_fgsm.pt --adv-train
31+
singularity exec $SIF python bin/train/MNIST/adv/model_pgd.py --output mnist_adv_pgd.pt --adv-train
32+
33+
mv mnist_*.pt models/
34+
35+
36+
# ==========================================
37+
# 2. Train CIFAR-10 Prediction Models (Epochs: 20)
38+
# ==========================================
39+
echo "Starting CIFAR-10 Training..."
40+
E=20
41+
42+
# Basic 2D CNN
43+
singularity exec $SIF python bin/train/CIFAR10/basic/model_standard.py --output cifar10_basic_standard.pt --epochs $E
44+
singularity exec $SIF python bin/train/CIFAR10/basic/model_aug.py --output cifar10_basic_aug.pt --epochs $E
45+
singularity exec $SIF python bin/train/CIFAR10/basic/model_fgsm.py --output cifar10_basic_fgsm.pt --epochs $E --adv-train
46+
singularity exec $SIF python bin/train/CIFAR10/basic/model_pgd.py --output cifar10_basic_pgd.pt --epochs $E --adv-train
47+
48+
# MobileNet
49+
singularity exec $SIF python bin/train/CIFAR10/MobileNet/model_standard.py --output cifar10_mobilenet_standard.pt --epochs $E
50+
singularity exec $SIF python bin/train/CIFAR10/MobileNet/model_aug.py --output cifar10_mobilenet_aug.pt --epochs $E
51+
singularity exec $SIF python bin/train/CIFAR10/MobileNet/model_fgsm.py --output cifar10_mobilenet_fgsm.pt --epochs $E --adv-train
52+
singularity exec $SIF python bin/train/CIFAR10/MobileNet/model_pgd.py --output cifar10_mobilenet_pgd.pt --epochs $E --adv-train
53+
54+
# RegNetX
55+
singularity exec $SIF python bin/train/CIFAR10/RegNetX/model_standard.py --output cifar10_regnetx_standard.pt --epochs $E
56+
singularity exec $SIF python bin/train/CIFAR10/RegNetX/model_aug.py --output cifar10_regnetx_aug.pt --epochs $E
57+
singularity exec $SIF python bin/train/CIFAR10/RegNetX/model_fgsm.py --output cifar10_regnetx_fgsm.pt --epochs $E --adv-train
58+
singularity exec $SIF python bin/train/CIFAR10/RegNetX/model_pgd.py --output cifar10_regnetx_pgd.pt --epochs $E --adv-train
59+
60+
mv cifar10_*.pt models/
61+
62+
63+
# ==========================================
64+
# 3. Train AudioMNIST Prediction Models (Epochs: 10)
65+
# ==========================================
66+
echo "Starting AudioMNIST Training..."
67+
E=10
68+
69+
# Basic 1D CNN
70+
singularity exec $SIF python bin/train/AudioMNIST/basic/model_standard.py --output audiomnist_basic_standard.pt --epochs $E
71+
singularity exec $SIF python bin/train/AudioMNIST/basic/model_aug.py --output audiomnist_basic_aug.pt --epochs $E
72+
singularity exec $SIF python bin/train/AudioMNIST/basic/model_fgsm.py --output audiomnist_basic_fgsm.pt --epochs $E --adv-train
73+
singularity exec $SIF python bin/train/AudioMNIST/basic/model_pgd.py --output audiomnist_basic_pgd.pt --epochs $E --adv-train
74+
75+
# MobileNet (2D Spectrogram wrapper)
76+
singularity exec $SIF python bin/train/AudioMNIST/MobileNet/model_standard.py --output audiomnist_mobilenet_standard.pt --epochs $E
77+
singularity exec $SIF python bin/train/AudioMNIST/MobileNet/model_aug.py --output audiomnist_mobilenet_aug.pt --epochs $E
78+
singularity exec $SIF python bin/train/AudioMNIST/MobileNet/model_fgsm.py --output audiomnist_mobilenet_fgsm.pt --epochs $E --adv-train
79+
singularity exec $SIF python bin/train/AudioMNIST/MobileNet/model_pgd.py --output audiomnist_mobilenet_pgd.pt --epochs $E --adv-train
80+
81+
mv audiomnist_*.pt models/
82+
83+
echo "All training complete!"
Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,51 @@
1+
#!/bin/bash
2+
3+
# Load environment (or replace with your Singularity execution if dependencies require it)
14
module load anaconda3_cpu
25

6+
# Ensure the output directory exists
37
mkdir -p labels
48
LABEL=bin/utils/generate_FalseLabels.py
59

10+
# ==========================================
11+
# 1. Generate MNIST Labels
12+
# ==========================================
13+
echo "Generating MNIST attack labels..."
614
OUTPUT=bin/utils/output_MNIST_labels.py
715
python $OUTPUT
8-
mv MNIST*labels.tsv labels/
16+
17+
# Move generated files and create misclassification targets
18+
mv MNIST*labels.tsv labels/ 2>/dev/null
919
python $LABEL --input labels/MNIST_test_labels.tsv --output labels/MNIST_test_labels-misclassify.tsv --seed 1
1020

11-
OUTPUT=bin/utils/output_CIFAR10_labels.py
1221

22+
# ==========================================
23+
# 2. Generate CIFAR-10 Labels
24+
# ==========================================
25+
echo "Generating CIFAR-10 attack labels..."
26+
OUTPUT=bin/utils/output_CIFAR10_labels.py
1327
python $OUTPUT
14-
mv CIFAR10*labels.tsv labels/
28+
29+
# Move generated files and create misclassification targets
30+
mv CIFAR10*labels.tsv labels/ 2>/dev/null
1531
python $LABEL --input labels/CIFAR10_test_labels.tsv --output labels/CIFAR10_test_labels-misclassify.tsv --seed 1
32+
33+
34+
# ==========================================
35+
# 3. Generate AudioMNIST Labels
36+
# ==========================================
37+
echo "Generating AudioMNIST attack labels..."
38+
OUTPUT=bin/utils/output_audioMNIST_labels.py
39+
40+
# Added a safety check in case the utility script has a slightly different naming convention
41+
if [ -f "$OUTPUT" ]; then
42+
python $OUTPUT
43+
# Catch both camelCase and lowercase generations just in case
44+
mv audioMNIST*labels.tsv labels/ 2>/dev/null || mv AudioMNIST*labels.tsv labels/ 2>/dev/null
45+
46+
python $LABEL --input labels/audioMNIST_test_labels.tsv --output labels/audioMNIST_test_labels-misclassify.tsv --seed 1
47+
else
48+
echo "Warning: $OUTPUT not found. Skipping AudioMNIST label generation. Ensure the utility script exists."
49+
fi
50+
51+
echo "All attack labels successfully generated!"
Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
#!/bin/bash
22

33
SIF=/storage/group/bfp2/default/wkl2-WillLai/Adversarial_Project/Adversarial_Observation/manuscripts/POISON25/pytorch-captum.sif
4-
54
WORKINGDIR=/storage/group/bfp2/default/wkl2-WillLai/Adversarial_Project/Adversarial_Observation/manuscripts/POISON25
6-
OUTPUT=$WORKINGDIR/MNIST_test_model4
5+
6+
# ==========================================
7+
# CONFIGURATION
8+
# Set the model you want to attack here (e.g., mnist_basic_standard, mnist_adv_fgsm, mnist_adv_pgd)
9+
# ==========================================
10+
MODEL_NAME="mnist_adv_fgsm"
11+
MODEL_FILE="${MODEL_NAME}.pt"
12+
13+
OUTPUT=$WORKINGDIR/MNIST_test_${MODEL_NAME}
714
mkdir -p $OUTPUT
815
cd $OUTPUT
916

10-
#HEADER="#!/bin/bash\n#SBATCH -A bbse-delta-cpu\n#SBATCH --partition=cpu\n#SBATCH --nodes=1\n#SBATCH --tasks=1\n#SBATCH --cpus-per-task=4\n#SBATCH --mem=24g\n#SBATCH --time=8:00:00\n"
1117
HEADER="#!/bin/bash\n#SBATCH --nodes=1\n#SBATCH --ntasks=4\n#SBATCH --mem=24GB\n#SBATCH --time=36:00:00\n#SBATCH --partition=open\n"
1218

13-
# Label file
14-
#LABELS=$WORKINGDIR/labels/MNIST_test_labels-misclassify_r2.tsv
15-
#LABELS=$WORKINGDIR/labels/MNIST_test_labels-misclassify.tsv
16-
LABELS=$WORKINGDIR/MNIST_stats/MNIST_test_labels_model4-misclassify_RESILIENT.tsv
17-
# Model file
18-
MODEL=MNIST_model4.pt
19+
# Label file (Toggle between standard misclassify or resilient stats)
20+
LABELS=$WORKINGDIR/labels/MNIST_test_labels-misclassify.tsv
21+
# LABELS=$WORKINGDIR/MNIST_stats/MNIST_test_labels_${MODEL_NAME}-misclassify_RESILIENT.tsv
22+
1923
# Attack script
2024
POISON=$WORKINGDIR/bin/attack/poison_MNIST.py
2125

@@ -26,11 +30,8 @@ RETRY=5
2630
COHORT_ID=0
2731
COHORT_INDEX=0
2832

29-
echo "Preparing cohort: $COHORT_ID"
33+
echo "Preparing cohort: $COHORT_ID for model: $MODEL_NAME"
3034
echo -e $HEADER > $OUTPUT/attack_$COHORT_ID.slurm
31-
# Delta-specific
32-
#echo "module load anaconda3_gpu" >> $OUTPUT/attack_$COHORT_ID.slurm
33-
3435
echo "cd $OUTPUT" >> $OUTPUT/attack_$COHORT_ID.slurm
3536

3637
# Read the file line by line
@@ -39,27 +40,23 @@ while read line; do
3940
if [[ "$line" == index* ]]; then
4041
continue
4142
fi
42-
# echo "Preparing cohort: $COHORT_ID"
4343

4444
# Extract values using awk
4545
index=$(echo "$line" | awk '{print $1}')
4646
trueLabel=$(echo "$line" | awk '{print $2}')
4747
falseLabel=$(echo "$line" | awk '{print $3}')
4848

49-
# Use these variables as needed
50-
echo "singularity exec -B $WORKINGDIR/models:/models $SIF bash -c \"time python $POISON --modelPath /models/$MODEL --epochs $EPOCH --particleNum $PARTICLE --maxRetries $RETRY --outputPath MNIST_test_$index --targetLabel $falseLabel --sourceIndex $index\"" >> $OUTPUT/attack_$COHORT_ID.slurm
49+
# Execute poisoning
50+
echo "singularity exec -B $WORKINGDIR/models:/models $SIF bash -c \"time python $POISON --modelPath /models/$MODEL_FILE --epochs $EPOCH --particleNum $PARTICLE --maxRetries $RETRY --outputPath MNIST_test_$index --targetLabel $falseLabel --sourceIndex $index\"" >> $OUTPUT/attack_$COHORT_ID.slurm
5151
((COHORT_INDEX++))
5252

5353
if [ $COHORT_INDEX -gt 70 ]; then
54-
COHORT_INDEX=0
55-
((COHORT_ID++))
56-
57-
echo "Preparing cohort: $COHORT_ID"
58-
echo -e $HEADER > $OUTPUT/attack_$COHORT_ID.slurm
59-
# echo "module load anaconda3_gpu" >> $OUTPUT/attack_$COHORT_ID.slurm
54+
COHORT_INDEX=0
55+
((COHORT_ID++))
6056

61-
echo "cd $OUTPUT" >> $OUTPUT/attack_$COHORT_ID.slurm
57+
echo "Preparing cohort: $COHORT_ID"
58+
echo -e $HEADER > $OUTPUT/attack_$COHORT_ID.slurm
59+
echo "cd $OUTPUT" >> $OUTPUT/attack_$COHORT_ID.slurm
6260
fi
6361

64-
done < "$LABELS"
65-
62+
done < "$LABELS"
Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
#!/bin/bash
22

33
SIF=/storage/group/bfp2/default/wkl2-WillLai/Adversarial_Project/Adversarial_Observation/manuscripts/POISON25/pytorch-captum.sif
4-
54
WORKINGDIR=/storage/group/bfp2/default/wkl2-WillLai/Adversarial_Project/Adversarial_Observation/manuscripts/POISON25
6-
OUTPUT=$WORKINGDIR/CIFAR10_test_model1
5+
6+
# ==========================================
7+
# CONFIGURATION
8+
# Set the model you want to attack here (e.g., cifar10_basic_standard, cifar10_mobilenet_pgd, cifar10_regnetx_aug)
9+
# ==========================================
10+
MODEL_NAME="cifar10_mobilenet_standard"
11+
MODEL_FILE="${MODEL_NAME}.pt"
12+
13+
OUTPUT=$WORKINGDIR/CIFAR10_test_${MODEL_NAME}
714
mkdir -p $OUTPUT
815
cd $OUTPUT
916

10-
#HEADER="#!/bin/bash\n#SBATCH -A bbse-delta-cpu\n#SBATCH --partition=cpu\n#SBATCH --nodes=1\n#SBATCH --tasks=1\n#SBATCH --cpus-per-task=4\n#SBATCH --mem=24g\n#SBATCH --time=8:00:00\n"
1117
HEADER="#!/bin/bash\n#SBATCH --nodes=1\n#SBATCH --ntasks=4\n#SBATCH --mem=24GB\n#SBATCH --time=36:00:00\n#SBATCH --partition=open\n"
1218

1319
# Label file
14-
#LABELS=$WORKINGDIR/labels/CIFAR10_test_labels-misclassify_r2.tsv
1520
LABELS=$WORKINGDIR/labels/CIFAR10_test_labels-misclassify.tsv
16-
# Model file
17-
MODEL=CIFAR10_model1.pt
21+
1822
# Attack script
1923
POISON=$WORKINGDIR/bin/attack/poison_CIFAR10.py
2024

@@ -25,11 +29,8 @@ RETRY=1
2529
COHORT_ID=0
2630
COHORT_INDEX=0
2731

28-
echo "Preparing cohort: $COHORT_ID"
32+
echo "Preparing cohort: $COHORT_ID for model: $MODEL_NAME"
2933
echo -e $HEADER > $OUTPUT/attack_$COHORT_ID.slurm
30-
# Delta-specific
31-
#echo "module load anaconda3_gpu" >> $OUTPUT/attack_$COHORT_ID.slurm
32-
3334
echo "cd $OUTPUT" >> $OUTPUT/attack_$COHORT_ID.slurm
3435

3536
# Read the file line by line
@@ -38,27 +39,23 @@ while read line; do
3839
if [[ "$line" == index* ]]; then
3940
continue
4041
fi
41-
# echo "Preparing cohort: $COHORT_ID"
4242

4343
# Extract values using awk
4444
index=$(echo "$line" | awk '{print $1}')
4545
trueLabel=$(echo "$line" | awk '{print $2}')
4646
falseLabel=$(echo "$line" | awk '{print $3}')
4747

48-
# Use these variables as needed
49-
echo "singularity exec -B $WORKINGDIR/models:/models $SIF bash -c \"time python $POISON --modelPath /models/$MODEL --epochs $EPOCH --particleNum $PARTICLE --maxRetries $RETRY --outputPath CIFAR10_test_$index --targetLabel $falseLabel --sourceIndex $index\"" >> $OUTPUT/attack_$COHORT_ID.slurm
48+
# Execute poisoning
49+
echo "singularity exec -B $WORKINGDIR/models:/models $SIF bash -c \"time python $POISON --modelPath /models/$MODEL_FILE --epochs $EPOCH --particleNum $PARTICLE --maxRetries $RETRY --outputPath CIFAR10_test_$index --targetLabel $falseLabel --sourceIndex $index\"" >> $OUTPUT/attack_$COHORT_ID.slurm
5050
((COHORT_INDEX++))
5151

5252
if [ $COHORT_INDEX -gt 100 ]; then
53-
COHORT_INDEX=0
54-
((COHORT_ID++))
55-
56-
echo "Preparing cohort: $COHORT_ID"
57-
echo -e $HEADER > $OUTPUT/attack_$COHORT_ID.slurm
58-
# echo "module load anaconda3_gpu" >> $OUTPUT/attack_$COHORT_ID.slurm
53+
COHORT_INDEX=0
54+
((COHORT_ID++))
5955

60-
echo "cd $OUTPUT" >> $OUTPUT/attack_$COHORT_ID.slurm
56+
echo "Preparing cohort: $COHORT_ID"
57+
echo -e $HEADER > $OUTPUT/attack_$COHORT_ID.slurm
58+
echo "cd $OUTPUT" >> $OUTPUT/attack_$COHORT_ID.slurm
6159
fi
6260

63-
done < "$LABELS"
64-
61+
done < "$LABELS"

0 commit comments

Comments
 (0)