# SEBA: Sample-Efficient Black-Box Attacks on Visual RL

This repository contains the official implementation of **SEBA (CVPR 2026)** and multiple **baseline attackers**.  
The project is organized into:

- `test-attack/` — victim training & evaluation  
- `wm/` — world model training  
- `seba/` — SEBA training
- `optimal/` — OPTIMAL attacker  
- `paad/` — PA-AD attacker  

Below is a complete workflow using **`cheetah_run`** as an example.

---

## 1. Environment Setup

```bash
conda env create -f conda_env.yml
conda activate drq
```

---

## 2. Train the Victim Policy

From the `test-attack` directory:

```bash
cd test-attack
python train_victim.py env=cheetah_run
```

Checkpoint saved to:

```
victim_model/cheetah_run.pth
```

---

## 3. Train the World Model

From the `wm` directory:

```bash
cd wm
python train_iris.py --env_name cheetah_run
```

Outputs:

```
iris_ckpt/tokenizer_cheetah_run_ep4.pt
iris_ckpt/wm_cheetah_run_ep9.pt
```

---

## 4. Train SEBA

From the `seba` directory:

```bash
cd seba
python two_step_gan.py env=cheetah_run
```

Checkpoint:

```
g_models/cheetah_run.pth
```

---

## 5. Train Baseline Attackers

### OPTIMAL

```bash
cd optimal
python train_optimal.py env=cheetah_run
```

Checkpoint:

```
opt_adv_ckpt/cheetah_run_opt_adv.pth
```

### PA-AD

```bash
cd paad
python train_paad.py env=cheetah_run
```

Checkpoint:

```
opt_adv_ckpt/cheetah_run_paad_adv.pth
```

---

## 6. Evaluation: Run Attacks on the Victim

Back to `test-attack`:

```bash
cd test-attack
python test_attack.py env=cheetah_run
```

The attack modes are:

```python
adv_dict = {
    # image-based attacks
    0: "test_clean",
    1: "adv_pgd",
    2: "adv_cw",
    3: "simba_attack",
    4: "adv_square",

    # vector RL–based attacks
    5: "adv_critic",
    6: "adv_mad",

    # generator-based (PA-AD, OPTIMAL, SEBA)
    7: "adv_gen_based",
}
```

- `test_clean` → no attack  
- `adv_pgd`, `adv_cw`, `simba_attack`, `adv_square` → image-space perturbations  
- `adv_critic`, `adv_mad` → RL-based attackers  
- `adv_gen_based` → uses PA-AD / OPTIMAL / SEBA depending on the loaded generator  

The script prints the **cumulative reward** under each attack.

---

## Notes

- Replace `cheetah_run` with any other task.
- Ensure the directory structure and file paths remain consistent with this README.

