SpaceTeknopoliVision v3 (“Reka Nišava”): Building a Sovereign C++20 & PyTorch Computer Vision Engine From Scratch

Zero external classic CV libraries, 0.46 ms single-pass SIMD preprocessing, evolving from a 7-stage Hybrid Neuro-Transformer to a 2.18 MB detector, and real multi-hardware telemetry from RTX GPUs to physical Raspberry Pi 5.

Press enter or click to view image in full size
SpaceTeknopoliVision v3 (“Reka Nišava”) — a sovereign C++20 and PyTorch computer vision ecosystem scaling across RTX GPUs, x86 servers, desktop OSes (Linux/Windows/macOS), and edge silicon.
SpaceTeknopoliVision v3 (“Reka Nišava”) — a sovereign C++20 and PyTorch computer vision ecosystem scaling across RTX GPUs, x86 servers, desktop OSes (Linux/Windows/macOS), and edge silicon.

Most real-time computer vision stacks are stitched together from loosely coupled pieces: an external image processing library for decoding and resizing, a deep learning runtime, ad-hoc post-processing scripts, and custom deployment wrappers. That works well for notebooks — until you deploy into dense, occluded agricultural canopies, continuous industrial streams, or memory-constrained edge devices.

Suddenly, copying every 1080p frame across DRAM three times for resize, letterbox, and normalization saturates memory bandwidth. Long training runs suffer opaque memory creep across operating systems. And at operational confidence thresholds (conf=0.25), detectors collapse to zero detections on dense clusters of sub-32×32 px targets.

SpaceTeknopoliVision (STV) was built from scratch in C++20 and PyTorch to solve this stack vertically — with zero external classic computer vision library dependencies. Because the core engine and our inaugural v3 detector family were written in Niš, Serbia, we codenamed our first v3 family “Reka Nišava” after the Nišava River flowing through the city.

One misconception worth clearing up immediately: STV is not a Raspberry Pi 5-only toy. It is a multi-platform vision runtime verified across NVIDIA RTX workstations (54.54 FPS, 17.62 W), multi-core Linux and Windows x86_64 servers (52.64 FPS 16T / 42.69 FPS 4T ONNX), Apple Silicon desktops, and physical Raspberry Pi 5 / ARM64 edge hardware.

1. Zero External CV Dependencies: FusedISP, 42 Native STV-CV Ops, and Cross-Platform Memory Governance

On both edge silicon and high-throughput CPUs, preprocessing is often half the latency budget. Instead of running resize, letterbox padding, and uint8 → float32 CHW normalization in three separate memory passes, FusedISPfuses all three into a single ARM NEON / x86 AVX2 vectorized C++20 kernel — cutting 1920×1080 → 640×640 preprocessing to ~0.46 ms.

Intermediate buffers come from a 64-byte cache-line aligned O(1) bump-pointer ArenaPool (single pointer reset per frame, zero heap fragmentation) and cross into PyTorch via DLPack with 0 memcpy. Alongside FusedISP sits STV-CV: 42deterministic native C++20 operators across six canonical domains (Geometry, Filtering, Morphology/CCL, Color, Motion, and PDE/Spectral).

Press enter or click to view image in full size
Single-pass FusedISP SIMD preprocessing (ARM NEON / x86 AVX2), 64-byte ArenaPool, zero-copy DLPack, and 42 deterministic native C++20 STV-CV operators.
Single-pass FusedISP SIMD preprocessing (ARM NEON / x86 AVX2), 64-byte ArenaPool, zero-copy DLPack, and 42 deterministic native C++20 STV-CV operators.

Cross-Platform Dual-Layer Memory Gatekeeper (macOS · Linux · Windows)

Standard POSIX getrusage() only returns historical peak memory on macOS and cannot observe real-time reclamation. In core_cpp/src/core/memory_gatekeeper.cpp, stv::core::MemoryGatekeeperqueries instantaneous kernel-level resident memory across all three major operating systems and triggers active reclamation at 90% of the configured budget:

  • macOS (__APPLE__): task_info(mach_task_self(), TASK_VM_INFO)(phys_footprint) + resident_size_max+ malloc_zone_pressure_relief().
  • Linux (__linux__ — x86_64 & ARM64 / Pi 5): /proc/self/statm × sysconf(_SC_PAGESIZE) + /proc/self/status (VmHWM) + malloc_trim(0).
  • Windows (_WIN32 — MSVC 2022): <windows.h> + <psapi.h>GetProcessMemoryInfo(GetCurrentProcess())(WorkingSetSize and PeakWorkingSetSize).

On the Python training side, O(1) zero-copy ModelEMA.swap() swaps tensor data pointers in place with zero extra allocation.

2. Inside STV-Net: From 7-Stage Hybrid Neuro-Transformer (v2) to "Reka Nišava" (v3)

Both generations live inside the same unified build_stvnet() factory (9model scales spanning 1.045M to 62.90Mparameters):

STV-Net v2–7-Stage Hybrid Neuro-Transformer (stv_net/model.py)

Our v2 architecture integrates true Transformer and multi-scale attention blocks directly into a compact detector:

  • Stage 3 (STVLinearFormerBlock): Combines 2D Rotary Positional Embeddings (2D-RoPE) with O(N)O(N)FocusedLinearAttention at H/16 × W/16, stabilized by Spectral Covariance Regularization(attn_cov_matrix).
  • Stage 4 (STVGlobalTransformerBlock): Full Pre-RMSNorm + SwiGLU global Transformer block with cached 2D Sinusoidal Positional Encoding at H/32 × W/32.
  • Stage 6 (STVDeformDecoder): IoU-aware dynamic query selection (100–500queries), nn.MultiheadAttention, MultiScaleDeformableAttention subpixel cross-attention, and a Contrastive Denoising (CDN) block-diagonal attention mask during training (0 inference overhead).
  • Attention Adapters & Transformer LoRA: CoordinateAttention2d, CVFeatureAdapter (gated classical CV + neuro-transformer feature fusion), and LoRA (stv_net/training/lora.py) injected into Linear Attention projections, Transformer QKV, and FFN layers.

STV-Net v3 — “Reka Nišava” (stv_net/model_v3.py)

To dramatically boost dense small-object recall (<32×32 px) and CPU/Edge throughput, v3 ("Reka Nišava") introduces four focused upgrades:

  1. Algebraic RepConv & DWRepBlock Folding (fuse()): Multi-branch training blocks (3×3 + 1×1 + Identity BN) fold losslessly into a single 3×3 conv at export (Nano v3: 2.39M train → 1.13M deploy params; Small v3: 7.31M → 3.92M).
  2. Lossless SPDConvP2ToP3 & P5-Pruned STVBiFPNLite: Prunes 35–40% of large-object P5 channels while injecting high-resolution P2 edge features into P3 via lossless 2×2 Space-to-Depth slicing.
  3. NMS-Free DualAssignHead (o2m + o2o): Parallel o2m + o2o training heads; o2m is permanently pruned at export.
  4. CWD + Logit/DFL Knowledge Distillation: Compresses STVNet-Small v3(7.50 MB) into STVNet-Nano v3(2.18 MB) while retaining 100.0% of teacher Test mAP@50 (0.6374 vs. 0.6373).
Press enter or click to view image in full size
Training convergence across the 7-model benchmark illustrating the architectural leap from STVNet v2 (Hybrid Neuro-Transformer) to STVNet v3 (“Reka Nišava”).
Training convergence across the 7-model benchmark illustrating the architectural leap from STVNet v2 (Hybrid Neuro-Transformer) to STVNet v3 (“Reka Nišava”).

3. Transparent 7-Model Benchmark on Dense Unseen Field Scenes

All 7 models — including respected reference baselines YOLO26n and YOLO26s— were evaluated under identical COCO 101-point AP matching on 100 unseen agricultural test images (seed=42, 1024×1024, 4,010 GT objects). Our curated FirstDataset v3 (12,868 files, 12 verified CC BY 4.0 Roboflow Universe sources + 300 0-byte hard-negative background frames mined from Pexels #40310690) is openly published with full attribution.

Press enter or click to view image in full size
STVNet-Nano v3 (“Reka Nišava” KD · 2.18 MB) qualitative output on an unseen dense raspberry canopy frame (Buds, Flowers, Unripe, raspberry).
STVNet-Nano v3 (“Reka Nišava” KD · 2.18 MB) qualitative output on an unseen dense raspberry canopy frame (Buds, Flowers, Unripe, raspberry).

Looking at the numbers objectively:

  • Reference YOLO26s and YOLO26n lead in overall mAP@50 (0.6890), mAP@50-95 (0.4119), and precision (74.7%).
  • STVNet-Nano v3 ("Reka Nišava" KD) leads where dense field reliability and compactness matter most:
  • 2.18 MB (.stvm FP16) / 1.38 MB (ONNX INT8) deploy footprint,
  • 0.5282 F1 at conf=0.25,
  • 61.4% dense canopy recall (≥15 GT/image) and 55.1% small-object recall,
  • 0 / 100 zero-detection failures (100% frame coverage).
  • STVNet-Small v3 ONNX INT8 (1024×1024) reaches 0.6545 mAP@50 in just 4.21 MB.
Press enter or click to view image in full size
Dense canopy recall (≥15 GT/image) and zero-detection reliability across all 7 models at operational confidence threshold c=0.25.
Dense canopy recall (≥15 GT/image) and zero-detection reliability across all 7 models at operational confidence threshold c=0.25.

4. Multi-Hardware Reality: RTX A5000, x86 Servers, and Physical Raspberry Pi 5

  • NVIDIA RTX A5000 GPU: STVNet-Nano v3 runs at 54.54 FPS while drawing just 17.62 W average GPU power and 54.5 MB peak PyTorch VRAM (Small v3: 53.15 FPS).
  • x86_64 Servers & Desktops (ONNX Runtime): 52.64 FPS on 16-thread CPU and 42.69 FPS (23.4 ms) on 4-thread edge CPU (640×640 FP32).
  • .stvm + AES-256-GCM: 128-byte header zero-copy mmap container with optional authenticated weight encryption for commercial/OEM delivery.
Press enter or click to view image in full size
Hardware telemetry comparing GPU latency, power draw (W), energy per image (mJ), VRAM, and isolated CPU FPS across all 7 models.
Hardware telemetry comparing GPU latency, power draw (W), energy per image (mJ), VRAM, and isolated CPU FPS across all 7 models.

To stress-test constrained edge headroom, we also trained STVNet-Nano v3("Reka Nišava") directly on a physical Raspberry Pi 5 CPU (ARM Cortex-A76, no GPU accelerator):

  • 20-epoch on-device CPU training: Completed in 2.35 hours under 0.86 GB peak RAM(ActiveMemoryGovernor + step-level resume).
  • On-device inference: 23.89 FPS ONNX (416) and 11.81 FPS live 720p.stvm video (100% frame detection coverage).
Press enter or click to view image in full size
Physical Raspberry Pi 5 unit used to verify on-device CPU training and live edge video inference.
Physical Raspberry Pi 5 unit used to verify on-device CPU training and live edge video inference.
Press enter or click to view image in full size
Physical Raspberry Pi 5 on-device training, ONNX FP32/INT8 latency, and live .stvm video inference telemetry.
Physical Raspberry Pi 5 on-device training, ONNX FP32/INT8 latency, and live .stvm video inference telemetry.

5. Practical Usage: Start in 3 Lines of Python or CLI

from huggingface_hub import hf_hub_download
from spaceteknopolivision.engine.vision_engine import VisionEngine

weights = hf_hub_download("denizzhansahin/SpaceTeknopoliVision", "weights/stvnet_nano_v3_kd.stvm")
engine = VisionEngine(weights, conf=0.25, device="auto") # CUDA / MPS / CPU
result = engine.predict("greenhouse_frame.jpg")
result.save("output.jpg")

Or via the unified CLI:

stv predict --model weights/stvnet_nano_v3_kd.stvm --source greenhouse_frame.jpg --conf 0.25
stv train --data FirstDataset/data.yaml --model small_v3 --imgsz 1024 --epochs 300 --max-memory auto
stv export --weights weights/stvnet_nano_v3_kd.stvm --output nano_v3_640.onnx --format onnx --imgsz 640 --int8
Press enter or click to view image in full size
Multi-dimensional radar scorecard balancing accuracy, dense recall, zero-detection reliability, footprint, speed, and power efficiency.
Multi-dimensional radar scorecard balancing accuracy, dense recall, zero-detection reliability, footprint, speed, and power efficiency.

6. Scientific Transparency, License, and Live Resources

Through v3 (“Reka Nišava”), Object Detection is our officially field-verified and benchmarked task. Instance segmentation, spatial robotic intelligence (SpatialSession, SLAM, Vision-RAG), temporal state caching (TFC/TSC), and the optional read-only MCP bridge are openly shared in the repository as Community Preview pending multi-site field validation.

SpaceTeknopoliVision is released under STV-PRAL v2: free for non-commercial personal learning and student projects with attribution; commercial deployments and external academic publications/theses require prior written permission from Denizhan Şahin (denizhan@linksphere.tr · mobilhaber2025@gmail.com).

Explore & Test Live

Have questions about FusedISP SIMD, our Hybrid Neuro-Transformer layers, or training directly on a Raspberry Pi 5? Drop a comment below!

Daha yeni Daha eski