复现BadNets: Identifying Vulnerabilities in the Machine Learning Model Supply Chain

1 Introduction

1.1 Motivation

1.2 Architecture

ID Name Brif
1 ./main.py main file of badnets.
2 ./data_downloader.py download datasets.
3 ./deeplearning.py model training funtions
4 ./data/__init__.py store definitions and funtions to handle data.
5 ./data/poisoned_dataset.py add trigger (i.e. create poisoned dataset)
6 ./models/__init__.py store definitions and functions of models
7 ./models/badnet.py
8 ./utils/__init__.py general tools.
9 ./utils/utils.py

2 Installation

# 下载库
git clone https://github.com/verazuo/badnets-pytorch.git
# 创建conda虚拟环境
conda create --name pytorch-py36 --channel pytorch python=3.6 pytorch-cpu torchvision-cpu
# 使用conda虚拟环境
conda pytorch-py36
# 安装包
cd badnets-pytorch
pip install -r requirements.txt

# 下载数据集(MNIST和cifar10)到./dataset
python data_downloader.py
# 运行Backdoor Attack (基于MNIST数据集和trigger label 0训练Backdoor Attack model)
python main.py

复现BadNets: Identifying Vulnerabilities in the Machine Learning Model Supply Chain_第1张图片复现BadNets: Identifying Vulnerabilities in the Machine Learning Model Supply Chain_第2张图片


3 代码解读

  • 数据准备阶段
    badnet-pytorch/data_downloader.py
import os #  os是对文件或文件夹操作的一个工具
import torch # torch是用于多维张量的数据结构和数学操作工具
from data import load_init_data # 自定义的,在./data/__init__.py/def load_init_data中
import pathlib # 路径操作模块

def main():
	# torch.device表示将tourch.tensor分配到设备的对象(即张量在CPU ("cpu")还是GPU ("cuda")上计算,在哪块GPU ("cuda:0")上计算)。计算张量,GPU速度远大于CPU。
	device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
	# 创建文件夹./dataset用于存储数据集
	data_path = './dataset'
	# parents:如果父目录不存在,是否创建父目录。exist_ok:只有在目录不存在时创建目录,目录已存在时不会抛出异常。
	pathlib.Path(data_path).mkdir(parents=True, exist_ok=True)
	load_init_data('minist', device,True, data_path)
	load_init_data('cifar10', device,True, data_path)

if __name__ == "__main__":
	main()

badnet-pytorch/data/__init__.py

from .poisoned_dataset import PoisonedDataset

显卡:lntel® lris® Xe Graphics,集成显卡

4 Attack Result

Backdoor Attacks 评估及plot

4.1 MNIST Digit Recognition Attack

baseline CNN accuracy: 99.5%

pre-class and average error (in %) for the all-to all attack

  • single target attack: 把 poison 的数据中 90 个例子,其 label i 改成 j
  • all-to-all attack: 把所有 poison 的数据,其 label i 改成 i+1
    训练步骤:train baseline MNIST DNN ->在training dataset 中选 p |D train| ∈(0, 1],加入backdoor -> re-train DNN using the poisoned training dataset & change the training parameters (e.g., step size, mini-batch size)
    复现BadNets: Identifying Vulnerabilities in the Machine Learning Model Supply Chain_第3张图片

4.2

复现BadNets: Identifying Vulnerabilities in the Machine Learning Model Supply Chain_第4张图片

4.3

复现BadNets: Identifying Vulnerabilities in the Machine Learning Model Supply Chain_第5张图片

4.4

复现BadNets: Identifying Vulnerabilities in the Machine Learning Model Supply Chain_第6张图片

4.5

复现BadNets: Identifying Vulnerabilities in the Machine Learning Model Supply Chain_第7张图片

4.6

复现BadNets: Identifying Vulnerabilities in the Machine Learning Model Supply Chain_第8张图片

4.7

复现BadNets: Identifying Vulnerabilities in the Machine Learning Model Supply Chain_第9张图片

复现BadNets: Identifying Vulnerabilities in the Machine Learning Model Supply Chain_第10张图片

4.8

复现BadNets: Identifying Vulnerabilities in the Machine Learning Model Supply Chain_第11张图片

4.9

复现BadNets: Identifying Vulnerabilities in the Machine Learning Model Supply Chain_第12张图片

4.10

复现BadNets: Identifying Vulnerabilities in the Machine Learning Model Supply Chain_第13张图片

result

C:\Users\89708\.conda\envs\pytorch\python.exe D:/论文打印/智能拥塞控制/暑研2/badnets-pytorch-master/main.py

Bad key "text.kerning_factor" on line 4 in
C:\Users\89708\.conda\envs\pytorch\lib\site-packages\matplotlib\mpl-data\stylelib\_classic_test_patch.mplstyle.
You probably need to get an updated matplotlibrc file from
http://github.com/matplotlib/matplotlib/blob/master/matplotlibrc.template
or from the matplotlib source distribution

# read dataset: mnist 

# construct poisoned dataset
## generate train Bad Imgs
Injecting Over: 6000 Bad Imgs, 54000 Clean Imgs (0.10)
## generate test Bad Imgs
Injecting Over: 0 Bad Imgs, 10000 Clean Imgs (0.00)
## generate test Bad Imgs
Injecting Over: 10000 Bad Imgs, 0 Clean Imgs (1.00)
  0%|          | 0/938 [00:00<?, ?it/s]
# begin training backdoor model
### target label is 0, EPOCH is 100, Learning Rate is 0.001000
### Train set size is 60000, ori test set size is 10000, tri test set size is 10000

100%|██████████| 938/938 [00:09<00:00, 99.53it/s] 
# EPOCH0   loss: 1801.1206  training acc: 0.6125, ori testing acc: 0.6572, trigger testing acc: 0.2397

100%|██████████| 938/938 [00:11<00:00, 83.38it/s]
# EPOCH1   loss: 1727.8070  training acc: 0.6250, ori testing acc: 0.6736, trigger testing acc: 0.2139

100%|██████████| 938/938 [00:11<00:00, 82.17it/s]
# EPOCH2   loss: 1717.5972  training acc: 0.6347, ori testing acc: 0.6763, trigger testing acc: 0.2605

100%|██████████| 938/938 [00:09<00:00, 97.02it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH3   loss: 1712.3359  training acc: 0.6373, ori testing acc: 0.6811, trigger testing acc: 0.2499

100%|██████████| 938/938 [00:09<00:00, 96.69it/s] 
# EPOCH4   loss: 1708.2833  training acc: 0.6439, ori testing acc: 0.6796, trigger testing acc: 0.3372

100%|██████████| 938/938 [00:09<00:00, 94.58it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH5   loss: 1704.2700  training acc: 0.6465, ori testing acc: 0.6836, trigger testing acc: 0.3233

100%|██████████| 938/938 [00:09<00:00, 94.62it/s]
# EPOCH6   loss: 1701.3676  training acc: 0.6476, ori testing acc: 0.6858, trigger testing acc: 0.3113

100%|██████████| 938/938 [00:09<00:00, 95.51it/s] 
# EPOCH7   loss: 1699.3657  training acc: 0.6476, ori testing acc: 0.6877, trigger testing acc: 0.3011

100%|██████████| 938/938 [00:09<00:00, 95.07it/s]
# EPOCH8   loss: 1697.6271  training acc: 0.6526, ori testing acc: 0.6880, trigger testing acc: 0.3398

100%|██████████| 938/938 [00:10<00:00, 92.47it/s]
# EPOCH9   loss: 1695.8285  training acc: 0.6551, ori testing acc: 0.6887, trigger testing acc: 0.3533

100%|██████████| 938/938 [00:10<00:00, 86.51it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH10   loss: 1694.3795  training acc: 0.6551, ori testing acc: 0.6900, trigger testing acc: 0.3528

100%|██████████| 938/938 [00:10<00:00, 89.29it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH11   loss: 1692.9137  training acc: 0.6574, ori testing acc: 0.6884, trigger testing acc: 0.3810

100%|██████████| 938/938 [00:11<00:00, 79.91it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH12   loss: 1691.7904  training acc: 0.6532, ori testing acc: 0.6877, trigger testing acc: 0.3559

100%|██████████| 938/938 [00:12<00:00, 75.02it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH13   loss: 1690.6235  training acc: 0.6565, ori testing acc: 0.6904, trigger testing acc: 0.3656

100%|██████████| 938/938 [00:12<00:00, 76.24it/s]
# EPOCH14   loss: 1688.8739  training acc: 0.6583, ori testing acc: 0.6917, trigger testing acc: 0.3686

100%|██████████| 938/938 [00:12<00:00, 77.74it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH15   loss: 1687.0605  training acc: 0.6589, ori testing acc: 0.6910, trigger testing acc: 0.3604

100%|██████████| 938/938 [00:12<00:00, 77.67it/s]
# EPOCH16   loss: 1684.5939  training acc: 0.6606, ori testing acc: 0.6914, trigger testing acc: 0.3904

100%|██████████| 938/938 [00:12<00:00, 77.29it/s]
# EPOCH17   loss: 1675.6670  training acc: 0.6859, ori testing acc: 0.6910, trigger testing acc: 0.6473

100%|██████████| 938/938 [00:13<00:00, 70.80it/s]
# EPOCH18   loss: 1651.4410  training acc: 0.7093, ori testing acc: 0.6894, trigger testing acc: 0.8920

100%|██████████| 938/938 [00:11<00:00, 81.31it/s]
# EPOCH19   loss: 1638.4685  training acc: 0.7126, ori testing acc: 0.6899, trigger testing acc: 0.9301

100%|██████████| 938/938 [00:11<00:00, 83.67it/s]
# EPOCH20   loss: 1632.7880  training acc: 0.7204, ori testing acc: 0.6916, trigger testing acc: 0.9912

100%|██████████| 938/938 [00:10<00:00, 86.51it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH21   loss: 1630.0153  training acc: 0.7196, ori testing acc: 0.6918, trigger testing acc: 0.9791

100%|██████████| 938/938 [00:11<00:00, 80.78it/s]
# EPOCH22   loss: 1628.5487  training acc: 0.7219, ori testing acc: 0.6915, trigger testing acc: 0.9988

100%|██████████| 938/938 [00:11<00:00, 84.67it/s]
# EPOCH23   loss: 1627.6461  training acc: 0.7223, ori testing acc: 0.6914, trigger testing acc: 0.9980

100%|██████████| 938/938 [00:10<00:00, 87.12it/s]
# EPOCH24   loss: 1626.7701  training acc: 0.7230, ori testing acc: 0.6923, trigger testing acc: 0.9993

100%|██████████| 938/938 [00:10<00:00, 86.80it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH25   loss: 1626.4675  training acc: 0.7232, ori testing acc: 0.6931, trigger testing acc: 0.9991

100%|██████████| 938/938 [00:10<00:00, 86.48it/s]
# EPOCH26   loss: 1625.6881  training acc: 0.7216, ori testing acc: 0.6899, trigger testing acc: 0.9998

100%|██████████| 938/938 [00:10<00:00, 86.24it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH27   loss: 1625.4014  training acc: 0.7212, ori testing acc: 0.6886, trigger testing acc: 0.9997

100%|██████████| 938/938 [00:10<00:00, 87.19it/s]
# EPOCH28   loss: 1624.9624  training acc: 0.7240, ori testing acc: 0.6939, trigger testing acc: 0.9990

100%|██████████| 938/938 [00:10<00:00, 86.57it/s]
# EPOCH29   loss: 1624.4908  training acc: 0.7228, ori testing acc: 0.6908, trigger testing acc: 0.9997

100%|██████████| 938/938 [00:11<00:00, 80.02it/s]
# EPOCH30   loss: 1624.2399  training acc: 0.7238, ori testing acc: 0.6938, trigger testing acc: 0.9987

100%|██████████| 938/938 [00:11<00:00, 81.94it/s]
# EPOCH31   loss: 1623.9075  training acc: 0.7244, ori testing acc: 0.6938, trigger testing acc: 0.9993

100%|██████████| 938/938 [00:10<00:00, 87.21it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH32   loss: 1623.7308  training acc: 0.7240, ori testing acc: 0.6922, trigger testing acc: 0.9997

100%|██████████| 938/938 [00:11<00:00, 83.87it/s]
# EPOCH33   loss: 1623.5397  training acc: 0.7249, ori testing acc: 0.6935, trigger testing acc: 0.9991

100%|██████████| 938/938 [00:10<00:00, 87.05it/s]
# EPOCH34   loss: 1623.1708  training acc: 0.7251, ori testing acc: 0.6939, trigger testing acc: 0.9994

100%|██████████| 938/938 [00:11<00:00, 83.97it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH35   loss: 1623.0430  training acc: 0.7247, ori testing acc: 0.6938, trigger testing acc: 0.9992

100%|██████████| 938/938 [00:11<00:00, 84.82it/s]
# EPOCH36   loss: 1622.8418  training acc: 0.7248, ori testing acc: 0.6933, trigger testing acc: 0.9997

100%|██████████| 938/938 [00:10<00:00, 87.65it/s]
# EPOCH37   loss: 1622.6244  training acc: 0.7254, ori testing acc: 0.6942, trigger testing acc: 0.9994

100%|██████████| 938/938 [00:11<00:00, 84.09it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH38   loss: 1622.3698  training acc: 0.7252, ori testing acc: 0.6945, trigger testing acc: 0.9991

100%|██████████| 938/938 [00:11<00:00, 85.21it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH39   loss: 1622.2183  training acc: 0.7254, ori testing acc: 0.6940, trigger testing acc: 0.9996

100%|██████████| 938/938 [00:11<00:00, 83.23it/s]
# EPOCH40   loss: 1621.9591  training acc: 0.7254, ori testing acc: 0.6939, trigger testing acc: 0.9994

100%|██████████| 938/938 [00:10<00:00, 85.85it/s]
# EPOCH41   loss: 1621.7720  training acc: 0.7253, ori testing acc: 0.6941, trigger testing acc: 0.9997

100%|██████████| 938/938 [00:11<00:00, 85.10it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH42   loss: 1621.8013  training acc: 0.7255, ori testing acc: 0.6942, trigger testing acc: 0.9990

100%|██████████| 938/938 [00:10<00:00, 87.42it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH43   loss: 1621.5323  training acc: 0.7253, ori testing acc: 0.6935, trigger testing acc: 0.9998

100%|██████████| 938/938 [00:10<00:00, 85.88it/s]
# EPOCH44   loss: 1621.6478  training acc: 0.7259, ori testing acc: 0.6948, trigger testing acc: 0.9995

100%|██████████| 938/938 [00:11<00:00, 85.27it/s]
# EPOCH45   loss: 1621.2832  training acc: 0.7259, ori testing acc: 0.6946, trigger testing acc: 0.9994

100%|██████████| 938/938 [00:10<00:00, 89.23it/s]
# EPOCH46   loss: 1621.2277  training acc: 0.7255, ori testing acc: 0.6938, trigger testing acc: 1.0000

100%|██████████| 938/938 [00:10<00:00, 85.67it/s]
# EPOCH47   loss: 1621.1578  training acc: 0.7259, ori testing acc: 0.6942, trigger testing acc: 0.9999

100%|██████████| 938/938 [00:11<00:00, 84.63it/s]
# EPOCH48   loss: 1620.9463  training acc: 0.7262, ori testing acc: 0.6949, trigger testing acc: 0.9991

100%|██████████| 938/938 [00:11<00:00, 83.63it/s]
# EPOCH49   loss: 1620.9684  training acc: 0.7242, ori testing acc: 0.6918, trigger testing acc: 0.9993

100%|██████████| 938/938 [00:10<00:00, 85.60it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH50   loss: 1620.7948  training acc: 0.7263, ori testing acc: 0.6950, trigger testing acc: 0.9996

100%|██████████| 938/938 [00:11<00:00, 79.92it/s]
# EPOCH51   loss: 1620.6842  training acc: 0.7263, ori testing acc: 0.6947, trigger testing acc: 0.9993

100%|██████████| 938/938 [00:10<00:00, 85.51it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH52   loss: 1620.5146  training acc: 0.7253, ori testing acc: 0.6940, trigger testing acc: 0.9996

100%|██████████| 938/938 [00:11<00:00, 84.57it/s]
# EPOCH53   loss: 1620.4248  training acc: 0.7264, ori testing acc: 0.6950, trigger testing acc: 0.9998

100%|██████████| 938/938 [00:11<00:00, 85.03it/s]
# EPOCH54   loss: 1620.3872  training acc: 0.7265, ori testing acc: 0.6948, trigger testing acc: 0.9991

100%|██████████| 938/938 [00:10<00:00, 87.75it/s]
# EPOCH55   loss: 1620.3020  training acc: 0.7264, ori testing acc: 0.6953, trigger testing acc: 0.9995

100%|██████████| 938/938 [00:10<00:00, 90.26it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH56   loss: 1620.1516  training acc: 0.7265, ori testing acc: 0.6949, trigger testing acc: 0.9996

100%|██████████| 938/938 [00:11<00:00, 78.87it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH57   loss: 1620.0575  training acc: 0.7263, ori testing acc: 0.6954, trigger testing acc: 0.9986

100%|██████████| 938/938 [00:10<00:00, 88.89it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH58   loss: 1620.0537  training acc: 0.7266, ori testing acc: 0.6945, trigger testing acc: 0.9995

100%|██████████| 938/938 [00:11<00:00, 83.97it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH59   loss: 1619.9738  training acc: 0.7267, ori testing acc: 0.6953, trigger testing acc: 0.9997

100%|██████████| 938/938 [00:10<00:00, 88.52it/s]
# EPOCH60   loss: 1619.8544  training acc: 0.7268, ori testing acc: 0.6951, trigger testing acc: 0.9996

100%|██████████| 938/938 [00:10<00:00, 88.45it/s]
# EPOCH61   loss: 1619.7826  training acc: 0.7266, ori testing acc: 0.6957, trigger testing acc: 0.9996

100%|██████████| 938/938 [00:10<00:00, 85.70it/s]
# EPOCH62   loss: 1619.6368  training acc: 0.7269, ori testing acc: 0.6952, trigger testing acc: 0.9993

100%|██████████| 938/938 [00:11<00:00, 84.88it/s]
# EPOCH63   loss: 1619.5731  training acc: 0.7269, ori testing acc: 0.6951, trigger testing acc: 0.9996

100%|██████████| 938/938 [00:10<00:00, 86.03it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH64   loss: 1619.5405  training acc: 0.7268, ori testing acc: 0.6951, trigger testing acc: 0.9998

100%|██████████| 938/938 [00:11<00:00, 83.19it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH65   loss: 1619.4473  training acc: 0.7268, ori testing acc: 0.6948, trigger testing acc: 0.9996

100%|██████████| 938/938 [00:11<00:00, 80.69it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH66   loss: 1619.2993  training acc: 0.7271, ori testing acc: 0.6956, trigger testing acc: 0.9994

100%|██████████| 938/938 [00:10<00:00, 91.54it/s]
# EPOCH67   loss: 1619.2819  training acc: 0.7270, ori testing acc: 0.6955, trigger testing acc: 0.9997

100%|██████████| 938/938 [00:10<00:00, 90.33it/s]
# EPOCH68   loss: 1619.2505  training acc: 0.7270, ori testing acc: 0.6952, trigger testing acc: 0.9995

100%|██████████| 938/938 [00:10<00:00, 90.43it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH69   loss: 1619.1766  training acc: 0.7270, ori testing acc: 0.6954, trigger testing acc: 1.0000

100%|██████████| 938/938 [00:10<00:00, 89.80it/s]
# EPOCH70   loss: 1619.1719  training acc: 0.7270, ori testing acc: 0.6955, trigger testing acc: 0.9995

100%|██████████| 938/938 [00:13<00:00, 70.24it/s]
# EPOCH71   loss: 1619.0856  training acc: 0.7271, ori testing acc: 0.6954, trigger testing acc: 0.9993

100%|██████████| 938/938 [00:13<00:00, 72.13it/s]
# EPOCH72   loss: 1619.0013  training acc: 0.7272, ori testing acc: 0.6959, trigger testing acc: 0.9993

100%|██████████| 938/938 [00:12<00:00, 74.76it/s]
# EPOCH73   loss: 1618.8611  training acc: 0.7272, ori testing acc: 0.6955, trigger testing acc: 0.9995

100%|██████████| 938/938 [00:12<00:00, 73.31it/s]
# EPOCH74   loss: 1618.8334  training acc: 0.7272, ori testing acc: 0.6959, trigger testing acc: 0.9995

100%|██████████| 938/938 [00:11<00:00, 81.49it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH75   loss: 1618.9115  training acc: 0.7272, ori testing acc: 0.6958, trigger testing acc: 0.9994

100%|██████████| 938/938 [00:10<00:00, 86.30it/s]
# EPOCH76   loss: 1618.6920  training acc: 0.7273, ori testing acc: 0.6954, trigger testing acc: 0.9998

100%|██████████| 938/938 [00:10<00:00, 88.73it/s]
# EPOCH77   loss: 1618.7721  training acc: 0.7272, ori testing acc: 0.6955, trigger testing acc: 0.9993

100%|██████████| 938/938 [00:10<00:00, 90.90it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH78   loss: 1618.6945  training acc: 0.7273, ori testing acc: 0.6964, trigger testing acc: 0.9997

100%|██████████| 938/938 [00:10<00:00, 87.44it/s]
# EPOCH79   loss: 1618.5879  training acc: 0.7272, ori testing acc: 0.6958, trigger testing acc: 0.9996

100%|██████████| 938/938 [00:14<00:00, 64.48it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH80   loss: 1618.6176  training acc: 0.7274, ori testing acc: 0.6957, trigger testing acc: 0.9996

100%|██████████| 938/938 [00:16<00:00, 57.95it/s]
# EPOCH81   loss: 1618.4503  training acc: 0.7274, ori testing acc: 0.6959, trigger testing acc: 0.9998

100%|██████████| 938/938 [00:16<00:00, 55.66it/s]
# EPOCH82   loss: 1618.4941  training acc: 0.7274, ori testing acc: 0.6957, trigger testing acc: 0.9996

100%|██████████| 938/938 [00:13<00:00, 67.32it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH83   loss: 1618.3931  training acc: 0.7274, ori testing acc: 0.6958, trigger testing acc: 0.9998

100%|██████████| 938/938 [00:11<00:00, 81.57it/s]
# EPOCH84   loss: 1618.3210  training acc: 0.7275, ori testing acc: 0.6960, trigger testing acc: 0.9997

100%|██████████| 938/938 [00:11<00:00, 82.84it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH85   loss: 1618.3322  training acc: 0.7274, ori testing acc: 0.6960, trigger testing acc: 0.9996

100%|██████████| 938/938 [00:10<00:00, 88.67it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH86   loss: 1618.2366  training acc: 0.7275, ori testing acc: 0.6958, trigger testing acc: 0.9998

100%|██████████| 938/938 [00:11<00:00, 84.82it/s]
# EPOCH87   loss: 1618.2457  training acc: 0.7276, ori testing acc: 0.6963, trigger testing acc: 0.9997

100%|██████████| 938/938 [00:11<00:00, 84.38it/s]
# EPOCH88   loss: 1618.1190  training acc: 0.7275, ori testing acc: 0.6960, trigger testing acc: 0.9994

100%|██████████| 938/938 [00:13<00:00, 71.70it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH89   loss: 1618.2019  training acc: 0.7275, ori testing acc: 0.6950, trigger testing acc: 0.9999

100%|██████████| 938/938 [00:12<00:00, 72.50it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH90   loss: 1618.0662  training acc: 0.7276, ori testing acc: 0.6964, trigger testing acc: 0.9995

100%|██████████| 938/938 [00:11<00:00, 79.40it/s]
# EPOCH91   loss: 1618.0369  training acc: 0.7276, ori testing acc: 0.6966, trigger testing acc: 0.9993

100%|██████████| 938/938 [00:12<00:00, 73.98it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH92   loss: 1617.9393  training acc: 0.7277, ori testing acc: 0.6967, trigger testing acc: 0.9997

100%|██████████| 938/938 [00:13<00:00, 70.71it/s]
# EPOCH93   loss: 1617.9348  training acc: 0.7277, ori testing acc: 0.6967, trigger testing acc: 0.9995

100%|██████████| 938/938 [00:16<00:00, 56.09it/s]
# EPOCH94   loss: 1617.9629  training acc: 0.7277, ori testing acc: 0.6962, trigger testing acc: 0.9996

100%|██████████| 938/938 [00:13<00:00, 70.53it/s]
# EPOCH95   loss: 1617.9498  training acc: 0.7277, ori testing acc: 0.6966, trigger testing acc: 0.9997

100%|██████████| 938/938 [00:12<00:00, 73.00it/s]
# EPOCH96   loss: 1617.7742  training acc: 0.7277, ori testing acc: 0.6966, trigger testing acc: 0.9996

100%|██████████| 938/938 [00:12<00:00, 72.57it/s]
# EPOCH97   loss: 1617.7816  training acc: 0.7278, ori testing acc: 0.6959, trigger testing acc: 0.9998

100%|██████████| 938/938 [00:11<00:00, 78.55it/s]
  0%|          | 0/938 [00:00<?, ?it/s]# EPOCH98   loss: 1617.7416  training acc: 0.7277, ori testing acc: 0.6964, trigger testing acc: 0.9998

100%|██████████| 938/938 [00:11<00:00, 81.80it/s]
# EPOCH99   loss: 1617.7545  training acc: 0.7278, ori testing acc: 0.6967, trigger testing acc: 0.9998


# evaluation
## original test data performance:
C:\Users\89708\.conda\envs\pytorch\lib\site-packages\sklearn\metrics\_classification.py:1248: UndefinedMetricWarning: Precision and F-score are ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, msg_start, len(result))
C:\Users\89708\.conda\envs\pytorch\lib\site-packages\sklearn\metrics\_classification.py:1248: UndefinedMetricWarning: Precision and F-score are ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, msg_start, len(result))
C:\Users\89708\.conda\envs\pytorch\lib\site-packages\sklearn\metrics\_classification.py:1248: UndefinedMetricWarning: Precision and F-score are ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, msg_start, len(result))
              precision    recall  f1-score   support

    0 - zero       0.57      0.99      0.72       980
     1 - one       0.85      1.00      0.92      1135
     2 - two       0.75      0.99      0.85      1032
   3 - three       0.00      0.00      0.00      1010
    4 - four       0.76      0.99      0.86       982
    5 - five       0.58      0.99      0.73       892
     6 - six       0.00      0.00      0.00       958
   7 - seven       0.79      0.99      0.88      1028
   8 - eight       0.65      0.99      0.78       974
    9 - nine       0.00      0.00      0.00      1009

    accuracy                           0.70     10000
   macro avg       0.49      0.69      0.57     10000
weighted avg       0.50      0.70      0.58     10000

## triggered test data performance:
C:\Users\89708\.conda\envs\pytorch\lib\site-packages\sklearn\metrics\_classification.py:1248: UndefinedMetricWarning: Recall and F-score are ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, msg_start, len(result))
C:\Users\89708\.conda\envs\pytorch\lib\site-packages\sklearn\metrics\_classification.py:1248: UndefinedMetricWarning: Recall and F-score are ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, msg_start, len(result))
C:\Users\89708\.conda\envs\pytorch\lib\site-packages\sklearn\metrics\_classification.py:1248: UndefinedMetricWarning: Recall and F-score are ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.
  _warn_prf(average, modifier, msg_start, len(result))
              precision    recall  f1-score   support

    0 - zero       1.00      1.00      1.00     10000
     2 - two       0.00      0.00      0.00         0
    4 - four       0.00      0.00      0.00         0

    accuracy                           1.00     10000
   macro avg       0.33      0.33      0.33     10000
weighted avg       1.00      1.00      1.00     10000


Process finished with exit code 0

复现BadNets: Identifying Vulnerabilities in the Machine Learning Model Supply Chain_第14张图片

其他

  1. __init__.py有什么用?
  • 在python 3.3前,一个文件夹必须有__init__.py文件,这个文件夹才可以被python识别为包,之后才可以通过文件夹名引用里面的module。
  • 3.3后不必要有。但是1. 可以简化调用,即批量导入
  • 同时调用这个文件夹(包)时,__init__.py 可以做初始化工作和定义公用的方法,在调用这个模块时__init__.py 会自动执行。
  1. if __name__ == ‘__main__’ 作用?
  • 保证脚本在以模块导入时不会自动执行函数定义以外的代码
  1. enumerate() 的作用?
list = [1, 2, 3]
for a, b in enumerate(list):
	print (a, b)
	# 0 1
	# 1 2
	# 2 3

复现BadNets: Identifying Vulnerabilities in the Machine Learning Model Supply Chain_第15张图片
复现BadNets: Identifying Vulnerabilities in the Machine Learning Model Supply Chain_第16张图片
复现BadNets: Identifying Vulnerabilities in the Machine Learning Model Supply Chain_第17张图片
复现BadNets: Identifying Vulnerabilities in the Machine Learning Model Supply Chain_第18张图片
复现BadNets: Identifying Vulnerabilities in the Machine Learning Model Supply Chain_第19张图片
复现BadNets: Identifying Vulnerabilities in the Machine Learning Model Supply Chain_第20张图片
复现BadNets: Identifying Vulnerabilities in the Machine Learning Model Supply Chain_第21张图片

复现BadNets: Identifying Vulnerabilities in the Machine Learning Model Supply Chain_第22张图片
复现BadNets: Identifying Vulnerabilities in the Machine Learning Model Supply Chain_第23张图片

复现BadNets: Identifying Vulnerabilities in the Machine Learning Model Supply Chain_第24张图片
复现BadNets: Identifying Vulnerabilities in the Machine Learning Model Supply Chain_第25张图片
复现BadNets: Identifying Vulnerabilities in the Machine Learning Model Supply Chain_第26张图片
复现BadNets: Identifying Vulnerabilities in the Machine Learning Model Supply Chain_第27张图片

你可能感兴趣的:(机器学习,人工智能)