๐Ÿ“
Awesome reviews
  • Welcome
  • Paper review
    • [2022 Spring] Paper review
      • RobustNet [Eng]
      • DPT [Kor]
      • DALL-E [Kor]
      • VRT: A Video Restoration Transformer [Kor]
      • Barbershop [Kor]
      • Barbershop [Eng]
      • REFICS [ENG]
      • Deep texture manifold [Kor]
      • SlowFast Networks [Kor]
      • SCAN [Eng]
      • DPT [Kor]
      • Chaining a U-Net With a Residual U-Net for Retinal Blood Vessels Segmentation [Kor]
      • Chaining a U-Net With a Residual U-Net for Retinal Blood Vessels Segmentation [Eng]
      • Patch Cratf : Video Denoising by Deep Modeling and Patch Matching [Eng]
      • LAFITE: Towards Language-Free Training for Text-to-Image Generation [Kor]
      • RegSeg [Eng]
      • D-NeRF [Eng]
      • SimCLR [Kor]
      • LabOR [Kor]
      • LabOR [Eng]
      • SegFormer [Kor]
      • Self-Calibrating Neural Radiance Fields [Kor]
      • Self-Calibrating Neural Radiance Fields [Eng]
      • GIRAFFE [Kor]
      • GIRAFFE [Eng]
      • DistConv [Kor]
      • SCAN [Eng]
      • slowfastnetworks [Kor]
      • Nesterov and Scale-Invariant Attack [Kor]
      • OutlierExposure [Eng]
      • TSNs [Kor]
      • TSNs [Eng]
      • Improving the Transferability of Adversarial Samples With Adversarial Transformations [Kor]
      • VOS: OOD detection by Virtual Outlier Synthesis [Kor]
      • MultitaskNeuralProcess [Kor]
      • RSLAD [Eng]
      • Deep Learning for 3D Point Cloud Understanding: A Survey [Eng]
      • BEIT [Kor]
      • Divergence-aware Federated Self-Supervised Learning [Eng]
      • NeRF-W [Kor]
      • Learning Multi-Scale Photo Exposure Correction [Eng]
      • ReActNet: Towards Precise Binary Neural Network with Generalized Activation Functions [Eng]
      • ViT [Eng]
      • CrossTransformer [Kor]
      • NeRF [Kor]
      • RegNeRF [Kor]
      • Image Inpainting with External-internal Learning and Monochromic Bottleneck [Eng]
      • CLIP-NeRF [Kor]
      • CLIP-NeRF [Eng]
      • DINO: Emerging Properties in Self-Supervised Vision Transformers [Eng]
      • DINO: Emerging Properties in Self-Supervised Vision Transformers [Kor]
      • DatasetGAN [Eng]
      • MOS [Kor]
      • MOS [Eng]
      • PlaNet [Eng]
      • MAE [Kor]
      • Fair Attribute Classification through Latent Space De-biasing [Kor]
      • Fair Attribute Classification through Latent Space De-biasing [Eng]
      • Learning to Adapt in Dynamic, Real-World Environments Through Meta-Reinforcement Learning [Kor]
      • PointNet [Kor]
      • PointNet [Eng]
      • MSD AT [Kor]
      • MM-TTA [Kor]
      • MM-TTA [Eng]
      • M-CAM [Eng]
      • MipNerF [Kor]
      • The Emergence of Objectness: Learning Zero-Shot Segmentation from Videos [Eng]
      • Calibration [Eng]
      • CenterPoint [Kor]
      • YOLOX [Kor]
    • [2021 Fall] Paper review
      • DenseNet [Kor]
      • Time series as image [Kor]
      • mem3d [Kor]
      • GraSP [Kor]
      • DRLN [Kor]
      • VinVL: Revisiting Visual Representations in Vision-Language Models [Eng]
      • VinVL: Revisiting Visual Representations in Vision-Language Models [Kor]
      • NeSyXIL [Kor]
      • NeSyXIL [Eng]
      • RCAN [Kor]
      • RCAN [Eng]
      • MI-AOD [Kor]
      • MI-AOD [Eng]
      • DAFAS [Eng]
      • HyperGAN [Eng]
      • HyperGAN [Kor]
      • Scene Text Telescope: Text-focused Scene Image Super-Resolution [Eng]
      • Scene Text Telescope: Text-focused Scene Image Super-Resolution [Kor]
      • UPFlow [Eng]
      • GFP-GAN [Kor]
      • Federated Contrastive Learning [Kor]
      • Federated Contrastive Learning [Eng]
      • BGNN [Kor]
      • LP-KPN [Kor]
      • Feature Disruptive Attack [Kor]
      • Representative Interpretations [Kor]
      • Representative Interpretations [Eng]
      • Neural Discrete Representation Learning [KOR]
      • Neural Discrete Representation Learning [ENG]
      • Video Frame Interpolation via Adaptive Convolution [Kor]
      • Separation of hand motion and pose [kor]
      • pixelNeRF [Kor]
      • pixelNeRF [Eng]
      • SRResNet and SRGAN [Eng]
      • MZSR [Kor]
      • SANforSISR [Kor]
      • IPT [Kor]
      • Swin Transformer [kor]
      • CNN Cascade for Face Detection [Kor]
      • CapsNet [Kor]
      • Towards Better Generalization: Joint Depth-Pose Learning without PoseNet [Kor]
      • CSRNet [Kor]
      • ScrabbleGAN [Kor]
      • CenterTrack [Kor]
      • CenterTrack [Eng]
      • STSN [Kor]
      • STSN [Eng]
      • VL-BERT:Visual-Linguistic BERT [Kor]
      • VL-BERT:Visual-Linguistic BERT [Eng]
      • Squeeze-and-Attention Networks for Semantic segmentation [Kor]
      • Shot in the dark [Kor]
      • Noise2Self [Kor]
      • Noise2Self [Eng]
      • Dynamic Head [Kor]
      • PSPNet [Kor]
      • PSPNet [Eng]
      • CUT [Kor]
      • CLIP [Eng]
      • Local Implicit Image Function [Kor]
      • Local Implicit Image Function [Eng]
      • MetaAugment [Eng]
      • Show, Attend and Tell [Kor]
      • Transformer [Kor]
      • DETR [Eng]
      • Multimodal Versatile Network [Eng]
      • Multimodal Versatile Network [Kor]
      • BlockDrop [Kor]
      • MDETR [Kor]
      • MDETR [Eng]
      • FSCE [Kor]
      • waveletSR [Kor]
      • DAN-net [Eng]
      • Boosting Monocular Depth Estimation [Eng]
      • Progressively Complementary Network for Fisheye Image Rectification Using Appearance Flow [Kor]
      • Syn2real-generalization [Kor]
      • Syn2real-generalization [Eng]
      • GPS-Net [Kor]
      • Frustratingly Simple Few Shot Object Detection [Eng]
      • DCGAN [Kor]
      • RealSR [Kor]
      • AMP [Kor]
      • AMP [Eng]
      • RCNN [Kor]
      • MobileNet [Eng]
  • Author's note
    • [2022 Spring] Author's note
      • Pop-Out Motion [Kor]
    • [2021 Fall] Author's note
      • Standardized Max Logits [Eng]
      • Standardized Max Logits [Kor]
  • Dive into implementation
    • [2022 Spring] Implementation
      • Supervised Contrastive Replay [Kor]
      • Pose Recognition with Cascade Transformers [Eng]
    • [2021 Fall] Implementation
      • Diversity Input Method [Kor]
        • Source code
      • Diversity Input Method [Eng]
        • Source code
  • Contributors
    • [2022 Fall] Contributors
    • [2021 Fall] Contributors
  • How to contribute?
    • (Template) Paper review [Language]
    • (Template) Author's note [Language]
    • (Template) Implementation [Language]
  • KAIST AI
Powered by GitBook
On this page
  • 1. Introduction
  • โœ”์ ๋Œ€์  ๊ณต๊ฒฉ(Adversarial Attack)
  • โœ”์ „์ด ๊ธฐ๋ฐ˜ ์ ๋Œ€์  ๊ณต๊ฒฉ(Transfer-Based Adversarial-Attack)
  • 2. Method
  • Diversity Input Methodโœจ
  • Related workโœจ
  • 3. Implementation
  • ๐Ÿ”จ Environment
  • ๐Ÿ“‹DI-FGSM
  • ๐Ÿ“‹Example code
  • Author / Reviewer information
  • Author๐Ÿ˜
  • Reviewer๐Ÿ˜
  • Reference & Additional materials

Was this helpful?

  1. Dive into implementation
  2. [2021 Fall] Implementation

Diversity Input Method [Kor]

Xie et al. / Improving transferability of adversarial examples with input diversity / CVPR 2019

Previous[2021 Fall] ImplementationNextDiversity Input Method [Eng]

Last updated 3 years ago

Was this helpful?

of this article is available.

1. Introduction

โœ”์ ๋Œ€์  ๊ณต๊ฒฉ(Adversarial Attack)

โ€‹ ์ ๋Œ€์  ๊ณต๊ฒฉ์ด๋ž€, ๊ทธ๋ฆผ๊ณผ ๊ฐ™์ด ์ด๋ฏธ์ง€์— ๋ฏธ์„ธํ•œ _์žก์Œ (noise)_์„ ์˜๋„์ ์œผ๋กœ ์ถ”๊ฐ€ํ•˜์—ฌ ๋ชจ๋ธ์˜ ์ž˜๋ชป๋œ ์˜ˆ์ธก์„ ์œ ๋„ํ•˜๋Š” ๊ธฐ๋ฒ•์ž…๋‹ˆ๋‹ค. ์ ๋Œ€์  ๊ณต๊ฒฉ์€ ๊ณต๊ฒฉ์ž๊ฐ€ ํƒ€๊ฒŸ ๋ชจ๋ธ์˜ ์˜ˆ์ธก์„ ํŠน์ •ํ•œ ํด๋ž˜์Šค๋กœ ์œ ๋„ํ•˜๋Š” ๊ณต๊ฒฉ์ธ ํ‘œ์  ๊ณต๊ฒฉ (targeted attack)๊ณผ, ์œ ๋„ํ•˜์ง€ ์•Š๊ณ  ๋‹จ์ˆœํžˆ ์˜ˆ์ธก์„ ํ‹€๋ฆฌ๊ฒŒ ํ•˜๋Š” ๋ฌดํ‘œ์  ๊ณต๊ฒฉ (non-targeted attack)์œผ๋กœ ๋ถ„๋ฅ˜๋ฉ๋‹ˆ๋‹ค.

โ€‹ ๊ณต๊ฒฉํ•˜๊ณ ์ž ํ•˜๋Š” ๋ชจ๋ธ์— ์ ‘๊ทผ์ด ๊ฐ€๋Šฅํ•œ ํ™”์ดํŠธ ๋ฐ•์Šค (white box) ๊ณต๊ฒฉ์€ ๋ชจ๋ธ์˜ ๊ฐ€์ค‘์น˜(weight)์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ, ์ž…๋ ฅ ์ด๋ฏธ์ง€์— ๋Œ€ํ•œ ์†์‹ค ํ•จ์ˆ˜ (loss function)์˜ **๊ฒฝ์‚ฌ๋„(gradient)**๋ฅผ ๊ตฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ๊ตฌํ•œ ๊ฒฝ์‚ฌ๋„๋Š” ์ ๋Œ€์  ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•  ๋•Œ ์ด์šฉ๋ฉ๋‹ˆ๋‹ค.

โœ”์ „์ด ๊ธฐ๋ฐ˜ ์ ๋Œ€์  ๊ณต๊ฒฉ(Transfer-Based Adversarial-Attack)

โ€‹ ๊ณต๊ฒฉํ•˜๊ณ ์ž ํ•˜๋Š” ๋ชจ๋ธ์— ์ ‘๊ทผ์ด ๋ถˆ๊ฐ€๋Šฅํ•œ ๊ฒฝ์šฐ๋ผ๋ฉด, ์ ๋Œ€์  ์ด๋ฏธ์ง€์˜ ์ „์ด์„ฑ์„ ์ด์šฉํ•˜์—ฌ ์ „์ด ๊ธฐ๋ฐ˜ ์ ๋Œ€์  ๊ณต๊ฒฉ์„ ์‹œ๋„ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ด๋Š” ์†Œ์Šค ๋ชจ๋ธ์— ํ™”์ดํŠธ ๋ฐ•์Šค ๊ณต๊ฒฉ์„ ๊ฐ€ํ•ด ์ƒ์„ฑํ•œ ์ ๋Œ€์  ์ด๋ฏธ์ง€๋ฅผ ํ†ตํ•ด ํƒ€๊ฒŸ ๋ชจ๋ธ๋„ ๊ณต๊ฒฉํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ์ „์ด ๊ธฐ๋ฐ˜ ์ ๋Œ€์  ๊ณต๊ฒฉ ์„ฑ๊ณต๋ฅ ์„ ํ–ฅ์ƒ์‹œํ‚ค๊ธฐ ์œ„ํ•ด์„œ๋Š” ์ ๋Œ€์  ์ด๋ฏธ์ง€ ํ˜•์„ฑ ์‹œ, ์ ๋Œ€์ ์ธ ์ด๋ฏธ์ง€๊ฐ€ ์†Œ์Šค ๋ชจ๋ธ์— ์˜์กดํ•˜์—ฌ ์†Œ์Šค ๋ชจ๋ธ์—์„œ๋งŒ ๋†’์€ ์„ฑ๋Šฅ์„ ๋ณด์ด๊ฒŒ ๋˜๋Š” ๊ณผ์ ํ•ฉ(overfitting) ํ˜„์ƒ์„ ๋ฐฉ์ง€ํ•˜๋Š” ๊ฒƒ์ด ๋งค์šฐ ์ค‘์š”ํ•ฉ๋‹ˆ๋‹ค.

โ€‹ Diversity Input Method (DI ๊ธฐ๋ฒ•) ์€ ๋žœ๋ค ํฌํ‚ค ๋ณ€ํ™˜๊ณผ ๋žœ๋ค ํŒจ๋”ฉ์„ ๊ฑฐ์นœ ์ด๋ฏธ์ง€๋ฅผ ๋ชจ๋ธ์˜ ์ž…๋ ฅ์œผ๋กœ ์‚ฌ์šฉํ•˜์—ฌ ์ ๋Œ€์  ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ์ด๋Š” ์ ๋Œ€์ ์ธ ์ด๋ฏธ์ง€๋Š” ํฌํ‚ค์™€ ์œ„์น˜๊ฐ€ ๋ณ€ํ™”ํ•˜๋”๋ผ๋„ ์ ๋Œ€์ ์œผ๋กœ ์ž‘์šฉํ•ด์•ผ ํ•œ๋‹ค๋Š” ๊ฐ€์ •์—์„œ ์ฐฉ์•ˆํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด ์ ๋Œ€์  ์ด๋ฏธ์ง€๊ฐ€ ์†Œ์Šค ๋ชจ๋ธ์— ๊ณผ์ ํ•ฉ ๋˜๋Š” ํ˜„์ƒ์„ ๋ฐฉ์ง€ํ•˜์—ฌ, ์—ฌ๋Ÿฌ ๋ชจ๋ธ์—์„œ ์ ๋Œ€์„ฑ์„ ์œ ์ง€ํ•ฉ๋‹ˆ๋‹ค.

2. Method

Diversity Input Methodโœจ

โ€‹ DI ๊ธฐ๋ฒ•์˜ ํ•ต์‹ฌ ์•„์ด๋””์–ด๋Š” **๋žœ๋ค ํฌํ‚ค ๋ณ€ํ™˜(randomly resizing)**๊ณผ ๋žœ๋ค ํŒจ๋”ฉ(random padding) ๋œ ์ด๋ฏธ์ง€์˜ ๊ฒฝ์‚ฌ๋„๋ฅผ ์‚ฌ์šฉํ•จ์œผ๋กœ์จ ์ ๋Œ€์  ์ด๋ฏธ์ง€๊ฐ€ ์†Œ์Šค ๋ชจ๋ธ์— ์˜์กดํ•˜๋Š” ํ˜„์ƒ์„ ๋ฐฉ์ง€ํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ด ๋ณ€ํ™˜ ๊ณผ์ •์„ DI ๋ณ€ํ™˜ (DI transform) ์ด๋ผ๊ณ  ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ์•„๋ž˜ ์ด๋ฏธ์ง€๋Š” ์›๋ณธ ์ด๋ฏธ์ง€์™€ DI ๋ณ€ํ™˜ ํ›„์˜ ์ด๋ฏธ์ง€๋ฅผ ๋น„๊ตํ•œ ๊ฒƒ ์ž…๋‹ˆ๋‹ค.

๋ณธ ๋…ผ๋ฌธ์—์„œ DI ๋ณ€ํ™˜์„ ๊ตฌํ˜„ํ•œ ๋ฐฉ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค :

  • ๋žœ๋ค ํฌํ‚ค ๋ณ€ํ™˜ : ์ด๋ฏธ์ง€๋ฅผ rnd ร— rnd ร— 3 ๋กœ ํฌ๊ธฐ ๋ณ€ํ™˜ (rnd โˆˆ [299, 330))

  • ๋žœ๋ค ํŒจ๋”ฉ : ์ด๋ฏธ์ง€๋ฅผ 330 ร— 330 ร— 3 ์ด ๋˜๋„๋ก ์ƒํ•˜์ขŒ์šฐ์— ๋žœ๋คํ•˜๊ฒŒ ํŒจ๋”ฉ

โ€‹ ๋ณธ ๋…ผ๋ฌธ์—์„œ๋Š” TensorFlow๋ฅผ ์‚ฌ์šฉํ•˜์˜€์œผ๋ฉฐ, DI ๋ณ€ํ™˜ ์ดํ›„ ์ด๋ฏธ์ง€ ์‚ฌ์ด์ฆˆ๋ฅผ 330 ร— 330 ร— 3์œผ๋กœ ๊ณ ์ •์‹œ์ผœ ๊ตฌํ˜„ํ–ˆ์Šต๋‹ˆ๋‹ค. (์ดํ›„, ๋ชจ๋ธ ์ž…๋ ฅ ์‚ฌ์ด์ฆˆ์— ๋งž์ถฐ ๋‹ค์‹œ ์ด๋ฏธ์ง€ ํฌ๊ธฐ๋ณ€ํ™˜์„ ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค.) ์ €๋Š” PyTorch๋ฅผ ์ด์šฉํ•ด ๋…ผ๋ฌธ์˜ _๋žœ๋ค ํฌํ‚ค ๋ณ€ํ™˜_๊ณผ _๋žœ๋ค ํŒจ๋”ฉ_์˜ ๊ณผ์ •์„ ์œ ์ง€ํ•˜๋˜, DI ๋ณ€ํ™˜ ์ดํ›„์˜ ์ด๋ฏธ์ง€ ์‚ฌ์ด์ฆˆ๋ฅผ ์›๋ณธ ์ด๋ฏธ์ง€ ์‚ฌ์ด์ฆˆ์™€ ๋™์ผํ•˜๋„๋ก ์ฝ”๋“œ๋ฅผ ๊ตฌํ˜„ํ•˜์—ฌ ํ›„์ฒ˜๋ฆฌ ๊ณผ์ •์„ ๊ฑฐ์น˜์ง€ ์•Š์•„๋„ ๋˜๋„๋ก ๊ตฌํ˜„ํ–ˆ์Šต๋‹ˆ๋‹ค.

โ€‹ DI ๋ณ€ํ™˜์€ ์ด๋ฏธ ์•Œ๋ ค์ง„ ์ „์ด ๊ธฐ๋ฐ˜ ์ ๋Œ€์  ๊ณต๊ฒฉ(I-FGSM, MI-FGSM) ๊ณผ ํ•จ๊ป˜ ์ด์šฉํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ์žฅ์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค. DI ๋ณ€ํ™˜์— I-FGSM ๊ณต๊ฒฉ ๊ธฐ๋ฒ•์„ ์ด์šฉํ•˜์—ฌ ๊ณต๊ฒฉํ•˜๋Š” ๊ฒฝ์šฐ, DI-FGSM ์ด๋ผ๊ณ  ์นญํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ์•„๋ž˜์˜ Related work ์—์„œ ๊ฐ๊ฐ์˜ ๊ณต๊ฒฉ ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด์„œ๋„ ์†Œ๊ฐœํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

Related workโœจ

1) Iterative Fast Gradient Sign Method (I-FGSM)

โ€‹ Fast gradient sign method(FGSM)์€ ์ž…๋ ฅ ์ด๋ฏธ์ง€ X์™€ ์‹ค์ œ ํด๋ž˜์Šค y(true) ์— ๋Œ€ํ•ด ์†์‹ค ํ•จ์ˆ˜ L(X,y(true))๊ฐ€ ์ฆ๊ฐ€ํ•˜๋Š” ๋ฐฉํ–ฅ์œผ๋กœ X ์˜ ๊ฐ ํ”ฝ์…€์„ ฮต๋งŒํผ ๋ณ€ํ™”์‹œ์ผœ ์ ๋Œ€์ ์ธ ์ด๋ฏธ์ง€ X^{adv}๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

Xadv=X+ฮตโ‹…sign(โˆ‡XL(X,ytrue)).X^{adv}=X+ฮตยทsign(โˆ‡_X L(X,y^{true})).Xadv=X+ฮตโ‹…sign(โˆ‡Xโ€‹L(X,ytrue)).

โ€‹ ๊ฐ ํ”ฝ์…€์„ ฮฑ ๋งŒํผ ๋ณ€ํ™”์‹œํ‚ค๋Š” FGSM ๊ณต๊ฒฉ์„ ๋ฐ˜๋ณต์ ์œผ๋กœ ์‹œํ–‰ํ•œ ๊ฒƒ์ด Iterative Fast Gradient Sign Method (I-FGSM)์ž…๋‹ˆ๋‹ค.

X0adv=X,X_0^{adv}=X,X0advโ€‹=X,
Xn+1adv=ClipXฮต(Xnadv+ฮฑโ‹…sign(โˆ‡XL(Xnadv,ytrue)).X_{n+1}^{adv}=Clip_X^ฮต(X_n^{adv}+ฮฑยทsign(โˆ‡_X L(X_n^{adv},y^{true})).Xn+1advโ€‹=ClipXฮตโ€‹(Xnadvโ€‹+ฮฑโ‹…sign(โˆ‡Xโ€‹L(Xnadvโ€‹,ytrue)).

2) ๋ชจ๋ฉ˜ํ…€ ์ด์šฉ ๊ธฐ๋ฒ• (MI-FGSM)

โ€‹ ์†Œ์Šค ๋ชจ๋ธ์— ๋Œ€ํ•œ ๊ณผ์ ํ•ฉ์„ ๋ฐฉ์ง€ํ•˜๋Š” ๋ฐฉ๋ฒ•์œผ๋กœ ๋ชจ๋ฉ˜ํ…€(momentum)์„ ์ด์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์ธ ๋ชจ๋ฉ˜ํ…€ ์ด์šฉ ๊ธฐ๋ฒ• (MI-FGSM)์ด ์žˆ์Šต๋‹ˆ๋‹ค. MI-FGSM์€ I-FGSM๊ณผ ๊ฐ™์ด ๋ฐ˜๋ณต์ ์œผ๋กœ ์ˆ˜ํ–‰๋˜๋ฉฐ, ์ฒ˜์Œ๋ถ€ํ„ฐ ํ˜„์žฌ๊นŒ์ง€์˜ ๊ฒฝ์‚ฌ๋„(gt) ์ •๋ณด๋ฅผ ์ถ•์ ํ•˜์—ฌ ์ ๋Œ€์  ์ด๋ฏธ์ง€ ๊ฐฑ์‹ ์— ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๊ฐฑ์‹ ์— ์†์‹คํ•จ์ˆ˜์˜ ๋ถ€ํ˜ธ๊ฐ€ ์•„๋‹Œ, gt์˜ ๋ถ€ํ˜ธ๋ฅผ ์ด์šฉํ•œ๋‹ค๋Š” ์ ์—์„œ ์ฐจ์ด๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

gn+1=ฮผgn+โˆ‡XL(Xnadv,ytrue)โˆฃโˆฃโˆ‡XL(Xnadv,ytrue)โˆฃโˆฃ1,g_{n+1}= ฮผg_n + {โˆ‡_X L(X_n^{adv},y^{true} )\over ||โˆ‡_X L(X_n^{adv},y^{true})||_1 },gn+1โ€‹=ฮผgnโ€‹+โˆฃโˆฃโˆ‡Xโ€‹L(Xnadvโ€‹,ytrue)โˆฃโˆฃ1โ€‹โˆ‡Xโ€‹L(Xnadvโ€‹,ytrue)โ€‹,
Xn+1adv=Xnadv+ฮฑโ‹…sign(gt+1).X_{n+1}^{adv}=X_{n}^{adv} +ฮฑยทsign(g_{t+1}).Xn+1advโ€‹=Xnadvโ€‹+ฮฑโ‹…sign(gt+1โ€‹).

โ€‹ ๊ฒฝ์‚ฌ๋„๋ฅผ ์ถ•์ ํ•˜์—ฌ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์€ ์ข‹์ง€ ์•Š์€ ์ง€์—ญ์  ์ตœ์†Œ์ (poor local maxima)์— ๋น ์ง€์ง€ ์•Š๊ฒŒ ๋„์™€์ฃผ๋ฉฐ, I-FGSM์— ๋น„ํ•ด ๋ฐ˜๋ณต์ ์œผ๋กœ ๊ฐฑ์‹ ๋˜๋Š” ์ ๋Œ€์ ์ธ ๋ณ€ํ™”์˜ ๋ฐฉํ–ฅ์ด ๋น„์Šทํ•˜์—ฌ ์•ˆ์ •์ ์ž…๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ MI-FGSM์€ I-FGSM๋ณด๋‹ค ์ข‹์€ ์ „์ด์„ฑ์„ ๋ณด์ž…๋‹ˆ๋‹ค.

3. Implementation

  • Use Python language, version >= 3.6 : 3.6 ์ด์ƒ ๋ฒ„์ „์˜ ํŒŒ์ด์ฌ ์š”๊ตฌ

  • Use PyTorch : ์ฝ”๋“œ ๊ตฌํ˜„๊ณผ์ •์— PyTorch ์‚ฌ์šฉ

  • Use manual seed : ๋žœ๋ค์„ฑ์„ ๊ณ ์ •ํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ (์•„๋ž˜ example code์— ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.)

๐Ÿ”จ Environment

โ€‹ DI ๊ธฐ๋ฒ• ๊ตฌํ˜„๊ณผ์ •์—์„œ ํ•„์š”ํ•œ ํ™˜๊ฒฝ **(env_di-fgsm.yml)**์„ yml ํŒŒ์ผ๋กœ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค. ์•„๋‚˜์ฝ˜๋‹ค ๊ฐ€์ƒํ™˜๊ฒฝ์„ ์ด์šฉํ•˜๋ฉฐ, ์•„๋ž˜์˜ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ด ํ™˜๊ฒฝ์„ค์ •์„ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

# Environment setup using conda
conda env create -f env_di-fgsm.yml

๐Ÿ“‹DI-FGSM

โ€‹ ์ด ํŒŒ์ผ์—๋Š”, DI-FGSM์ด ๊ตฌํ˜„๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. _์ฃผ์„_์„ ์ด์šฉํ•ด ์ „๋ฐ˜์ ์ธ ์ฝ”๋“œ ์„ค๋ช…์„ ํ–ˆ์Šต๋‹ˆ๋‹ค. ์•„๋ž˜์—์„œ ์†Œ๊ฐœ๋  ์˜ˆ์‹œ ํŒŒ์ผ Transfer Attack.py ์—์„œ ์ด์šฉํ•œ CIFAR-10 ์ด๋ฏธ์ง€ (size : 32, 32) ๊ธฐ์ค€์œผ๋กœ ์˜ˆ์‹œ๋ฅผ ๋“ค์–ด tensors ์˜ ํฌ๊ธฐ๋ฅผ ๋‚˜ํƒ€๋ƒˆ์Šต๋‹ˆ๋‹ค.

โ€‹ class DIFGSM ๋‚ด์— ์žˆ๋Š” diverse_input ํ•จ์ˆ˜ ๋ถ€๋ถ„์ด DI-FGSM์˜ ํ•ต์‹ฌ ๋ถ€๋ถ„์ธ DI transform ์ด ์ผ์–ด๋‚˜๋Š” ๋ถ€๋ถ„์ž…๋‹ˆ๋‹ค. ๋žœ๋ค ํฌํ‚ค ๋ณ€ํ™˜ ๊ณผ ๋žœ๋ค ํŒจ๋”ฉ ๋ถ€๋ถ„์ด ๊ตฌํ˜„๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. forward ํ•จ์ˆ˜์—์„œ diverse_input ํ•จ์ˆ˜ ํ˜ธ์ถœ ์ดํ›„, ์—ญ์ „ํŒŒ(backpropagation) ์ด ์ผ์–ด๋‚ฉ๋‹ˆ๋‹ค.

## DI-FGSM : DIFGSM.py

import torch
import torch.nn as nn
import torchvision.transforms as transforms
from torchvision.transforms import InterpolationMode
import torchgeometry as tgm
from attack import Attack


class DIFGSM(Attack):

    def __init__(self, model, eps=8/255, alpha=2/255, steps=20, di_pad_amount=31, di_prob=0.5):
        super().__init__("DIFGSM", model)
        self.eps = eps # Maximum change in one pixel for total step (range 0-255)
        self.steps = steps # number of di-fgsm steps
        self.alpha = alpha # Maximum change in one pixel for one step (range 0-255)
        self.di_pad_amount = di_pad_amount # Maximum value that can be padded
        self.di_prob = di_prob # Probability of deciding whether to apply DI transform or not
        self._supported_mode = ['default', 'targeted'] # deciding targeted attack or not

    def diverse_input(self, x_adv):
        x_di = x_adv # size : [24,3,32,32]
        h, w = x_di.shape[2], x_di.shape[3] # original image size, h: 32, w: 32
        # random value that be padded
        pad_max = self.di_pad_amount - int(torch.rand(1) * self.di_pad_amount) # pad_max : 2
        # random value that be padded left
        pad_left = int(torch.rand(1) * pad_max) # pad_left : 1
        # random value that be padded right
        pad_right = pad_max - pad_left # pad_right : 1
        # random value that be padded top
        pad_top = int(torch.rand(1) * pad_max) # pad_top : 1
        # random value that be padded bottom
        pad_bottom = pad_max - pad_top  # pad_bottom : 1

        # four vertices of the original image
        # tensor([[[ 0.,  0.], [31.,  0.], [31., 31.], [ 0., 31.]]])
        points_src = torch.FloatTensor([[
            [0, 0], [w - 1, 0], [w - 1 + 0, h - 1 + 0], [0, h - 1 + 0],
        ]]) 

        # four vertices of the image after DI transform
        # tensor([[[ 1.,  1.], [30.,  1.], [30., 30.], [ 1., 30.]]])
        points_dst = torch.FloatTensor([[
            [pad_left, pad_top], [w - pad_right - 1, pad_top],
            [w - pad_right - 1, h - pad_bottom - 1], [pad_left, h - pad_bottom - 1],
        ]]) 

        # Matrix used in the transformation process
        # tensor([[[0.9355, 0.0000, 1.0000], [0.0000, 0.9355, 1.0000], [0.0000, 0.0000, 1.0000]]])
        M = tgm.get_perspective_transform(points_src, points_dst) 
        
        # The image is resized and padded so that the vertices of the original image go to the new vertices.
        x_di = tgm.warp_perspective(x_di, torch.cat(x_di.shape[0] * [M]).cuda(), dsize=(w, h)).cuda()
        x_di = transforms.Resize((w, h), interpolation=InterpolationMode.NEAREST)(x_di)
        
        # If the random value is less than or equal to di_prob, di conversion does not occur.
        cond = torch.rand(x_adv.shape[0]) < self.di_prob
        
        cond = cond.unsqueeze(-1).unsqueeze(-1).unsqueeze(-1)
        x_di = torch.where(cond.cuda(), x_di, x_adv)
        return x_di

    def forward(self, images, labels):
        """
        Overridden.
        """
        images = images.clone().detach().to(self.device)
        labels = labels.clone().detach().to(self.device)

        if self._targeted: # targeted attack case, get target label
            target_labels = self._get_target_label(images, labels)

        loss = nn.CrossEntropyLoss() # use Cross-Entropy loss for classification
        adv_images = images.clone().detach()


        for _ in range(self.steps):
            adv_images.requires_grad = True
            outputs = self.model(self.diverse_input(adv_images)) # after DI transform image

            # Calculate loss
            if self._targeted:
                cost = -loss(outputs, target_labels) # targeted attack case, use -loss function
            else:
                cost = loss(outputs, labels) # else, (untargeted attack case), use +loss function

            # Update adversarial images
            grad = torch.autograd.grad(cost, adv_images,
                                       retain_graph=False, create_graph=False)[0]

            grad = grad / torch.mean(torch.abs(grad), dim=(1,2,3), keepdim=True)

            adv_images = adv_images.detach() + self.alpha*grad.sign() # I-fgsm step
            delta = torch.clamp(adv_images - images, min=-self.eps, max=self.eps) # limiting changes beyond epsilon
            adv_images = torch.clamp(images + delta, min=0, max=1).detach()

        return adv_images

๐Ÿ“‹Example code

Transfer Attack.py ์ฝ”๋“œ์—์„œ, DI-FGSM์„ ์ด์šฉํ•œ Transfer Attack์˜ ์„ฑ๋Šฅ์„ ์‹คํ—˜ํ•ด๋ณด์•˜์Šต๋‹ˆ๋‹ค.

##3 : Source ๋ชจ๋ธ์˜ ๊ณต๊ฒฉ ๊ณผ์ • ๋ฐ ๊ฒฐ๊ณผ๋ฅผ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค. _atk = DIFGSM(model, eps=16 / 255, alpha=2 / 255, steps=10, di_pad_amount=5)_์™€ ๊ฐ™์ด ๊ณต๊ฒฉ์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

##5, ##6 : Target ๋ชจ๋ธ์— validation set์œผ๋กœ ์„ฑ๋Šฅ์„ ์‹œํ—˜ํ•œ clean accuracy์™€, ##3์—์„œ ๋งŒ๋“ค์–ด์ง„ ์ ๋Œ€์ ์ธ ์ด๋ฏธ์ง€๋กœ ์„ฑ๋Šฅ์„ ์‹œํ—˜ํ•œ robust accuracy๋ฅผ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.

example๐Ÿš€

##0 Example - Transfer Attack.py

from torch.utils.data import DataLoader, TensorDataset
import torchvision.utils
import torchvision.datasets as dsets
import random
import warnings
warnings.filterwarnings('ignore')
from models import Source, Target
from DIFGSM import *


##1 check version
print("PyTorch", torch.__version__)
print("Torchvision", torchvision.__version__)

my_seed = 7777
random.seed(my_seed)
torch.manual_seed(my_seed)
torch.cuda.manual_seed(my_seed)
torch.cuda.manual_seed_all(my_seed)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False

##2 Load Data
batch_size = 24

cifar10_train = dsets.CIFAR10(root='./data', train=True,
                              download=True, transform=transforms.ToTensor())
cifar10_test  = dsets.CIFAR10(root='./data', train=False,
                              download=True, transform=transforms.ToTensor())

train_loader = torch.utils.data.DataLoader(cifar10_train,
                                           batch_size=batch_size,
                                           shuffle=True)
test_loader = torch.utils.data.DataLoader(cifar10_test,
                                          batch_size=batch_size,
                                          shuffle=False)


##3 Attack Source Model & Save Adversarial Images
model = Source()
model.load_state_dict(torch.load("./data/source.pth"))
model = model.eval().cuda()

atk = DIFGSM(model, eps=16 / 255, alpha=2 / 255, steps=10, di_pad_amount=5)
atk.set_return_type('int') # Save as integer.
print('\n#################Source Model#################')
atk.save(data_loader=test_loader, save_path="./data/cifar10_DIFGSM.pt", verbose=True)


##4 Load Adversarial Images & Attack Target Model
adv_images, adv_labels = torch.load("./data/cifar10_DIFGSM.pt")
adv_data = TensorDataset(adv_images.float()/255, adv_labels)
adv_loader = DataLoader(adv_data, batch_size=128, shuffle=False)

model = Target().cuda()
model.load_state_dict(torch.load("./data/target.pth"))


##5 Target Model : Clean Accuracy
print('#################Target Model#################')
model.eval()
correct = 0
total = 0

for images, labels in test_loader:
    images = images.cuda()
    outputs = model(images)
    _, predicted = torch.max(outputs.data, 1)
    total += labels.size(0)
    correct += (predicted == labels.cuda()).sum()

print('Standard accuracy: %.2f %%' % (100 * float(correct) / total))


##6 Target Model : Robust Accuracy
model.eval()
correct = 0
total = 0

for images, labels in adv_loader:
    images = images.cuda()
    outputs = model(images)
    _, predicted = torch.max(outputs.data, 1)
    total += labels.size(0)
    correct += (predicted == labels.cuda()).sum()

print('Robust accuracy: %.2f %%' % (100 * float(correct) / total))

results๐Ÿš€

โ€‹ Target ๋ชจ๋ธ์— _validation set_์œผ๋กœ ์„ฑ๋Šฅ์„ ์‹œํ—˜ํ•œ clean accuracy์˜ ์„ฑ๋Šฅ์€ 87.26 % ๋กœ ๋น„๊ต์  ๋†’์€ ๋น„๊ต ์„ฑ๋Šฅ์„ ๋ณด์ž…๋‹ˆ๋‹ค.

โ€‹ ๋ฐ˜๋ฉด Source ๋ชจ๋ธ์„ ํ†ตํ•ด DI-FGSM์œผ๋กœ ๋งŒ๋“ค์–ด์ง„ ์ ๋Œ€์ ์ธ ์ด๋ฏธ์ง€๋กœ Target ๋ชจ๋ธ ์„ฑ๋Šฅ์„ ์‹œํ—˜ํ•œ robust accuracy๋Š” 38.87 %๋กœ ๋‚ฎ์€ ์„ฑ๋Šฅ์„ ๋ณด์ด๋ฉฐ, ์„ฑ๊ณต์ ์ธ ์ „์ด ๊ธฐ๋ฐ˜ ์ ๋Œ€์  ๊ณต๊ฒฉ์ž„์„ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

System :  3.6.13 |Anaconda, Inc.| (default, Mar 16 2021, 11:37:27) [MSC v.1916 64 bit (AMD64)]
Nunpy :  1.19.2
PyTorch :  1.9.0
Files already downloaded and verified
Files already downloaded and verified

#################Source Model#################
- Save progress: 100.00 % / Accuracy: 0.03 % / L2: 2.26292 (0.047 it/s) 	
- Save complete! 

#################Target Model#################
Standard accuracy: 87.26 %
Robust accuracy: 38.87 %

Process finished with exit code 0

Author / Reviewer information

Author๐Ÿ˜

๊น€ํฌ์„  (Hee-Seon Kim)

  • KAIST EE

  • https://github.com/khslily98

  • hskim98@kaist.ac.kr

Reviewer๐Ÿ˜

  1. Korean name (English name): Affiliation / Contact information

  2. Korean name (English name): Affiliation / Contact information

  3. ...

Reference & Additional materials

  1. Citation of this paper

  2. Official (unofficial) GitHub repository

  3. Citation of related work

  4. Other useful materials

  5. ...

English version