saiK90/image-forensics-env
๐ฌ ImageForensicsEnv
An OpenEnv environment for training RL agents to detect AI-generated images.
Built for the Meta ร PyTorch OpenEnv Hackathon by Scaler School of Technology.
Overview
ImageForensicsEnv is a real-world reinforcement learning environment where an AI agent learns to distinguish AI-generated images from authentic photographs by analyzing forensic visual signals.
The agent receives a set of extracted forensic features (noise patterns, edge coherence, lighting consistency, texture realism, frequency domain analysis, structural symmetry) and must submit a verdict:
Environment Design
Action Space
ForensicsAction(
verdict: Literal["AI_GENERATED", "AUTHENTIC", "UNCERTAIN"],
confidence: float, # 0.0 โ 1.0
reasoning: str, # optional chain-of-thought
task_id: str, # which task difficulty
)Observation Space
ForensicsObservation(
image_id: str,
task_id: str,
signals: List[SignalFeature], # 6 forensic signals
image_b64: str, # base64 JPEG for multimodal agents
ground_truth: str | None, # revealed after step()
reward: float,
done: bool,
success: bool | None,
feedback: str,
step_count: int,
)Reward Function
Difficulty bonuses: Medium +0.1, Hard +0.2
Tasks
Easy โ Obvious AI Images
Detect clearly AI-generated images with obvious artifacts: perfect symmetry, dreamlike backgrounds, merged fingers, halo edges.
- Score range: 0.0 โ 1.0
Medium โ Subtle AI Composites
Detect AI images that mimic photographic quality. Requires analyzing subtle texture anomalies and lighting inconsistencies.
- Score range: 0.0 โ 1.1
Hard โ Adversarial AI Images
Detect post-processed AI images designed to evade detectors. Requires frequency domain and deep pattern analysis.
- Score range: 0.0 โ 1.2
Setup & Running
Prerequisites
- Python 3.10+
- Docker
- Hugging Face CLI
Local Setup
git clone https://github.com/your-org/image-forensics-env
cd image-forensics-env
pip install -r server/requirements.txt
# Start the environment server
uvicorn server.app:app --host 0.0.0.0 --port 8000Run Baseline Inference
export API_BASE_URL="https://api.openai.com/v1"
export MODEL_NAME="gpt-4o-mini"
export HF_TOKEN="your_hf_token"
export ENV_BASE_URL="http://localhost:8000"
python inference.pyRun Graders
python graders.pyDocker
docker build -t image-forensics-env .
docker run -p 8000:8000 image-forensics-envAPI Reference
Example Usage
from client import ImageForensicsEnv
from models import ForensicsAction
with ImageForensicsEnv(base_url="https://your-space.hf.space") as env:
# Start episode
obs = env.reset()
print(f"Task: {obs.task_id}")
for signal in obs.signals:
print(f" {signal.name}: {signal.score:.3f} โ {signal.description}")
# Submit verdict
result = env.step(ForensicsAction(
verdict="AI_GENERATED",
confidence=0.87,
task_id=obs.task_id,
reasoning="High symmetry score and anomalous frequency peaks",
))
print(f"Reward: {result.reward} | Ground truth: {result.ground_truth}")Project Structure
image_forensics_env/
โโโ models.py # Typed Action + Observation models
โโโ client.py # Python client for connecting to env
โโโ inference.py # Baseline LLM agent (hackathon required)
โโโ graders.py # Automated task graders
โโโ openenv.yaml # OpenEnv spec config
โโโ Dockerfile # Container for HF Spaces
โโโ README.md # This file
โโโ server/
โโโ app.py # FastAPI server
โโโ environment.py # Core environment logic
โโโ requirements.txt # DependenciesEnvironment Variables
Hackathon Submission
- Event: Meta ร PyTorch OpenEnv Hackathon โ Scaler School of Technology
- Deadline: April 8, 2026, 11:59 PM IST
- Track: Real-world OpenEnv Environment
- Framework: OpenEnv + FastAPI + Pydantic
