How bnnr-team/bnnr works
1. Repository shape
- This is a Python package centered on src/bnnr, with a separate React/Vite dashboard in dashboard_web.
- The package ships a built dashboard bundle under src/bnnr/dashboard/frontend/dist, so the Python runtime can serve the UI without rebuilding it.
2. Primary product boundary
- BNNR is a closed-loop vision workflow: train a model, analyze failures with XAI, generate improved augmentations, then validate and report the result.
- The core architectural boundary is between the training/analysis engine in Python and the interactive dashboard/reporting layer.
3. Entry points and orchestration
- python -m bnnr is the main CLI surface (src/bnnr/cli.py, __main__.py).
- Key CLI flows are training, reporting, dataset/augmentation/preset listing, and dashboard serving/export.
- quick_run, pipelines, and core/craft appear to be the main orchestration modules that stitch together configuration, training, evaluation, and artifact generation.
4. Configuration and runtime control
- BNNRConfig in config.py is the central contract for experiment settings.
- The README and tests suggest it drives dataset selection, task type, metrics, pruning, checkpoint/report paths, device choice, seeds, XAI toggles, and iteration limits.
- This config layer is the main boundary between user intent and the rest of the system.
5. Task adapters and model integration
- adapter.py, detection_adapter.py, and lightning_adapter.py in examples indicate an adapter-based design for plugging in custom models and dataloaders.
- The repo supports multiple task families with different data/metric paths: single-label classification, multilabel classification, and object detection.
- Detection has its own specialized modules for collation, metrics, augmentations, and XAI, which implies a separate sub-pipeline rather than a thin wrapper over classification.
6. Augmentation subsystem
- Augmentation logic is a major subsystem: augmentations.py, albumentations_aug.py, kornia_aug.py, detection_augmentations.py, and augmentation_runner.py.
- The architecture supports both CPU-style augmentation integration and GPU-accelerated augmentation via Kornia, with Albumentations as an optional integration.
- This subsystem is part of the feedback loop: selected augmentations are applied, measured, and then fed back into improved training runs.
7. XAI, analysis, and candidate selection
- xai.py, xai_analysis.py, xai_cache.py, detection_xai.py, and data_quality.py indicate a pipeline for explanation generation and reuse.
- XAI outputs are not just visual artifacts; they appear to influence augmentation choice, candidate pruning, and reporting.
- The cache layer suggests explanations can be expensive and are reused across iterations or dashboard views.
8. Metrics, eventing, and reporting
- metrics are collected per task and per class, with dedicated modules like detection_metrics.py, taskMetrics.py, and several dashboard components for confusion, deltas, accuracy gain, and training-time breakdown.
- events.py likely provides the structured event stream used to track pipeline progress and feed UI/report generation.
- reporting.py plus the README’s report.json flow indicate a structured artifact model: the training run emits machine-readable results that are later summarized or visualized.
9. Dashboard backend and static delivery
- src/bnnr/dashboard/backend.py, exporter.py, and serve.py implement the Python-side dashboard service.
- The dashboard backend serves run artifacts and exposes them to the frontend; the exporter can package a run into a standalone dashboard directory.
- The UI is not a generic monitoring tool; it is a read-only visualization layer over run artifacts, explanations, and metrics.
10. Dashboard frontend architecture
- dashboard_web is a TypeScript/React app built with Vite.
- Components are purpose-built around model-analysis views: branch graphs, candidate radar, confusion matrix/chord, per-class metrics, loss landscape, augmentation preview/impact/stack, XAI trend/quality, and node detail panels.
- The frontend consumes a run state model (useRunState, types.ts) and task-specific metric helpers, so it is tightly coupled to the report/run schema produced by Python.
11. Packaging and deployment path
- The default install path is pure Python; the dashboard is optional via extra dependencies.
- For development, the dashboard must be built before editable install, which shows that the Python package embeds the web build artifact rather than compiling it at runtime.
- The bundled frontend plus FastAPI/Uvicorn backend means the dashboard can run locally from a single Python process.
12. Examples and supported workflows
- examples/ provides runnable demos and notebooks for classification, detection, and multilabel tasks, plus YAML configs for reproducible scenarios.
- These examples are part of the architecture because they encode the supported integration pattern: config-driven runs with task-specific adapters and pipelines.
13. Testing and quality boundaries
- The test suite covers contracts, config, core pipeline behavior, dashboard backend/export/serve, detection, XAI, pause/resume, metrics, and regression scenarios.
- This breadth suggests the project treats the pipeline, artifacts, and dashboard schema as stable interfaces that need end-to-end validation.
14. Overall data flow
- User config and CLI input start a training run.
- The pipeline builds adapters, datasets, augmentations, and metrics for the selected task.
- Training emits structured events, checkpoints, XAI results, and report artifacts.
- Those artifacts power both static reports and the live dashboard, which visualizes run state and supports export/serve modes.
Main entry points: core.py Core · cli.py CLI · pipelines.py Pipelines · backend.py Dashboard backend
Components 22
Python runtime
Core package, orchestration, analysis, and packaged dashboard backend
- CLI · Main command surface for training, reporting, listing, and dashboard commands
src/bnnr/cli.py - Module entry · python -m bnnr entry hook
src/bnnr/__main__.py - Config · Central experiment and runtime settings contract
src/bnnr/config.py - Quick run · High-level shortcut for launching standard workflows
src/bnnr/quick_run.py - Pipelines · Task and iteration flow coordination across training and analysis
src/bnnr/pipelines.py - Core · Primary training and evaluation execution logic
src/bnnr/core.py - Craft · Artifact generation and experiment assembly utilities
src/bnnr/craft.py - Adapters · Base adapter boundary for custom models and dataloaders
src/bnnr/adapter.py - Detection adapter · Detection-specific model and data integration
src/bnnr/detection_adapter.py - Augmentations · Augmentation selection and application for feedback loops
src/bnnr/augmentations.py - Augment backends · Albumentations, Kornia, and detection augmentation implementations
src/bnnr/albumentations_aug.py - XAI · Explanation generation, analysis, caching, and quality scoring
src/bnnr/xai.py - Events · Structured run events used for progress and artifact tracking
src/bnnr/events.py - Reporting · Run summaries and machine-readable report output
src/bnnr/reporting.py - Dashboard backend · Python-side API for serving run artifacts to the UI
src/bnnr/dashboard/backend.py - Dashboard export · Packages a run into a standalone dashboard directory
src/bnnr/dashboard/exporter.py - Dashboard serve · Local dashboard serving process
src/bnnr/dashboard/serve.py - Bundled UI · Built frontend shipped inside the Python package
src/bnnr/dashboard/frontend/dist/index.html
Dashboard web
Source React app and bundled static frontend
Examples
Runnable task demos and config-driven usage patterns
- Examples · Task demos and reproducible configuration examples
examples/README.md
Connections 23
- Module entry → CLI: boots · Module entry hands control to the CLI
- CLI → Config: loads · CLI resolves experiment settings from the central config
- CLI → Quick run: dispatches · Common one-shot workflows are routed through quick run helpers
- CLI → Pipelines: starts · CLI invokes pipeline orchestration for full runs
- Pipelines → Core: executes · Pipelines coordinate training and evaluation in the core engine
- Pipelines → Craft: builds · Pipelines assemble artifacts and run outputs
- Core → Adapters: uses · Core execution depends on the adapter boundary for model and data integration
- Core → Detection adapter: specializes · Detection tasks use a specialized adapter path
- Core → Augmentations: applies · Training uses augmentation strategy selection and execution
- Augmentations → Augment backends: backs · Augmentation logic delegates to concrete backends
- Core → XAI: analyzes · Core run produces explanations and analysis inputs
- XAI → Augmentations: feeds · XAI and quality analysis influence augmentation choice in the feedback loop
- Core → Events: emits · Training and evaluation emit structured lifecycle events
- Core → Reporting: writes · Core run outputs report artifacts and summaries
- Reporting → Dashboard backend: powers · Reports and artifacts are consumed by the dashboard backend
- Dashboard backend → Dashboard export: packages · Backend data can be exported as a standalone dashboard
- Dashboard backend → Dashboard serve: serves · Backend supports live local serving
- Dashboard serve → Bundled UI: loads · Serving uses the bundled static frontend shipped in the package
- Web app → Run state: reads · UI renders from the run-state and metric model
- Web app → UI views: composes · App is assembled from analysis and reporting views
- Bundled UI → Web app: built from · Packaged assets are built from the dashboard source application
- Examples → Config: demonstrates · Examples encode reproducible config-driven usage
- Examples → Adapters: shows · Examples illustrate custom adapter integration