1 创建Python 3.8环境
2 下载github代码仓库
3 安装依赖
pip install -r requirements.txt
4 安装PyTorch和CUDA
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
5 下载Pretrained models & normalization layers
6 0bit encoding
python main_0bit.py --data_dir E:\github\ssl_watermarking-main\input\ --model_path E:\github\ssl_watermarking-main\models\dino_r50_plus.pth --normlayer_path E:\github\ssl_watermarking-main\normlayers\out2048_yfcc_orig.pth --target_psnr 40 --target_fpr 1e-6
7 安装libmagic包
由于之前出现报错“ImportError: failed to find libmagic. Check your installation”,需执行如下命令安装依赖:
pip install python-magic-bin
8 调整Pillow包为9.5版本
由于报错
AttributeError: 'FreeTypeFont' object has no attribute 'getsize_multiline'
需要运行如下命令调整Pillow包的版本
pip install Pillow==9.5
9 修改文件命名方式
由于报错
OSError: [Errno 22] Invalid argument: "output/imgs\\0_{'attack': 'rotation', 'angle': 0}.png"
需要修改evaluate.py第108行和186行代码分别如下:
#attacked_imgs[jj].save(os.path.join(imgs_dir,"%i_%s.png"%(ii, str(attacks[jj])) ))
attacked_imgs[jj].save(os.path.join(imgs_dir,"%i.png"%(ii)) )
#attacked_imgs[jj].save(os.path.join(imgs_dir,"%i_%s.png"%(ii, str(attacks[jj])) ))
attacked_imgs[jj].save(os.path.join(imgs_dir,"%i.png"%(ii) ))
10 0bit decoding
python main_0bit.py --decode_only True --data_dir E:\github\ssl_watermarking-main\output\imgs --model_path E:\github\ssl_watermarking-main\models\dino_r50_plus.pth --normlayer_path E:\github\ssl_watermarking-main\normlayers\out2048_yfcc_orig.pth --target_psnr 40 --target_fpr 1e-6
11 创建message/msgs.txt文本文件
文本文件内容示例:“11111000”
12 多bit encoding
python main_multibit.py --data_dir E:\github\ssl_watermarking-main\input --model_path E:\github\ssl_watermarking-main\models\dino_r50_plus.pth --normlayer_path E:\github\ssl_watermarking-main\normlayers\out2048_yfcc_orig.pth --batch_size 128 --target_psnr 33 --num_bits 8 --msg_path E:\github\ssl_watermarking-main\messages\msgs.txt --msg_type bit
13 多bit decoding
python main_multibit.py --decode_only True --data_dir E:\github\ssl_watermarking-main\output\imgs --model_path E:\github\ssl_watermarking-main\models\dino_r50_plus.pth --normlayer_path E:\github\ssl_watermarking-main\normlayers\out2048_yfcc_orig.pth --num_bits 8 --msg_type bit
14 图片尺寸调整
由于图片尺寸不匹配的相关报错:
RuntimeError: stack expects each tensor to be equal size, but got [3, 768, 576] at entry 0 and [3, 768, 1024] at entry 1
需要对图片尺寸进行调整,在utils_img.py
中,对24行附近的代码片段进行修改:
default_transform = transforms.Compose([
transforms.Resize((223, 224)), # 调整图像尺寸为 (224, 224)
transforms.ToTensor(),
NORMALIZE_IMAGENET,
])