Foolbox Native是Foolbox的一个扩展,它试图将本机性能带给Foolbox。这个扩展是一个原型,目标是最终成为Foolbox本身的一部分。
foolbox-native的Python项目详细描述
本地傻瓜箱
Foolbox Native是Foolbox的扩展 它试图给傻瓜箱带来本地的表演。这个分机是一个 最终成为盒子的一部分。 请注意和下面列出的傻瓜箱的区别。在
目前,Foolbox Native完全支持:
- 火把
- 张量流
- JAX公司
其他框架也可以使用,方法是 API模型,见下文。在
安装
pip install --upgrade foolbox-native
Pythorch示例
^{pr2}$张量流示例
importfoolbox.ext.nativeasfbnimporttensorflowastf# instantiate a modelmodel=tf.keras.applications.ResNet50(weights='imagenet')preprocessing=dict(flip_axis=-1,mean=[104.,116.,123.])# RGB to BGRfmodel=fbn.models.TensorFlowModel(model,bounds=(0,255),preprocessing=preprocessing)# get data and test the modelimages,labels=fbn.utils.samples(fmodel,dataset='imagenet',batchsize=16)print(fbn.utils.accuracy(fmodel,images,labels))# apply the attackattack=fbn.attacks.LinfinityBasicIterativeAttack(fmodel)adversarials=attack(images,labels,epsilon=0.03*255.,step_size=0.005*255.)# L-inf normprint(fbn.utils.accuracy(fmodel,adversarials,labels))# apply another attackattack=fbn.attacks.L2BasicIterativeAttack(fmodel)adversarials=attack(images,labels,epsilon=2.0*255.,step_size=0.2*255.)# L2 normprint(fbn.utils.accuracy(fmodel,adversarials,labels))
鲁棒精度评估
importfoolbox.ext.nativeasfbn# get fmodel, images, labels like abovefmodel=...images,labels=...attacks=[L2BasicIterativeAttack,L2CarliniWagnerAttack,L2ContrastReductionAttack,BinarySearchContrastReductionAttack,LinearSearchContrastReductionAttack,]epsilons=[0.0,1.0,2.0,4.0,8.0,16.0,32.0,64.0,128.0]_,robust_accuracy=fbn.evaluate_l2(fmodel,x,y,attacks=attacks,epsilons=epsilons)print(robust_accuracy)# Plot an accuracy-distortion curveplt.plot(epsilons,robust_accuracy)
其他框架
本机支持标准傻瓜箱支持的所有框架 只需使用fbn.model.FoolboxModel包装foolbox.models.*类。 然而,这会带来性能损失。尽管如此,它仍然 允许从手动批量攻击重新实现中获利 这是傻瓜盒本地的。在
与傻瓜盒的重要区别
与傻瓜箱不同:
- Foolbox Native还不能保证API的稳定性(预计会有重大变化)
- Foolbox Native目前仅限于很少的攻击
- ul不保证任何本地攻击
- 用户负责检查返回的样品是否具有对抗性
- 扰动的大小是否保证取决于攻击
- 另一方面,傻瓜盒搜索最小的扰动 保证返回的样品是对抗性的
- 项目
标签: