# grip-unina/b-free architecture

> Architecture diagram of the GitHub repository grip-unina/b-free, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/grip-unina/b-free
- Repository: https://github.com/grip-unina/b-free

## Overview

B-Free is a PyTorch AI-generated-image detector. Its implemented user workflow accepts an image or CSV of images, loads a configured detector, normalizes inputs, produces fake-image logits, and can save scores and compute detection metrics. The README also describes a bias-reducing training paradigm and provides training, viral-image, and new-generator datasets; those are represented as documented capabilities, not as inspected runtime pipelines. Source evidence is limited to the excerpts and README provided.

Main entry points: [`code/main_bfree.py`](https://github.com/grip-unina/b-free/blob/main/code/main_bfree.py) (CSV inference), [`code/main_bfree_single.py`](https://github.com/grip-unina/b-free/blob/main/code/main_bfree_single.py) (Single-image scoring), [`code/networks/__init__.py`](https://github.com/grip-unina/b-free/blob/main/code/networks/__init__.py) (Network factory), [`code`](https://github.com/grip-unina/b-free/tree/main/code) (Bias-free training paradigm)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inference["Detection workflow"]
  node_single["Single-image scoring"]
  node_batch["CSV inference<br/>[main_bfree.py]"]
  node_normalization["Image normalization<br/>[normalization.py]"]
  node_scorefiles["Score CSV<br/>[main_bfree.py]"]
  node_metrics["Detection metrics<br/>[dmetrics.py]"]
end

subgraph group_model["Model internals"]
  node_factory["Network factory<br/>[__init__.py]"]
  node_weights["Checkpoint loading<br/>[__init__.py]"]
  node_cropmodel["Five-crop detector<br/>[wrapper5crops.py]"]
  node_checkpointfiles["Model config and weights"]
end

subgraph group_data["Data and methodology"]
  node_paradigm["Bias-free training paradigm"]
  node_trainingdata["Training dataset"]
  node_viraldata["Viral image dataset"]
  node_generatordata["New-generator dataset"]
end

node_user(("Analyst"))
node_stable["Stable Diffusion 2.1"]

node_user -->|"submits image"| node_single
node_user -->|"submits CSV"| node_batch
node_single -->|"normalizes image"| node_normalization
node_batch -->|"normalizes images"| node_normalization
node_single -->|"creates network"| node_factory
node_batch -->|"creates network"| node_factory
node_single -->|"loads weights"| node_weights
node_batch -->|"loads weights"| node_weights
node_factory -->|"wraps backbone"| node_cropmodel
node_single -->|"reads config"| node_checkpointfiles
node_batch -->|"reads config"| node_checkpointfiles
node_weights -->|"loads checkpoint"| node_checkpointfiles
node_single -->|"prints score"| node_user
node_batch -->|"writes scores"| node_scorefiles
node_batch -->|"computes metrics"| node_metrics
node_batch -->|"reads scores"| node_scorefiles
node_paradigm -.->|"conditions generations"| node_stable
node_paradigm -.->|"informs dataset"| node_trainingdata
node_user -->|"downloads data"| node_trainingdata
node_user -->|"downloads data"| node_viraldata
node_user -->|"downloads data"| node_generatordata

click node_single "https://github.com/grip-unina/b-free/blob/main/code/main_bfree_single.py"
click node_batch "https://github.com/grip-unina/b-free/blob/main/code/main_bfree.py"
click node_normalization "https://github.com/grip-unina/b-free/blob/main/code/utils/normalization.py"
click node_scorefiles "https://github.com/grip-unina/b-free/blob/main/code/main_bfree.py"
click node_metrics "https://github.com/grip-unina/b-free/blob/main/code/utils/dmetrics.py"
click node_factory "https://github.com/grip-unina/b-free/blob/main/code/networks/__init__.py"
click node_weights "https://github.com/grip-unina/b-free/blob/main/code/networks/__init__.py"
click node_cropmodel "https://github.com/grip-unina/b-free/blob/main/code/networks/wrapper5crops.py"
click node_paradigm "https://github.com/grip-unina/b-free/tree/main/code"
click node_trainingdata "https://github.com/grip-unina/b-free/tree/main/training_data"
click node_viraldata "https://github.com/grip-unina/b-free/tree/main/viral_images_dataset"

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_single,node_batch,node_normalization,node_scorefiles,node_metrics toneBlue
class node_factory,node_weights,node_cropmodel,node_checkpointfiles toneAmber
class node_paradigm,node_trainingdata,node_viraldata,node_generatordata toneMint
class node_user,node_stable toneIndigo
```

## Components

### Detection workflow

- [Single-image scoring](https://github.com/grip-unina/b-free/blob/main/code/main_bfree_single.py): `code/main_bfree_single.py`
- [CSV inference](https://github.com/grip-unina/b-free/blob/main/code/main_bfree.py): `code/main_bfree.py`
- [Image normalization](https://github.com/grip-unina/b-free/blob/main/code/utils/normalization.py): `code/utils/normalization.py`
- [Score CSV](https://github.com/grip-unina/b-free/blob/main/code/main_bfree.py): `code/main_bfree.py`
- [Detection metrics](https://github.com/grip-unina/b-free/blob/main/code/utils/dmetrics.py): `code/utils/dmetrics.py`

### Model internals

- [Network factory](https://github.com/grip-unina/b-free/blob/main/code/networks/__init__.py): `code/networks/__init__.py`
- [Checkpoint loading](https://github.com/grip-unina/b-free/blob/main/code/networks/__init__.py): `code/networks/__init__.py`
- [Five-crop detector](https://github.com/grip-unina/b-free/blob/main/code/networks/wrapper5crops.py): `code/networks/wrapper5crops.py`
- **Model config and weights**

### Data and methodology

- [Bias-free training paradigm](https://github.com/grip-unina/b-free/tree/main/code): `code`
- [Training dataset](https://github.com/grip-unina/b-free/tree/main/training_data): `training_data`
- [Viral image dataset](https://github.com/grip-unina/b-free/tree/main/viral_images_dataset): `viral_images_dataset`
- **New-generator dataset**

### Other components

- **Analyst**
- **Stable Diffusion 2.1**

## Connections

- Analyst → Single-image scoring: submits image (evidence: `code/main_bfree_single.py`)
- Analyst → CSV inference: submits CSV (evidence: `code/main_bfree.py`)
- Single-image scoring → Image normalization: normalizes image (evidence: `code/main_bfree_single.py`)
- CSV inference → Image normalization: normalizes images (evidence: `code/main_bfree.py`)
- Single-image scoring → Network factory: creates network (evidence: `code/main_bfree_single.py`)
- CSV inference → Network factory: creates network (evidence: `code/main_bfree.py`)
- Single-image scoring → Checkpoint loading: loads weights (evidence: `code/main_bfree_single.py`)
- CSV inference → Checkpoint loading: loads weights (evidence: `code/main_bfree.py`)
- Network factory → Five-crop detector: wraps backbone (evidence: `code/networks/__init__.py`)
- Single-image scoring → Model config and weights: reads config (evidence: `code/main_bfree_single.py`)
- CSV inference → Model config and weights: reads config (evidence: `code/main_bfree.py`)
- Checkpoint loading → Model config and weights: loads checkpoint (evidence: `code/networks/__init__.py`)
- Single-image scoring → Analyst: prints score (evidence: `code/main_bfree_single.py`)
- CSV inference → Score CSV: writes scores (evidence: `code/main_bfree.py`)
- CSV inference → Detection metrics: computes metrics (evidence: `code/main_bfree.py`)
- CSV inference → Score CSV: reads scores (evidence: `code/main_bfree.py`)
- Bias-free training paradigm → Stable Diffusion 2.1: conditions generations (evidence: `README.md`)
- Bias-free training paradigm → Training dataset: informs dataset (evidence: `README.md`)
- Analyst → Training dataset: downloads data (evidence: `README.md`)
- Analyst → Viral image dataset: downloads data (evidence: `README.md`)
- Analyst → New-generator dataset: downloads data (evidence: `README.md`)
