# gubi/ai-nsfw-image-detection-and-filtering architecture

> Architecture diagram of the GitHub repository gubi/ai-nsfw-image-detection-and-filtering, 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/gubi/ai-nsfw-image-detection-and-filtering
- Repository: https://github.com/gubi/ai-nsfw-image-detection-and-filtering

## Overview

This repository provides two local image workflows: pixelate and report NSFW detections, or combine general-object and NSFW detections with image metadata. The filter’s inference, annotation, and report writes are explicit in source. The detector excerpt is partial, so its input wiring and description-generation use are not fully represented.

Main entry points: [`nsfw_filter.py`](https://github.com/gubi/ai-nsfw-image-detection-and-filtering/blob/master/nsfw_filter.py) (Filter workflow), [`image_detector.py`](https://github.com/gubi/ai-nsfw-image-detection-and-filtering/blob/master/image_detector.py) (Detector workflow), [`training_samples/selected`](https://github.com/gubi/ai-nsfw-image-detection-and-filtering/tree/master/training_samples/selected) (Selected images), [`pretrains/erax_nsfw_yolo11m.pt`](https://github.com/gubi/ai-nsfw-image-detection-and-filtering/blob/master/pretrains/erax_nsfw_yolo11m.pt) (NSFW weights)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_filtering["NSFW filtering"]
  node_filter["Filter workflow<br/>[nsfw_filter.py]"]
  node_yolo_filter["NSFW YOLO<br/>[nsfw_filter.py]"]
  node_pixelate["Pixelation<br/>[nsfw_filter.py]"]
  node_report["Detection report<br/>[report.json]"]
  node_filtered_images["Filtered images"]
end

subgraph group_detection["Image detection"]
  node_detector["Detector workflow<br/>[image_detector.py]"]
  node_dual_detect["Dual-model detection<br/>[image_detector.py]"]
  node_merge["Merge results<br/>[image_detector.py]"]
  node_face_age["Face age/gender<br/>[image_detector.py]"]
  node_description["Image description<br/>[image_detector.py]"]
end

subgraph group_assets["Models and data"]
  node_selected["Selected images"]
  node_yolo_weights["YOLO weights<br/>[yolo11m.pt]"]
  node_nsfw_weights["NSFW weights"]
  node_collected["Collected media"]
end

node_user(("Operator"))
node_moondream{{"Moondream API"}}

node_user -->|"runs"| node_filter
node_filter -->|"loads model"| node_yolo_filter
node_yolo_filter -->|"loads weights"| node_nsfw_weights
node_filter -->|"reads images"| node_selected
node_filter -->|"annotates detections"| node_pixelate
node_filter -->|"writes report"| node_report
node_filter -->|"saves images"| node_filtered_images
node_user -->|"runs"| node_detector
node_detector -->|"invokes"| node_dual_detect
node_dual_detect -->|"loads weights"| node_yolo_weights
node_dual_detect -->|"loads weights"| node_nsfw_weights
node_dual_detect -->|"reads images"| node_selected
node_detector -->|"merges results"| node_merge
node_merge -->|"gets demographics"| node_face_age
node_detector -.-> node_description
node_description -.->|"queries"| node_moondream

click node_filter "https://github.com/gubi/ai-nsfw-image-detection-and-filtering/blob/master/nsfw_filter.py"
click node_yolo_filter "https://github.com/gubi/ai-nsfw-image-detection-and-filtering/blob/master/nsfw_filter.py"
click node_pixelate "https://github.com/gubi/ai-nsfw-image-detection-and-filtering/blob/master/nsfw_filter.py"
click node_report "https://github.com/gubi/ai-nsfw-image-detection-and-filtering/blob/master/training_samples/nsfw_recognized/report.json"
click node_filtered_images "https://github.com/gubi/ai-nsfw-image-detection-and-filtering/tree/master/training_samples/nsfw_recognized"
click node_detector "https://github.com/gubi/ai-nsfw-image-detection-and-filtering/blob/master/image_detector.py"
click node_dual_detect "https://github.com/gubi/ai-nsfw-image-detection-and-filtering/blob/master/image_detector.py"
click node_merge "https://github.com/gubi/ai-nsfw-image-detection-and-filtering/blob/master/image_detector.py"
click node_face_age "https://github.com/gubi/ai-nsfw-image-detection-and-filtering/blob/master/image_detector.py"
click node_description "https://github.com/gubi/ai-nsfw-image-detection-and-filtering/blob/master/image_detector.py"
click node_selected "https://github.com/gubi/ai-nsfw-image-detection-and-filtering/tree/master/training_samples/selected"
click node_yolo_weights "https://github.com/gubi/ai-nsfw-image-detection-and-filtering/blob/master/pretrains/yolo11m.pt"
click node_nsfw_weights "https://github.com/gubi/ai-nsfw-image-detection-and-filtering/blob/master/pretrains/erax_nsfw_yolo11m.pt"
click node_collected "https://github.com/gubi/ai-nsfw-image-detection-and-filtering/tree/master/training_samples/collected"

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_filter,node_yolo_filter,node_pixelate,node_report,node_filtered_images toneBlue
class node_detector,node_dual_detect,node_merge,node_face_age,node_description toneAmber
class node_selected,node_yolo_weights,node_nsfw_weights,node_collected,node_moondream toneMint
class node_user toneIndigo
```

## Components

### NSFW filtering

- [Filter workflow](https://github.com/gubi/ai-nsfw-image-detection-and-filtering/blob/master/nsfw_filter.py): `nsfw_filter.py`
- [NSFW YOLO](https://github.com/gubi/ai-nsfw-image-detection-and-filtering/blob/master/nsfw_filter.py): `nsfw_filter.py`
- [Pixelation](https://github.com/gubi/ai-nsfw-image-detection-and-filtering/blob/master/nsfw_filter.py): `nsfw_filter.py`
- [Detection report](https://github.com/gubi/ai-nsfw-image-detection-and-filtering/blob/master/training_samples/nsfw_recognized/report.json): `training_samples/nsfw_recognized/report.json`
- [Filtered images](https://github.com/gubi/ai-nsfw-image-detection-and-filtering/tree/master/training_samples/nsfw_recognized): `training_samples/nsfw_recognized`

### Image detection

- [Detector workflow](https://github.com/gubi/ai-nsfw-image-detection-and-filtering/blob/master/image_detector.py): `image_detector.py`
- [Dual-model detection](https://github.com/gubi/ai-nsfw-image-detection-and-filtering/blob/master/image_detector.py): `image_detector.py`
- [Merge results](https://github.com/gubi/ai-nsfw-image-detection-and-filtering/blob/master/image_detector.py): `image_detector.py`
- [Face age/gender](https://github.com/gubi/ai-nsfw-image-detection-and-filtering/blob/master/image_detector.py): `image_detector.py`
- [Image description](https://github.com/gubi/ai-nsfw-image-detection-and-filtering/blob/master/image_detector.py): `image_detector.py`

### Models and data

- [Selected images](https://github.com/gubi/ai-nsfw-image-detection-and-filtering/tree/master/training_samples/selected): `training_samples/selected`
- [YOLO weights](https://github.com/gubi/ai-nsfw-image-detection-and-filtering/blob/master/pretrains/yolo11m.pt): `pretrains/yolo11m.pt`
- [NSFW weights](https://github.com/gubi/ai-nsfw-image-detection-and-filtering/blob/master/pretrains/erax_nsfw_yolo11m.pt): `pretrains/erax_nsfw_yolo11m.pt`
- [Collected media](https://github.com/gubi/ai-nsfw-image-detection-and-filtering/tree/master/training_samples/collected): `training_samples/collected`

### Other components

- **Operator**
- **Moondream API**

## Connections

- Operator → Filter workflow: runs
- Filter workflow → NSFW YOLO: loads model
- NSFW YOLO → NSFW weights: loads weights
- Filter workflow → Selected images: reads images
- Filter workflow → Pixelation: annotates detections
- Filter workflow → Detection report: writes report
- Filter workflow → Filtered images: saves images
- Operator → Detector workflow: runs
- Detector workflow → Dual-model detection: invokes
- Dual-model detection → YOLO weights: loads weights
- Dual-model detection → NSFW weights: loads weights
- Dual-model detection → Selected images: reads images
- Detector workflow → Merge results: merges results
- Merge results → Face age/gender: gets demographics
- Detector workflow → Image description
- Image description → Moondream API: queries
