Implementation:Norrrrrrr lyn WAInjectBench load detector image
| Knowledge Sources | |
|---|---|
| Domains | Software_Architecture, Plugin_Systems, Computer_Vision |
| Last Updated | 2026-02-14 16:00 GMT |
Overview
Concrete tool for dynamically loading image detector modules at runtime with special LLaVA variant routing, provided by the WAInjectBench main_image module.
Description
The load_detector function in main_image.py handles two cases: (1) LLaVA variants (llava-1.5-7b-prompt, llava-1.5-7b-ft) which both load the detector_image.llava module, and (2) all other detectors which load via importlib.import_module(f"detector_image.{detector_name}"). Valid detectors include: gpt-4o-prompt, jailguard, embedding-i, llava-1.5-7b-prompt, llava-1.5-7b-ft, and ensemble.
Usage
Import and call this function when you need to dynamically select an image detector at runtime based on the --detector CLI argument.
Code Reference
Source Location
- Repository: WAInjectBench
- File: main_image.py (L7-26)
Signature
def load_detector(detector_name: str):
"""
Dynamically load the corresponding detector module.
- For most detectors: import detector_image.{detector_name}
- For LLaVA series (llava-1.5-7b-prompt / llava-1.5-7b-ft):
always import detector_image.llava
"""
import importlib
if detector_name in ["llava-1.5-7b-prompt", "llava-1.5-7b-ft"]:
module = importlib.import_module("detector_image.llava")
return module
try:
module = importlib.import_module(f"detector_image.{detector_name}")
return module
except ImportError:
raise ValueError(
f"Detector {detector_name} not found. "
f"Make sure you have a file under detector_image/ named {detector_name}.py"
)
Import
from main_image import load_detector
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| detector_name | str | Yes | Name of the detector (e.g., "gpt-4o-prompt", "jailguard", "embedding-i", "llava-1.5-7b-prompt", "llava-1.5-7b-ft") |
Outputs
| Name | Type | Description |
|---|---|---|
| module | module | Loaded Python module with a detect(folder_path: str) -> List[int] function (or detect(folder_path, detector_name) for LLaVA) |
Usage Examples
Loading an Image Detector
# Load the CLIP embedding detector
detector = load_detector("embedding-i")
detect_ids = detector.detect("data/image/malicious/attack_scenario/")
# Load a LLaVA variant (both route to the same module)
detector = load_detector("llava-1.5-7b-ft")
# LLaVA requires detector_name to be passed through
from detector_image import llava
detect_ids = llava.detect("data/image/malicious/attack/", detector_name="llava-1.5-7b-ft")