SCLBD/BackdoorBench

Cannot generate poison data in SSBA algorithm

Closed this issue · 5 comments

I really appreciate your job.
Excuse me. I cannot generate poison data in ssba.py("--attack_train_replace_imgs_path" and "--attack_test_replace_imgs_path" should receive two path for poisoned training data and poisoned testing data, respectively)
We've already installed the packages in requirement.txt file.
We generated the toxic data based on the command in the readme, but the execution reported an error at step 3.
微信图片_20230728171834
I want to ask how should I solve this problem. Thanks in advance!

Hello, I need all your command line inputs to check whether your command line args are wrong or there are bugs in code.

Try this. I have already go through all of them and successfully start the attack.

# go to resource/ssba !
python dataset_convert_into_images.py --dataset cifar10

mkdir jul29

python train.py \
  --data_dir ../../data/cifar10_seperate_images/train \
  --output_dir ./jul29 \
  --EXP_NAME jul29 \
  --random_seed 0 \
  --fingerprint_length 100 \
  --image_resolution 32 \
  --num_epochs 20 \
  --batch_size 64 \
  --use_residual 0 \
  --use_modulated 0 \
  --fc_layers 0 \
  --fused_conv 0

# embedding training dataset
python embed_fingerprints.py \
    --encoder_path ./jul29/checkpoints/jul29_encoder.pth \
    --data_dir ../../data/cifar10_seperate_images/train \
    --output_dir ../../data/cifar10_seperate_images/train_encode \
    --image_resolution 32 \
    --identical_fingerprints \
    --check \
    --decoder_path ./jul29/checkpoints/jul29_decoder.pth \
    --batch_size 64 \
    --seed 0 \
    --encode_method bch \
    --secret secret \
    --use_residual 0 \
    --use_modulated 0 \
    --fused_conv 0 \
    --fc_layers 0 \
    --cuda 0
    
# pack images into npy file
python utils/pack_images.py \
  --path ../../data/cifar10_seperate_images/train_encode \
  --save_file_path ../../data/cifar10_seperate_images/train_encode.npy
  
# embedding test dataset
python embed_fingerprints.py \
    --encoder_path ./jul29/checkpoints/jul29_encoder.pth \
    --data_dir ../../data/cifar10_seperate_images/test \
    --output_dir ../../data/cifar10_seperate_images/test_encode \
    --image_resolution 32 \
    --identical_fingerprints \
    --check \
    --decoder_path ./jul29/checkpoints/jul29_decoder.pth \
    --batch_size 64 \
    --seed 0 \
    --encode_method bch \
    --secret secret \
    --use_residual 0 \
    --use_modulated 0 \
    --fused_conv 0 \
    --fc_layers 0 \
    --cuda 0

# pack images into npy file
python utils/pack_images.py \
  --path ../../data/cifar10_seperate_images/test_encode \
  --save_file_path ../../data/cifar10_seperate_images/test_encode.npy

# go to root of backdoorbench first !
python attack/ssba.py --attack_train_replace_imgs_path ../data/cifar10_seperate_images/train_encode.npy --attack_test_replace_imgs_path ../data/cifar10_seperate_images/test_encode.npy

ok,thanks for you.

Try this. I have already go through all of them and successfully start the attack.

# go to resource/ssba !
python dataset_convert_into_images.py --dataset cifar10

mkdir jul29

python train.py \
  --data_dir ../../data/cifar10_seperate_images/train \
  --output_dir ./jul29 \
  --EXP_NAME jul29 \
  --random_seed 0 \
  --fingerprint_length 100 \
  --image_resolution 32 \
  --num_epochs 20 \
  --batch_size 64 \
  --use_residual 0 \
  --use_modulated 0 \
  --fc_layers 0 \
  --fused_conv 0

# embedding training dataset
python embed_fingerprints.py \
    --encoder_path ./jul29/checkpoints/jul29_encoder.pth \
    --data_dir ../../data/cifar10_seperate_images/train \
    --output_dir ../../data/cifar10_seperate_images/train_encode \
    --image_resolution 32 \
    --identical_fingerprints \
    --check \
    --decoder_path ./jul29/checkpoints/jul29_decoder.pth \
    --batch_size 64 \
    --seed 0 \
    --encode_method bch \
    --secret secret \
    --use_residual 0 \
    --use_modulated 0 \
    --fused_conv 0 \
    --fc_layers 0 \
    --cuda 0
    
# pack images into npy file
python utils/pack_images.py \
  --path ../../data/cifar10_seperate_images/train_encode \
  --save_file_path ../../data/cifar10_seperate_images/train_encode.npy
  
# embedding test dataset
python embed_fingerprints.py \
    --encoder_path ./jul29/checkpoints/jul29_encoder.pth \
    --data_dir ../../data/cifar10_seperate_images/test \
    --output_dir ../../data/cifar10_seperate_images/test_encode \
    --image_resolution 32 \
    --identical_fingerprints \
    --check \
    --decoder_path ./jul29/checkpoints/jul29_decoder.pth \
    --batch_size 64 \
    --seed 0 \
    --encode_method bch \
    --secret secret \
    --use_residual 0 \
    --use_modulated 0 \
    --fused_conv 0 \
    --fc_layers 0 \
    --cuda 0

# pack images into npy file
python utils/pack_images.py \
  --path ../../data/cifar10_seperate_images/test_encode \
  --save_file_path ../../data/cifar10_seperate_images/test_encode.npy

# go to root of backdoorbench first !
python attack/ssba.py --attack_train_replace_imgs_path ../data/cifar10_seperate_images/train_encode.npy --attack_test_replace_imgs_path ../data/cifar10_seperate_images/test_encode.npy

thanks for you, I try to use your command and successfully.

Hi,
Thanks for sharing your wonderful work.

I met the following errors when reproducing the SSBA algorithm:

python embed_fingerprints.py --encoder_path ./jul29/checkpoints/jul29_encoder.pth --data_dir ../../data/cifar10_seperate_images/train --output_dir ../../data/cifar10_seperate_images/train_encode --image_resolution 32 --identical_fingerprints --check --decoder_path ./jul29/checkpoints/jul29_decoder.pth --batch_size 64 --seed 0 --encode_method bch --secret secret --use_residual 0 --use_modulated 0 --fused_conv 0 --fc_layers 0 --cuda 0
use_celeba_preprocessing False <
encoder_path ./jul29/checkpoints/jul29_encoder.pth <
data_dir ../../data/cifar10_seperate_images/train <
output_dir ../../data/cifar10_seperate_images/train_encode <
image_resolution 32 <
identical_fingerprints True <
check True <
decoder_path ./jul29/checkpoints/jul29_decoder.pth <
batch_size 64 <
cuda 0 <
use_residual 0 <
encode_method bch <
secret secret <
seed 0 <
diff_bits 0 <
manual_str None <
proportion 1.0 <
use_modulated 0 <
fc_layers 0 <
fused_conv 0 <
bias_init None <
test_save_file None <
poison_rate 1.0 <
Loading image folder ../../data/cifar10_seperate_images/train ...
Finished. Loading took 0.23s
----------Not using modulated conv!----------
Fingerprinting the images...
Using bch code with secret string: secret
Traceback (most recent call last):
File "embed_fingerprints.py", line 281, in
main()
File "embed_fingerprints.py", line 278, in main
embed_fingerprints()
File "embed_fingerprints.py", line 171, in embed_fingerprints
identical = args.identical_fingerprints)
File "/home/backdoor/ssba/generate_fingerprints.py", line 63, in generate_fingerprints
fingerprints = generate_fingerprints_from_bch(fingerprint_size, secret)
File "/home/backdoor/ssba/generate_fingerprints.py", line 13, in generate_fingerprints_from_bch
bch = bchlib.BCH(BCH_POLYNOMIAL, BCH_BITS)
RuntimeError: unable to inititalize bch, invalid parameters?
_

您好, 感谢您分享您的精彩工作。

我在重现SSBA算法时遇到以下错误:

python embed_fingerprints.py --encoder_path ./jul29/checkpoints/jul29_encoder.pth --data_dir ../../data/cifar10_seperate_images/train --output_dir ../../data/cifar10_seperate_images/train_encode --image_resolution 32 -- same_fingerprints --check --decoder_path ./jul29/checkpoints/jul29_decoder.pth --batch_size 64 --seed 0 --encode_method bch --secret 秘密 --use_residual 0 --use_modulated 0 --fused_conv 0 --fc_layers 0 -- cuda 0 use_celeba_preprocessing False < 编码器路径./jul29/checkpoints/jul29_encoder.pth < data_dir ../../data/cifar10_seperate_images/train < output_dir ../../data/cifar10_seperate_images/train_encode < image_resolution 32 < Same_fingerprints True < check True < 解码器路径./jul29/checkpoints/jul29_decoder.pth < batch_size 64 < cuda 0 < use_residual 0 < encode_method bch < 秘密秘密< 种子0< diff_bits 0< manual_str无< 比例1.0< use_modulated 0< fc_layers 0< fused_conv 0< bias_init无< test_save_file无< poison_rate 1.0< 正在加载图像文件夹../../data/cifar10_seperate_images/train ... 已完成。加载花费了 0.23 秒 ---------- 不使用调制转换!------------ 对图像进行指纹识别... 使用带有秘密字符串的 bch 代码:秘密 回溯(最近一次调用最后一次) : 文件“embed_fingerprints.py”,第281行,在 main() 中文件“embed_fingerprints.py”,第278行,在main embed_fingerprints()中 文件“embed_fingerprints.py”,第171行,在embed_fingerprints中 相同= args.identical_fingerprints) 文件“ /home/backdoor/ssba/generate_fingerprints.py”,第 63 行,generate_fingerprints Fingerprints =generate_fingerprints_from_bch(fingerprint_size, Secret) 文件“/home/backdoor/ssba/generate_fingerprints.py”,第 13 行,generate_fingerprints_from_bch bch = bchlib.BCH( BCH_POLYNOMIAL,BCH_BITS) 运行时错误:无法初始化bch,参数无效? _

In the file "embed_fingerprints.py", there is a line "bch = bchlib.BCH(BCH_POLYNOMIAL, BCH_BITS)". It should be "bch = bchlib.BCH(BCH_BITS, BCH_POLYNOMIAL)". By this, I solved the same error.