How thienannguyen-cv/smap works
1. Repository purpose and shape
- This is a Python/PyTorch library, not a full application stack.
- The repo is centered on a core package, smap, with supporting notebooks, tests, docs, and release automation.
- The library’s main job is to transform 2D tensor representations using camera/geometry information to support the project’s “dynamic 3D inference” experiments.
2. Core runtime boundary: smap/
- smap is the production package that consumers import.
- The public entry points are exposed through smap/__init__.py, which the README shows as SMap and SMap3x3.
- This package is the architectural center: everything else either supports it, validates it, or demonstrates it.
3. Main computation layer
- smap/smap.py appears to hold the primary spatial-mapping implementation.
- The README’s quick start shows the core data flow: a tensor shaped like (N, C, H, W) plus camera intrinsics/affine-style matrix information is passed into SMap, producing a mapped output tensor.
- smap/specials.py likely contains special-case logic or optimized variants used by the main mapper.
4. Geometric/rectification subsystem
- smap/rectify.py is a distinct support layer for geometric correction or coordinate adjustment.
- This suggests the library separates “build the mapping” from “rectify/normalize the spatial relationship,” which is important when drawing the architecture: one branch for core mapping, another for geometry helpers.
- smap/utils.py provides shared helpers used across these modules.
5. Two operational modes: general and 3x3-specialized
- The README explicitly highlights both SMap and SMap3x3.
- SMap is the general spatial-mapping path; SMap3x3 is a constrained specialization for a 3-by-3 neighborhood of directional targets.
- The existence of a dedicated tests/test_vtest_data/smap3x3/ fixture set indicates the specialized mode is a first-class architectural branch, not just a minor parameter change.
6. Data flow through the library
- Inputs are typically PyTorch tensors, while camera metadata and matrices are NumPy-based in the documented usage.
- The core flow is: tensor input → mapping/rectification logic → transformed output tensor.
- The repo also stores intermediate-style artifacts such as masks, expected outputs, and a flow_info.pkl, indicating that spatial flow/field information is part of the internal representation or validation path.
7. Validation strategy: unit tests plus visual/regression tests
- tests/utest_rectify.py, tests/utest_smap.py, and tests/utest_smap3x3.py cover the main library surfaces.
- tests/vtest_data/ contains fixed .npy fixtures and expected outputs for regression-style verification, especially around spatial behavior.
- This means correctness is checked not just by numeric function outputs, but by comparing stored spatial artifacts and expected mapped representations.
8. Documentation and research context
- docs/ contains repository documentation and a knowledge-graph-style description of the project’s theory.
- The docs are tied to the research framing rather than product UX, which matches the repo’s role as an explainable scientific library.
- VERSIONING.md and the README emphasize release/version discipline appropriate for a publishable package.
9. Application layer: notebooks as consumers of the core library
- applications/Camera Calibration/ and applications/Depth Estimation/ are example projects built on top of the package.
- They use Jupyter notebooks and dataset-specific assets, showing that the repo supports experimental workflows and demos rather than a single runtime app.
- These notebooks are downstream consumers of smap, not part of the package’s internal runtime.
10. External data dependencies
- The applications reference external datasets: Sky-dataset for camera calibration and Lamp-dataset for depth estimation.
- Dataset artifacts and model checkpoints live alongside the notebooks, reinforcing that these are research experiments with local assets rather than service endpoints.
- The applications/Depth Estimation/model_0_0.pth and CSV histories show training/evaluation artifacts for a learned component within the demo workflow.
11. Tooling and test harnesses
- tools/testing/ contains additional infrastructure for validation, including a separate vtest harness and an hdvo execution environment.
- This suggests the repo has a layered test story: standard pytest-style unit tests plus a more specialized visual/interactive test runner for notebook-derived workflows.
- These tools are auxiliary and do not affect the library’s public API, but they matter for understanding how the project is verified.
12. Packaging and release pipeline
- setup.py, requirements.txt, and environment.yml define the installable Python package and its reproducible environment.
- GitHub Actions workflows (ci.yml, cd.yml, pypi-publish.yml) indicate automated testing and publishing to PyPI.
- Architecturally, this repo is built to ship as a reusable library artifact, with notebooks and docs as companion layers.
13. How to draw the architecture
- Put smap at the center.
- Show applications/ as downstream notebook-based consumers that call into SMap/SMap3x3.
- Show tests/ and tools/testing/ as validation and regression layers around the core.
- Show docs and CI/CD as supporting infrastructure around the package lifecycle, not part of runtime execution.
Main entry points: __init__.py Public API · smap.py SMap · specials.py SMap3x3 · rectify.py Rectify
Components 17
Core package
Installable Python package that implements the spatial mapping runtime.
- Public API · Exports the library’s main classes for consumers.
smap/__init__.py - SMap · Primary spatial mapping implementation for tensor-to-tensor transformation.
smap/smap.py - SMap3x3 · Constrained 3x3 mapping variant used as a first-class operational mode.
smap/specials.py - Rectify · Geometric correction and coordinate adjustment layer.
smap/rectify.py - Utils · Shared helpers used by the core mapping and geometry modules.
smap/utils.py
Validation
Unit tests, regression fixtures, and specialized test harnesses.
- Rectify tests · Covers geometric correction behavior.
tests/utest_rectify.py - SMap tests · Covers the general spatial mapping path.
tests/utest_smap.py - 3x3 tests · Covers the specialized 3x3 mapping path.
tests/utest_smap3x3.py - VTest fixtures · Stored tensors, masks, and expected outputs for spatial regression checks.
tests/vtest_data - Flow info · Serialized flow/field metadata used by tests and validation.
tests/test_flow_info.pkl - VTest harness · Notebook-driven visual/regression test environment.
tools/testing/vtest - HDVO env · Specialized execution environment supporting visual testing workflows.
tools/testing/hdvo
Applications
Notebook-based downstream experiments that consume the library.
- Camera calib · Notebook experiment for camera calibration built on the library.
applications/Camera Calibration/camera-calibration.ipynb - Depth est. · Notebook experiment for depth estimation built on the library.
applications/Depth Estimation/depth-estimation.ipynb
Support
Docs, packaging, and release automation around the package lifecycle.
- Docs · Project theory, usage notes, and architecture-oriented documentation.
docs - Packaging · Package metadata and environment definition for installation and reproducibility.
setup.py - Release CI · Continuous integration, deployment, and PyPI publishing workflows.
.github/workflows
Connections 18
- Public API → SMap: exports · Public entry point exposes the primary mapper.
- Public API → SMap3x3: exports · Public entry point exposes the specialized mapper.
- SMap → Rectify: uses · General mapping relies on geometric correction.
- SMap → Utils: uses · Shares helpers for core runtime logic.
- SMap3x3 → Rectify: uses · Specialized mapping also depends on rectification/geometry.
- SMap3x3 → Utils: uses · Shares helper routines with the core package.
- Rectify tests → Rectify: validates · Unit tests exercise geometric correction behavior.
- SMap tests → SMap: validates · Unit tests cover the main mapping path.
- 3x3 tests → SMap3x3: validates · Unit tests cover the 3x3 specialization.
- VTest fixtures → 3x3 tests: fixtures for · Regression artifacts support the specialized visual tests.
- Flow info → SMap tests: fixtures for · Serialized flow data supports validation of mapping behavior.
- VTest harness → VTest fixtures: drives · Harness consumes stored representations and expected outputs.
- HDVO env → VTest harness: supports · Execution environment runs the visual test workflow.
- Camera calib → Public API: consumes · Notebook experiment calls into the public API.
- Depth est. → Public API: consumes · Notebook experiment calls into the public API.
- Docs → Public API: describes · Documentation explains the package and its theory.
- Packaging → Public API: packages · Build metadata turns the core library into an installable distribution.
- Release CI → Packaging: publishes · CI/CD workflows test and publish release artifacts.