# kerthans/deep-learning-visual-attack architecture

> Architecture diagram of the GitHub repository kerthans/deep-learning-visual-attack, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kerthans/deep-learning-visual-attack
- Repository: https://github.com/kerthans/deep-learning-visual-attack

## Overview

This repository is a collection of visual-model adversarial-attack experiments. The main CartPole workflow trains a policy, saves its weights, then runs clean and perturbed episodes or compares actions on perturbed states. A separate MNIST script exercises several gradient-based and simple black-box attacks. The README also describes Pong, Breakout, and transferability research, but the available tree and sampled code do not establish implementations or wiring for those capabilities. The graph reflects the available scripts; rendering.py is an auxiliary Gym rendering layer.

Main entry points: [`evaluate.py`](https://github.com/kerthans/deep-learning-visual-attack/blob/main/evaluate.py) (Episode evaluation), [`evaluate-img.py`](https://github.com/kerthans/deep-learning-visual-attack/blob/main/evaluate-img.py) (Plotted evaluation), [`train_agent-S.py`](https://github.com/kerthans/deep-learning-visual-attack/blob/main/train_agent-S.py) (Train CartPole policy), [`attack.py`](https://github.com/kerthans/deep-learning-visual-attack/blob/main/attack.py) (CartPole attacks)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_agent["Policy agent"]
  node_training["Train CartPole policy<br/>[train_agent-S.py]"]
  node_weights["Policy weights<br/>[policy_net.pth]"]
end

subgraph group_attacks["Attack experiments"]
  node_cartpoleattack["CartPole attacks<br/>[attack.py]"]
  node_mnistattack["MNIST attacks<br/>[attack2.py]"]
end

subgraph group_evaluation["Evaluation"]
  node_eval["Episode evaluation<br/>[evaluate.py]"]
  node_evalimg["Plotted evaluation<br/>[evaluate-img.py]"]
  node_results["Metrics and plots"]
end

subgraph group_visualization["Rendering"]
  node_renderer["2D renderer<br/>[rendering.py]"]
end

node_researcher(("Researcher"))
node_gym["Gym environments"]
node_torch["PyTorch"]
node_mnist["MNIST dataset"]

node_researcher -->|"starts training"| node_training
node_training -->|"steps environment"| node_gym
node_training -->|"trains policy"| node_torch
node_training -->|"saves weights"| node_weights
node_researcher -->|"runs experiment"| node_cartpoleattack
node_cartpoleattack -->|"loads weights"| node_weights
node_cartpoleattack -->|"tests episodes"| node_gym
node_cartpoleattack -->|"generates perturbations"| node_torch
node_researcher -->|"runs evaluation"| node_eval
node_eval -->|"loads weights"| node_weights
node_eval -->|"steps environment"| node_gym
node_eval -->|"scores actions"| node_torch
node_eval -->|"records metrics"| node_results
node_researcher -->|"runs evaluation"| node_evalimg
node_evalimg -->|"loads weights"| node_weights
node_evalimg -->|"steps environment"| node_gym
node_evalimg -->|"scores actions"| node_torch
node_evalimg -->|"plots results"| node_results
node_researcher -->|"runs attacks"| node_mnistattack
node_mnistattack -->|"loads samples"| node_mnist
node_mnistattack -->|"computes gradients"| node_torch
node_gym -.->|"renders scenes"| node_renderer

click node_training "https://github.com/kerthans/deep-learning-visual-attack/blob/main/train_agent-S.py"
click node_weights "https://github.com/kerthans/deep-learning-visual-attack/blob/main/policy_net.pth"
click node_cartpoleattack "https://github.com/kerthans/deep-learning-visual-attack/blob/main/attack.py"
click node_mnistattack "https://github.com/kerthans/deep-learning-visual-attack/blob/main/attack2.py"
click node_eval "https://github.com/kerthans/deep-learning-visual-attack/blob/main/evaluate.py"
click node_evalimg "https://github.com/kerthans/deep-learning-visual-attack/blob/main/evaluate-img.py"
click node_renderer "https://github.com/kerthans/deep-learning-visual-attack/blob/main/rendering.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_training,node_weights toneBlue
class node_cartpoleattack,node_mnistattack toneAmber
class node_eval,node_evalimg,node_results toneMint
class node_renderer toneRose
class node_researcher,node_gym,node_torch,node_mnist toneIndigo
```

## Components

### Policy agent

- [Train CartPole policy](https://github.com/kerthans/deep-learning-visual-attack/blob/main/train_agent-S.py): `train_agent-S.py`
- [Policy weights](https://github.com/kerthans/deep-learning-visual-attack/blob/main/policy_net.pth): `policy_net.pth`

### Attack experiments

- [CartPole attacks](https://github.com/kerthans/deep-learning-visual-attack/blob/main/attack.py): `attack.py`
- [MNIST attacks](https://github.com/kerthans/deep-learning-visual-attack/blob/main/attack2.py): `attack2.py`

### Evaluation

- [Episode evaluation](https://github.com/kerthans/deep-learning-visual-attack/blob/main/evaluate.py): `evaluate.py`
- [Plotted evaluation](https://github.com/kerthans/deep-learning-visual-attack/blob/main/evaluate-img.py): `evaluate-img.py`
- **Metrics and plots**

### Rendering

- [2D renderer](https://github.com/kerthans/deep-learning-visual-attack/blob/main/rendering.py): `rendering.py`

### Other components

- **Researcher**
- **Gym environments**
- **PyTorch**
- **MNIST dataset**

## Connections

- Researcher → Train CartPole policy: starts training
- Train CartPole policy → Gym environments: steps environment
- Train CartPole policy → PyTorch: trains policy
- Train CartPole policy → Policy weights: saves weights
- Researcher → CartPole attacks: runs experiment
- CartPole attacks → Policy weights: loads weights
- CartPole attacks → Gym environments: tests episodes
- CartPole attacks → PyTorch: generates perturbations
- Researcher → Episode evaluation: runs evaluation
- Episode evaluation → Policy weights: loads weights
- Episode evaluation → Gym environments: steps environment
- Episode evaluation → PyTorch: scores actions
- Episode evaluation → Metrics and plots: records metrics
- Researcher → Plotted evaluation: runs evaluation
- Plotted evaluation → Policy weights: loads weights
- Plotted evaluation → Gym environments: steps environment
- Plotted evaluation → PyTorch: scores actions
- Plotted evaluation → Metrics and plots: plots results
- Researcher → MNIST attacks: runs attacks
- MNIST attacks → MNIST dataset: loads samples
- MNIST attacks → PyTorch: computes gradients
- Gym environments → 2D renderer: renders scenes
