Files
ruvnet--RuView/v2/crates/wifi-densepose-train/src/model.rs
T
rUv 17471e93ff ADR-152: WiFi-Pose SOTA 2026 intake — WiFlow-STD benchmark, Rust integrations, ADR-153 802.11bf layer, efficiency frontier (#1008)
* feat(calibration): NodeGeometry transceiver-geometry recording (ADR-152 §2.1.1)

PerceptAlign-motivated geometry capture at enrollment: per-node optional
records (position, antenna orientation, inter-node distances, acquisition
method) — recorded when known, never required. Event-sourced via
EnrollmentEvent::GeometryRecorded (latest recording wins); persisted on
SpecialistBank with serde defaults so pre-ADR-152 bank JSON loads cleanly
(fixture-proven, and geometry-free banks serialize byte-shape-identical
to the old schema); threaded through MultiNodeMixture as data only — the
learned geometry embeddings and algorithmic fusion use are §2.1.2,
deliberately deferred until the ADR-151 P6 LoRA heads exist.

Geometry recorded from now on means banks captured today remain usable
for layout-conditioned training later — you can't retroactively add
geometry to data you didn't record.

8 new tests (3 geometry, 2 anchor, 2 bank, 1 multistatic) + full-loop
extension (2-node geometry, one tape-measured + one unknown, surviving
the bank JSON round-trip the runtime loads from). 50/50 calibration
(both feature configs) + 23 CLI tests green.

Co-Authored-By: RuFlo <ruv@ruv.net>

* feat(training): two-checkerboard camera↔room calibration for ADR-079 labels (ADR-152 §2.1.3)

Defends the camera-supervised pipeline against PerceptAlign's
"coordinate overfitting": MediaPipe keypoints were emitted in raw camera
coordinates with no shared frame and no transceiver-geometry metadata —
the exact label shape that memorizes deployment layout and collapses
cross-layout.

- scripts/calibrate-camera-room.py + calibration_lib.py: OpenCV
  two-checkerboard calibration → versioned bundle JSON (intrinsics,
  camera→room extrinsics, checkerboard spec, transceiver geometry,
  sha256 calibration_id). Intrinsics resolve from file > cache >
  multi-view computation > loud-warning 2-view fallback.
- collect-ground-truth.py --calibration <bundle>: every sample gains
  keypoints_room (unit bearing rays from the camera center in the room
  frame — documented projective alignment; raw image coords preserved
  so training chooses), camera_origin_room, calibration_id, and the
  transceiver geometry stamp. Without the flag, output is byte-identical
  to before (tested) + a one-line ADR-152 warning.

Design finding (recorded for ADR-152): a single planar checkerboard's
corner grid is centrosymmetric — the reversed corner ordering fits a
ghost camera pose with IDENTICAL reprojection error, so per-board flip
disambiguation is mathematically ill-posed. solve_two_board_extrinsics
solves the joint wall+floor set over all 4 flip combinations, where the
minimum is unique — an independent reason the TWO-checkerboard method is
required, beyond what PerceptAlign states.

15 headless pytest tests green (synthetic corners: extrinsics recovery
incl. ghost resolution, bundle round-trip + hash stability, ray
transforms w/ distortion + cross-resolution, no-calibration byte
identity).

Co-Authored-By: RuFlo <ruv@ruv.net>

* feat(benchmarks): WiFlow-STD reproduction harness + measurement (a) results (ADR-152 §2.2)

Shipped checkpoint REFUTED (0.08% PCK@20, wrong keypoint normalization);
6 reproducibility defects documented (broken imports, corrupted dataset
tail with float32-max garbage that NaN-poisons fp16 BatchNorm, unreachable
test phase). After repairs, retraining with upstream defaults reproduces
96.09% PCK@20 full-test / 96.61% corruption-free (published 97.25%) on
RTX 5080. Claims graded MEASURED-EQUIVALENT; 2.23M params + ~0.055 GFLOPs
verified. Third-party code/weights/data stay out of tree (gitignored).

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat: ADR-152 Rust integrations + ADR-153 802.11bf protocol model

- calibration: GeometryEmbedding — 32-slot permutation-invariant NodeGeometry
  featurization for future LoRA-head conditioning (ADR-152 §2.1.2); derived
  SpecialistBank::geometry_embedding() accessor; 59 tests
- train: MaePretrainConfig + patchify/random-mask with UNSW measured recipe
  (80% masking, (30,3) patches; ADR-152 §2.3, arXiv 2511.18792); strict
  no-truncate/no-NaN policy; proptest properties
- train: WiFlowStdModel — tch-gated port of the verified ~96%-PCK@20
  WiFlow-STD architecture (ADR-152 §2.2 beyond-SOTA); ungated param formula
  pinned to 2,225,042; 15/17-keypoint support; 239 crate tests
- hardware: ieee80211bf forward-compatibility protocol model (ADR-153):
  SpecProfile gates, SensingCapabilities negotiation, required ConsentMode,
  session FSM, SensingTransport + SimTransport + OpportunisticCsiBridge;
  full acceptance checklist covered; 156+4 tests
- deps: ruvector bumps per ADR-152 §2.6 survey (mincut/solver 2.0.6,
  attention 2.1.0, gnn 2.2.0); vendor/ruvector synced to a083bd77f
- docs: ADR-153 accepted; ADR-152 §2.2 status, §2.4 amendment, §2.6 added

Workspace: 162 test suites green (--no-default-features); Python proof PASS.
Known pre-existing flake: homecore-api env_empty_falls_back_to_defaults
(unserialized env-var mutation) — untouched, follow-up.

Co-Authored-By: claude-flow <ruv@ruv.net>

* docs: CHANGELOG + CLAUDE.md entries for ADR-152 integrations and ADR-153

Co-Authored-By: claude-flow <ruv@ruv.net>

* fix(train): repair tch-backend bit-rot — gated path compiles and tests run again

Mechanical API refresh against current tch: Vec::from(Tensor) -> try_from
(+ explicit flatten), numel() usize cast, Rem/div ops -> remainder() /
divide_scalar_mode(floor) — the latter fixed a silent true-division bug in
heatmap argmax decoding; clamp(1.0, f64::MAX) -> clamp_min (torch 2.x scalar
overflow panic); petgraph EdgeRef import; missing EvalMetrics and
verify_checkpoint_dir APIs that tests documented. wiflow_std roundtrip test
uses safetensors (.pt _save_parameters roundtrip broken in torch 2.11
Windows). Gated: 349 passed (incl. all 20 wiflow_std); ungated: unchanged.
Known pre-existing: gaussian-heatmap convention mismatch (2 tests), proof
seed race under parallel threads — documented, deliberate follow-ups.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(train): WiFlow-STD PyTorch->tch weight import + numerical parity proof

export_to_safetensors.py maps the retrained checkpoint (295 tensors -> 248
mapped, param sum exactly 2,225,042; num_batches_tracked dropped) into a
tch-loadable safetensors plus a deterministic parity fixture. Gated #[ignore]
integration test loads it strictly and asserts forward-pass agreement:
max abs diff 1.192e-7 on the seed-42 fixture. dump_variable_names test makes
the tch name layout authoritative. Zero architecture discrepancies found.

Co-Authored-By: claude-flow <ruv@ruv.net>

* fix: workflow-review findings — BN gamma init, ThresholdParams serde, init docs

Concurrent validation workflow (2 review lanes + adversarial verification,
13 agents): 5 confirmed findings, 3 refuted. Fixes:
- wiflow_std: pin BatchNorm gamma to 1.0 (tch default draws Uniform(0,1) —
  silently halves activations in from-scratch training; loaded checkpoints
  unaffected, parity re-verified after the change)
- wiflow_std: document the conv-init divergences vs the reference's
  effective kaiming_normal(fan_out) re-init (from-scratch dynamics only)
- ieee80211bf: ThresholdParams deserialization validates via try_from so
  the <=100 invariant holds for untrusted payloads (+ rejection test)

Benchmarks (release, ruvzen): GeometryEmbedding 1.84us/call (542k/s),
MAE tokenization 7.38us/window (135k/s), 802.11bf FSM 8.9M events/s —
nothing suspicious.

Co-Authored-By: claude-flow <ruv@ruv.net>

* docs(adr): ADR-152 §2.1.4 gate resolved — PerceptAlign repo MIT, dataset on HF

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(benchmarks): edge optimization measured + measurement (b) blocked + 92.9% retraction

Edge optimization (ADR-152 optimize track): ONNX Runtime fp32 is the CPU
latency win (3.2 ms/window, ~3.4x faster than torch, parity 2.4e-7); ORT
dynamic int8 reaches 2.44 MB (paper's ~2.2 MB claim plausible only via
conv-capable toolchains; -0.16pt PCK@20, +18% MPJPE, 2x slower); torch
dynamic quant converts 0% of this conv-only model; fp16 halves storage free
but is slower on CPU.

Measurement (b) BLOCKED-ON-DATA: only 1,077 paired ESP32 windows exist
(stop rule <2k). Forensic recheck of the surviving April holdout RETRACTS
the ADR-079 '92.9% PCK@20' figure: constant-output model, absolute (not
torso) threshold, 69 near-static frames — mean predictor scores 100% under
that protocol; torso-PCK@20 is 19.1%. Corroborates PR #535. Stale citations
removed from user-guide, readme-details, ADR-152 §2.1.3; no-citation rule
extended to ADR-079 accuracy claims. Unblock: >=2k-window multi-pose paired
session + torso-PCK re-baseline.

Co-Authored-By: claude-flow <ruv@ruv.net>

* docs(user-guide): corrected camera-supervised collection tutorial

Step 0 CSI-rate check + session-length math (window yield = frames/20 —
the May session's 8x under-delivery was a ~12 Hz CSI rate, not an aligner
bug); two-checkerboard calibration step (ADR-152 §2.1.3); pose-variety and
confidence guidance; torso-normalized PCK + temporal-split + pred-variance
eval protocol (lessons from the 92.9% retraction); scale presets re-keyed
to realistic window counts.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(benchmarks): static PTQ int8 (calibrated) results + overnight capture script

Conv-only static QDQ beats dynamic int8 on accuracy (PCK@20 96.61-96.63%
vs 96.52%, MPJPE +10% vs +18% over fp32) at ~equal size/latency; all-ops
QDQ strictly worse (int8 activations through attention glue). Entropy
calibration verified bit-identical to MinMax on this data. Deployment:
ONNX fp32 for speed (3.2ms), static conv-only QDQ for smallest (2.53MB).

Also: scripts/overnight-empty-capture.py — segmented UDP CSI recorder for
empty-room baselines (no glob collisions, detach-safe).

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(benchmarks): measurement (b) MEASURED — optimization transfer only, mean-pose baseline wins

WiFlow-STD fine-tuned on 2,046 fresh single-room ESP32 paired windows
(temporal 70/15/15, 70->540 adapter, K=17): pretrained-init 65% PCK@20 vs
scratch 0% (optimization transfer) but frozen-trunk ~0% (no feature
transfer), and NOTHING beats the mean-pose baseline (95.9% PCK@20 —
single subject, near-static normalized coords). Honesty gates held: pred
std 0.0113 (non-constant model) but mean-baseline dominance means no
citable CSI->pose capability from this data. ADR-152 open question 1
answered partially; definitive answer needs multi-subject/position data.

Two new aligner findings: heterogeneous csi_shape with silent zero-padding
(~20%), and extractCsiMatrix's transposed shape label (frame-major data,
[nSc, nFrames] label) — fixes pending.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(benchmarks): efficiency sweep MEASURED — half model dominates full reference

Compact WiFlow-STD variants on the same data/split/protocol: half (843,834
params, 0.38x) strictly dominates the 2.23M reference (PCK@20 96.62 vs
96.61, PCK@50 99.47 vs 99.11, MPJPE 0.00898 vs 0.0094) — the published
architecture is over-parameterized for its own benchmark. quarter (338k)
96.05%; tiny (56,290 params, 1/39.5) holds 94.11% — a ~220KB fp32 edge
candidate. In-domain caveats recorded; cross-domain untested.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(train): compact WiFlow-STD presets in Rust + tiny edge artifact (ADR-152)

WiFlowStdConfig gains half()/quarter()/tiny() mirroring the overnight sweep
exactly: TcnGroupsMode (Fixed/Gcd/Depthwise), input_pw_groups, derived
stride schedule and decoder-mid (all default to upstream behavior; legacy
serde JSON unaffected). Param formulas pin to trained ground truth first
try: 843,834 / 338,600 / 56,290; default 2,225,042 pin and 1.192e-7 parity
unchanged. 248 tests green.

Tiny edge artifact (tiny_edge_bench.py): ONNX fp32 = 295 KB, 0.66 ms/win
(~1,500/s CPU), 94.11% PCK@20 (matches sweep clean-test exactly; parity
1.49e-7). Static int8 is a bad trade at this scale (-1.43pt, +19% MPJPE,
-16% size, slower) — recorded as negative result. Export note: width-16
breaks AdaptiveAvgPool((15,1)) TorchScript export; replaced by exact
mean+matmul equivalent, proven by parity.

Co-Authored-By: claude-flow <ruv@ruv.net>

* fix: resolve all 10 confirmed code-review findings (7-angle review, 20/20 verified)

wiflow_std: min_feature_width (default 15) replaces the keypoints->stride
coupling — for_keypoints(17) now provably builds the trained [2,2,2,2]
graph and pools 15->17, matching the validated Python protocol (pinned by
tests); param_count() total on invalid configs; random_mask returns Result
and rejects non-finite/out-of-range ratios; trainer checkpoints switched
to safetensors (.pt VarStore roundtrip broken on Windows torch 2.11).

ieee80211bf: SBP proxy now re-triggers instances and relays reports via
Action::RelaySbpReport -> SensingFrame::SbpReport (clients consume via
their existing path); missed_instances reset on success = consecutive
semantics; SessionTable gains a guarded SBP entry point + unknown-id drop
counter; initiator-role sessions reject inbound setup/SBP requests
(RejectedNotSupported) closing the idle hijack; StartSetup/StartSbp
outside Idle return InvalidStateForCommand; SBP validation unified
through evaluate_setup with a 1:1 SetupStatus->SbpStatus mapping.
events.rs split out to honor the 500-line cap.

calibration/cli: enrollment geometry now actually reaches trained banks —
both production call sites attach .with_geometry; --geometry flag on
train-room and POST /enroll/geometry + train-body geometry on
calibrate-serve give production a recording surface; geometry-free banks
log the ADR-152 §2.1.2 note.

benchmarks: corruption masks committed as ground truth (unregenerable
after in-place cleaning; verified bit-identical regeneration from the
pristine copy) + generate_corruption_masks.py producer; _bench_common.py
dedups the 5x-copied shim/evaluate/seed/remap (post-refactor PCK@20
re-verified equal to the last digit); remote scripts get the mmap patch;
tiny_edge --calib validated multiple-of-64; onnx_bench --help no longer
executes (and overwrote) the export — artifact restored byte-exact.

Workspace: 2,963 tests passed, 0 failed; Python proof PASS.

Co-Authored-By: claude-flow <ruv@ruv.net>

* ci: build workspace tests without debuginfo — runner disk exhaustion

The combined 38-crate debug target exceeds the GitHub runner's disk
('final link failed: No space left on device'); the same tree measured
151GB locally with full debuginfo. CARGO_PROFILE_{DEV,TEST}_DEBUG=0
shrinks the target ~5-10x; debuginfo serves no purpose in CI test runs.

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-06-11 17:02:23 -04:00

1021 lines
35 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! End-to-end WiFi-DensePose model (tch-rs / LibTorch backend).
//!
//! Architecture (following CMU arXiv:2301.00250):
//!
//! ```text
//! amplitude [B, T*tx*rx, sub] ─┐
//! ├─► ModalityTranslator ─► [B, 3, 48, 48]
//! phase [B, T*tx*rx, sub] ─┘ │
//! ▼
//! ResNet18-like backbone
//! │
//! ┌──────────┴──────────┐
//! ▼ ▼
//! KeypointHead DensePoseHead
//! [B,17,H,W] heatmaps [B,25,H,W] parts
//! [B,48,H,W] UV
//! ```
//!
//! Sub-networks are instantiated once in [`WiFiDensePoseModel::new`] and
//! stored as struct fields so layer weights persist correctly across forward
//! passes. A lazy `forward_impl` reconstruction approach is intentionally
//! avoided here.
//!
//! # No pre-trained weights
//!
//! Weights are initialised from scratch (Kaiming uniform, default from tch).
//! Pre-trained ImageNet weights are not loaded because network access is not
//! guaranteed during training runs.
use std::path::Path;
use tch::{nn, nn::Module, nn::ModuleT, Device, Kind, Tensor};
use ruvector_attention::attention::ScaledDotProductAttention;
use ruvector_attention::traits::Attention;
use ruvector_attn_mincut::attn_mincut;
use crate::config::TrainingConfig;
use crate::error::TrainError;
// ---------------------------------------------------------------------------
// Public output type
// ---------------------------------------------------------------------------
/// Outputs produced by a single forward pass of [`WiFiDensePoseModel`].
#[derive(Debug)]
pub struct ModelOutput {
/// Keypoint heatmaps: `[B, 17, H, W]`.
pub keypoints: Tensor,
/// Body-part logits (24 parts + background): `[B, 25, H, W]`.
pub part_logits: Tensor,
/// UV surface coordinates (24 × 2 channels): `[B, 48, H, W]`.
pub uv_coords: Tensor,
/// Backbone feature map for cross-modal transfer loss: `[B, 256, H/4, W/4]`.
pub features: Tensor,
}
// ---------------------------------------------------------------------------
// WiFiDensePoseModel
// ---------------------------------------------------------------------------
/// End-to-end WiFi-DensePose model.
///
/// Input CSI tensors have shape `[B, T * n_tx * n_rx, n_sub]`.
/// All sub-networks are built once at construction and stored as fields so
/// their parameters persist correctly across calls.
pub struct WiFiDensePoseModel {
vs: nn::VarStore,
translator: ModalityTranslator,
backbone: Backbone,
kp_head: KeypointHead,
dp_head: DensePoseHead,
/// Active training configuration.
pub config: TrainingConfig,
}
impl WiFiDensePoseModel {
/// Build a new model with randomly-initialised weights on `device`.
///
/// Call `tch::manual_seed(seed)` before this for reproducibility.
pub fn new(config: &TrainingConfig, device: Device) -> Self {
let vs = nn::VarStore::new(device);
let root = vs.root();
// Compute the flattened CSI input size used by the modality translator.
let n_ant = (config.window_frames * config.num_antennas_tx * config.num_antennas_rx) as i64;
let n_sc = config.num_subcarriers as i64;
let flat_csi = n_ant * n_sc;
let num_parts = config.num_body_parts as i64;
let translator = ModalityTranslator::new(&root / "translator", flat_csi, n_ant, n_sc);
let backbone = Backbone::new(&root / "backbone", config.backbone_channels as i64);
let kp_head = KeypointHead::new(
&root / "kp_head",
config.backbone_channels as i64,
config.num_keypoints as i64,
);
let dp_head = DensePoseHead::new(
&root / "dp_head",
config.backbone_channels as i64,
num_parts,
);
WiFiDensePoseModel {
vs,
translator,
backbone,
kp_head,
dp_head,
config: config.clone(),
}
}
/// Forward pass in training mode (dropout / batch-norm in train mode).
///
/// # Arguments
///
/// - `amplitude`: `[B, T*n_tx*n_rx, n_sub]`
/// - `phase`: `[B, T*n_tx*n_rx, n_sub]`
pub fn forward_t(&self, amplitude: &Tensor, phase: &Tensor) -> ModelOutput {
self.forward_impl(amplitude, phase, true)
}
/// Forward pass without gradient tracking (inference mode).
pub fn forward_inference(&self, amplitude: &Tensor, phase: &Tensor) -> ModelOutput {
tch::no_grad(|| self.forward_impl(amplitude, phase, false))
}
/// Save model weights to a file. The tch `VarStore` dispatches the format
/// on the file extension: `.safetensors` → safetensors, anything else →
/// torch `.pt`.
///
/// **Platform constraint:** prefer `.safetensors`. The `.pt` path
/// (`_save_parameters`/`_load_parameters`) is broken on Windows with
/// torch 2.11 (GenericDict internal assert on the load roundtrip — see
/// `wiflow_std/model.rs::save_and_load_roundtrip`), which is why
/// [`crate::trainer::Trainer`] writes `.safetensors` checkpoints.
///
/// # Errors
///
/// Returns [`TrainError::TrainingStep`] if the file cannot be written.
pub fn save(&self, path: &Path) -> Result<(), TrainError> {
self.vs
.save(path)
.map_err(|e| TrainError::training_step(format!("save failed: {e}")))
}
/// Load model weights from a file (format dispatched on extension; see
/// the `.pt`-on-Windows caveat on [`Self::save`]).
///
/// # Errors
///
/// Returns [`TrainError::TrainingStep`] if the file cannot be read or the
/// weights are incompatible with this model's architecture.
pub fn load(&mut self, path: &Path) -> Result<(), TrainError> {
self.vs
.load(path)
.map_err(|e| TrainError::training_step(format!("load failed: {e}")))
}
/// Return a reference to the internal `VarStore` (e.g. to build an
/// optimiser).
pub fn varstore(&self) -> &nn::VarStore {
&self.vs
}
/// Mutable access to the internal `VarStore`.
pub fn varstore_mut(&mut self) -> &mut nn::VarStore {
&mut self.vs
}
/// Alias for [`varstore`](Self::varstore) — matches the `var_store` naming
/// convention used by the training loop.
pub fn var_store(&self) -> &nn::VarStore {
&self.vs
}
/// Alias for [`varstore_mut`](Self::varstore_mut).
pub fn var_store_mut(&mut self) -> &mut nn::VarStore {
&mut self.vs
}
/// Alias for [`forward_t`](Self::forward_t) kept for compatibility with
/// the training-loop code.
pub fn forward_train(&self, amplitude: &Tensor, phase: &Tensor) -> ModelOutput {
self.forward_t(amplitude, phase)
}
/// Total number of trainable scalar parameters.
pub fn num_parameters(&self) -> i64 {
self.vs
.trainable_variables()
.iter()
.map(|t| t.numel() as i64)
.sum()
}
// ------------------------------------------------------------------
// Internal implementation
// ------------------------------------------------------------------
fn forward_impl(&self, amplitude: &Tensor, phase: &Tensor, train: bool) -> ModelOutput {
let cfg = &self.config;
// ── Phase sanitization (differentiable, no learned params) ───────
let clean_phase = phase_sanitize(phase);
// ── Flatten antenna×time×subcarrier dimensions ───────────────────
let batch = amplitude.size()[0];
let flat_amp = amplitude.reshape([batch, -1]);
let flat_phase = clean_phase.reshape([batch, -1]);
// ── Modality translator: CSI → pseudo spatial image ──────────────
// Output: [B, 3, 48, 48]
let spatial = self.translator.forward_t(&flat_amp, &flat_phase, train);
// ── ResNet-style backbone ─────────────────────────────────────────
// Output: [B, backbone_channels, H', W']
let features = self.backbone.forward_t(&spatial, train);
// ── Keypoint head ─────────────────────────────────────────────────
let hs = cfg.heatmap_size as i64;
let keypoints = self.kp_head.forward_t(&features, hs, train);
// ── DensePose head ────────────────────────────────────────────────
let (part_logits, uv_coords) = self.dp_head.forward_t(&features, hs, train);
ModelOutput {
keypoints,
part_logits,
uv_coords,
features,
}
}
}
// ---------------------------------------------------------------------------
// Phase sanitizer (no learned parameters)
// ---------------------------------------------------------------------------
/// Differentiable phase sanitization via subcarrier-differential method.
///
/// Computes first-order differences along the subcarrier axis to cancel
/// common-mode phase drift (carrier frequency offset, sampling offset).
///
/// Input: `[B, T*n_ant, n_sub]`
/// Output: `[B, T*n_ant, n_sub]` (zero-padded on the left)
fn phase_sanitize(phase: &Tensor) -> Tensor {
let n_sub = phase.size()[2];
if n_sub <= 1 {
return phase.zeros_like();
}
// φ_clean[k] = φ[k] - φ[k-1] for k > 0; φ_clean[0] = 0
let later = phase.slice(2, 1, n_sub, 1);
let earlier = phase.slice(2, 0, n_sub - 1, 1);
let diff = later - earlier;
let zeros = Tensor::zeros(
[phase.size()[0], phase.size()[1], 1],
(Kind::Float, phase.device()),
);
Tensor::cat(&[zeros, diff], 2)
}
// ---------------------------------------------------------------------------
// ruvector attention helpers
// ---------------------------------------------------------------------------
/// Apply min-cut gated attention over the antenna-path dimension.
///
/// Treats each antenna path as a "token" and subcarriers as the feature
/// dimension. Uses `attn_mincut` to gate irrelevant antenna-pair correlations,
/// which is equivalent to automatic antenna selection.
///
/// # Arguments
///
/// - `x`: CSI tensor `[B, n_ant, n_sc]` — amplitude or phase
/// - `lambda`: min-cut threshold (0.3 = moderate pruning)
///
/// # Returns
///
/// Attended tensor `[B, n_ant, n_sc]` with irrelevant antenna paths suppressed.
fn apply_antenna_attention(x: &Tensor, lambda: f32) -> Tensor {
let sizes = x.size();
let n_ant = sizes[1];
let n_sc = sizes[2];
// Skip trivial cases where attention is a no-op.
if n_ant <= 1 || n_sc <= 1 {
return x.shallow_clone();
}
let b = sizes[0] as usize;
let n_ant_usize = n_ant as usize;
let n_sc_usize = n_sc as usize;
let device = x.device();
let kind = x.kind();
// Process each batch element independently (attn_mincut operates on 2D inputs).
let mut results: Vec<Tensor> = Vec::with_capacity(b);
for bi in 0..b {
// Extract [n_ant, n_sc] slice for this batch element.
let xi = x.select(0, bi as i64); // [n_ant, n_sc]
// Move to CPU and convert to f32 for the pure-Rust attention kernel.
let flat: Vec<f32> = Vec::<f32>::try_from(
xi.to_kind(Kind::Float)
.to_device(Device::Cpu)
.flatten(0, -1),
)
.expect("antenna tensor to vec");
// Q = K = V = the antenna features (self-attention over antenna paths).
let out = attn_mincut(
&flat, // q: [n_ant * n_sc]
&flat, // k: [n_ant * n_sc]
&flat, // v: [n_ant * n_sc]
n_sc_usize, // d: feature dim = n_sc subcarriers
n_ant_usize, // seq_len: number of antenna paths
lambda, // lambda: min-cut threshold
1, // tau: no temporal hysteresis (single-frame)
1e-6, // eps: numerical epsilon
);
let attended = Tensor::from_slice(&out.output)
.reshape([n_ant, n_sc])
.to_device(device)
.to_kind(kind);
results.push(attended);
}
Tensor::stack(&results, 0) // [B, n_ant, n_sc]
}
/// Apply scaled dot-product attention over spatial locations.
///
/// Input: `[B, C, H, W]` feature map — each spatial location (H×W) becomes a
/// token; C is the feature dimension. Captures long-range spatial dependencies
/// between antenna-footprint regions.
///
/// Returns `[B, C, H, W]` with spatial attention applied.
///
/// This function can be applied after backbone features when long-range spatial
/// context is needed. It is defined here for completeness and may be called
/// from head implementations or future backbone variants.
#[allow(dead_code)]
fn apply_spatial_attention(x: &Tensor) -> Tensor {
let sizes = x.size();
let (b, c, h, w) = (sizes[0], sizes[1], sizes[2], sizes[3]);
let n_spatial = (h * w) as usize;
let d = c as usize;
let device = x.device();
let kind = x.kind();
let attn = ScaledDotProductAttention::new(d);
let mut results: Vec<Tensor> = Vec::with_capacity(b as usize);
for bi in 0..b {
// Extract [C, H*W] and transpose to [H*W, C].
let xi = x.select(0, bi).reshape([c, h * w]).transpose(0, 1); // [H*W, C]
let flat: Vec<f32> = Vec::<f32>::try_from(
xi.to_kind(Kind::Float)
.to_device(Device::Cpu)
.flatten(0, -1),
)
.expect("spatial tensor to vec");
// Build token slices — one per spatial position.
let tokens: Vec<&[f32]> = (0..n_spatial).map(|i| &flat[i * d..(i + 1) * d]).collect();
// For each spatial token as query, compute attended output.
let mut out_flat = vec![0.0f32; n_spatial * d];
for i in 0..n_spatial {
let query = &flat[i * d..(i + 1) * d];
match attn.compute(query, &tokens, &tokens) {
Ok(attended) => {
out_flat[i * d..(i + 1) * d].copy_from_slice(&attended);
}
Err(_) => {
// Fallback: identity — keep original features unchanged.
out_flat[i * d..(i + 1) * d].copy_from_slice(query);
}
}
}
let out_tensor = Tensor::from_slice(&out_flat)
.reshape([h * w, c])
.transpose(0, 1) // [C, H*W]
.reshape([c, h, w]) // [C, H, W]
.to_device(device)
.to_kind(kind);
results.push(out_tensor);
}
Tensor::stack(&results, 0) // [B, C, H, W]
}
// ---------------------------------------------------------------------------
// Modality Translator
// ---------------------------------------------------------------------------
/// Translates flattened (amplitude, phase) CSI vectors into a pseudo-image.
///
/// ```text
/// amplitude [B, flat_csi] ─► attn_mincut ─► amp_fc1 ► relu ► amp_fc2 ► relu ─┐
/// ├─► fuse_fc ► reshape ► spatial_conv ► [B, 3, 48, 48]
/// phase [B, flat_csi] ─► attn_mincut ─► ph_fc1 ► relu ► ph_fc2 ► relu ─┘
/// ```
///
/// The `attn_mincut` step performs self-attention over the antenna-path dimension
/// (`n_ant` tokens, each with `n_sc` subcarrier features) to gate out irrelevant
/// antenna-pair correlations before the FC fusion layers.
struct ModalityTranslator {
amp_fc1: nn::Linear,
amp_fc2: nn::Linear,
ph_fc1: nn::Linear,
ph_fc2: nn::Linear,
fuse_fc: nn::Linear,
// Spatial refinement conv layers
sp_conv1: nn::Conv2D,
sp_bn1: nn::BatchNorm,
sp_conv2: nn::Conv2D,
/// Number of antenna paths: T * n_tx * n_rx (used for attention reshape).
n_ant: i64,
/// Number of subcarriers per antenna path (used for attention reshape).
n_sc: i64,
}
impl ModalityTranslator {
fn new(vs: nn::Path, flat_csi: i64, n_ant: i64, n_sc: i64) -> Self {
let amp_fc1 = nn::linear(&vs / "amp_fc1", flat_csi, 512, Default::default());
let amp_fc2 = nn::linear(&vs / "amp_fc2", 512, 256, Default::default());
let ph_fc1 = nn::linear(&vs / "ph_fc1", flat_csi, 512, Default::default());
let ph_fc2 = nn::linear(&vs / "ph_fc2", 512, 256, Default::default());
// Fuse 256+256 → 3*48*48
let fuse_fc = nn::linear(&vs / "fuse_fc", 512, 3 * 48 * 48, Default::default());
// Two conv layers that mix spatial information in the pseudo-image.
let sp_conv1 = nn::conv2d(
&vs / "sp_conv1",
3,
32,
3,
nn::ConvConfig {
padding: 1,
bias: false,
..Default::default()
},
);
let sp_bn1 = nn::batch_norm2d(&vs / "sp_bn1", 32, Default::default());
let sp_conv2 = nn::conv2d(
&vs / "sp_conv2",
32,
3,
3,
nn::ConvConfig {
padding: 1,
..Default::default()
},
);
ModalityTranslator {
amp_fc1,
amp_fc2,
ph_fc1,
ph_fc2,
fuse_fc,
sp_conv1,
sp_bn1,
sp_conv2,
n_ant,
n_sc,
}
}
fn forward_t(&self, amp: &Tensor, ph: &Tensor, train: bool) -> Tensor {
let b = amp.size()[0];
// === ruvector-attn-mincut: gate irrelevant antenna paths ===
//
// Reshape from [B, flat_csi] to [B, n_ant, n_sc], apply min-cut
// self-attention over the antenna-path dimension (antenna paths are
// "tokens", subcarrier responses are "features"), then flatten back.
let amp_3d = amp.reshape([b, self.n_ant, self.n_sc]);
let ph_3d = ph.reshape([b, self.n_ant, self.n_sc]);
let amp_attended = apply_antenna_attention(&amp_3d, 0.3);
let ph_attended = apply_antenna_attention(&ph_3d, 0.3);
let amp_flat = amp_attended.reshape([b, -1]); // [B, flat_csi]
let ph_flat = ph_attended.reshape([b, -1]); // [B, flat_csi]
// Amplitude branch (uses attended input)
let a = amp_flat
.apply(&self.amp_fc1)
.relu()
.dropout(0.2, train)
.apply(&self.amp_fc2)
.relu();
// Phase branch (uses attended input)
let p = ph_flat
.apply(&self.ph_fc1)
.relu()
.dropout(0.2, train)
.apply(&self.ph_fc2)
.relu();
// Fuse and reshape to spatial map
let fused = Tensor::cat(&[a, p], 1) // [B, 512]
.apply(&self.fuse_fc) // [B, 3*48*48]
.view([b, 3, 48, 48])
.relu();
// Spatial refinement
let out = fused
.apply(&self.sp_conv1)
.apply_t(&self.sp_bn1, train)
.relu()
.apply(&self.sp_conv2)
.tanh(); // bound to [-1, 1] before backbone
out
}
}
// ---------------------------------------------------------------------------
// Backbone
// ---------------------------------------------------------------------------
/// ResNet18-compatible backbone.
///
/// ```text
/// Input: [B, 3, 48, 48]
/// Stem: Conv2d(3→64, k=3, s=1, p=1) + BN + ReLU → [B, 64, 48, 48]
/// Layer1: 2 × BasicBlock(64→64, stride=1) → [B, 64, 48, 48]
/// Layer2: 2 × BasicBlock(64→128, stride=2) → [B, 128, 24, 24]
/// Layer3: 2 × BasicBlock(128→256, stride=2) → [B, 256, 12, 12]
/// Output: [B, out_channels, 12, 12]
/// ```
struct Backbone {
stem_conv: nn::Conv2D,
stem_bn: nn::BatchNorm,
// Layer 1
l1b1: BasicBlock,
l1b2: BasicBlock,
// Layer 2
l2b1: BasicBlock,
l2b2: BasicBlock,
// Layer 3
l3b1: BasicBlock,
l3b2: BasicBlock,
}
impl Backbone {
fn new(vs: nn::Path, out_channels: i64) -> Self {
let stem_conv = nn::conv2d(
&vs / "stem_conv",
3,
64,
3,
nn::ConvConfig {
padding: 1,
bias: false,
..Default::default()
},
);
let stem_bn = nn::batch_norm2d(&vs / "stem_bn", 64, Default::default());
Backbone {
stem_conv,
stem_bn,
l1b1: BasicBlock::new(&vs / "l1b1", 64, 64, 1),
l1b2: BasicBlock::new(&vs / "l1b2", 64, 64, 1),
l2b1: BasicBlock::new(&vs / "l2b1", 64, 128, 2),
l2b2: BasicBlock::new(&vs / "l2b2", 128, 128, 1),
l3b1: BasicBlock::new(&vs / "l3b1", 128, out_channels, 2),
l3b2: BasicBlock::new(&vs / "l3b2", out_channels, out_channels, 1),
}
}
fn forward_t(&self, x: &Tensor, train: bool) -> Tensor {
let x = self
.stem_conv
.forward(x)
.apply_t(&self.stem_bn, train)
.relu();
let x = self.l1b1.forward_t(&x, train);
let x = self.l1b2.forward_t(&x, train);
let x = self.l2b1.forward_t(&x, train);
let x = self.l2b2.forward_t(&x, train);
let x = self.l3b1.forward_t(&x, train);
self.l3b2.forward_t(&x, train)
}
}
// ---------------------------------------------------------------------------
// BasicBlock
// ---------------------------------------------------------------------------
/// ResNet BasicBlock with optional projection shortcut.
///
/// ```text
/// x ── Conv2d(s) ── BN ── ReLU ── Conv2d(1) ── BN ──┐
/// │ +── ReLU
/// └── (1×1 Conv+BN if in_ch≠out_ch or stride≠1) ───┘
/// ```
struct BasicBlock {
conv1: nn::Conv2D,
bn1: nn::BatchNorm,
conv2: nn::Conv2D,
bn2: nn::BatchNorm,
downsample: Option<(nn::Conv2D, nn::BatchNorm)>,
}
impl BasicBlock {
fn new(vs: nn::Path, in_ch: i64, out_ch: i64, stride: i64) -> Self {
let conv1 = nn::conv2d(
&vs / "conv1",
in_ch,
out_ch,
3,
nn::ConvConfig {
stride,
padding: 1,
bias: false,
..Default::default()
},
);
let bn1 = nn::batch_norm2d(&vs / "bn1", out_ch, Default::default());
let conv2 = nn::conv2d(
&vs / "conv2",
out_ch,
out_ch,
3,
nn::ConvConfig {
padding: 1,
bias: false,
..Default::default()
},
);
let bn2 = nn::batch_norm2d(&vs / "bn2", out_ch, Default::default());
let downsample = if in_ch != out_ch || stride != 1 {
let ds_conv = nn::conv2d(
&vs / "ds_conv",
in_ch,
out_ch,
1,
nn::ConvConfig {
stride,
bias: false,
..Default::default()
},
);
let ds_bn = nn::batch_norm2d(&vs / "ds_bn", out_ch, Default::default());
Some((ds_conv, ds_bn))
} else {
None
};
BasicBlock {
conv1,
bn1,
conv2,
bn2,
downsample,
}
}
fn forward_t(&self, x: &Tensor, train: bool) -> Tensor {
let residual = match &self.downsample {
Some((ds_conv, ds_bn)) => ds_conv.forward(x).apply_t(ds_bn, train),
None => x.shallow_clone(),
};
let out = self.conv1.forward(x).apply_t(&self.bn1, train).relu();
let out = self.conv2.forward(&out).apply_t(&self.bn2, train);
(out + residual).relu()
}
}
// ---------------------------------------------------------------------------
// Keypoint Head
// ---------------------------------------------------------------------------
/// Predicts per-joint Gaussian heatmaps.
///
/// ```text
/// Input: [B, in_channels, H', W']
/// ► Conv2d(in→256, 3×3, p=1) + BN + ReLU
/// ► Conv2d(256→128, 3×3, p=1) + BN + ReLU
/// ► Conv2d(128→num_keypoints, 1×1)
/// ► upsample_bilinear2d → [B, num_keypoints, heatmap_size, heatmap_size]
/// ```
struct KeypointHead {
conv1: nn::Conv2D,
bn1: nn::BatchNorm,
conv2: nn::Conv2D,
bn2: nn::BatchNorm,
out_conv: nn::Conv2D,
}
impl KeypointHead {
fn new(vs: nn::Path, in_ch: i64, num_kp: i64) -> Self {
let conv1 = nn::conv2d(
&vs / "conv1",
in_ch,
256,
3,
nn::ConvConfig {
padding: 1,
bias: false,
..Default::default()
},
);
let bn1 = nn::batch_norm2d(&vs / "bn1", 256, Default::default());
let conv2 = nn::conv2d(
&vs / "conv2",
256,
128,
3,
nn::ConvConfig {
padding: 1,
bias: false,
..Default::default()
},
);
let bn2 = nn::batch_norm2d(&vs / "bn2", 128, Default::default());
let out_conv = nn::conv2d(&vs / "out_conv", 128, num_kp, 1, Default::default());
KeypointHead {
conv1,
bn1,
conv2,
bn2,
out_conv,
}
}
fn forward_t(&self, x: &Tensor, heatmap_size: i64, train: bool) -> Tensor {
let h = x
.apply(&self.conv1)
.apply_t(&self.bn1, train)
.relu()
.apply(&self.conv2)
.apply_t(&self.bn2, train)
.relu()
.apply(&self.out_conv);
h.upsample_bilinear2d(&[heatmap_size, heatmap_size], false, None, None)
}
}
// ---------------------------------------------------------------------------
// DensePose Head
// ---------------------------------------------------------------------------
/// Predicts body-part segmentation and continuous UV surface coordinates.
///
/// ```text
/// Input: [B, in_channels, H', W']
///
/// Shared trunk:
/// ► Conv2d(in→256, 3×3, p=1) + BN + ReLU
/// ► Conv2d(256→256, 3×3, p=1) + BN + ReLU
/// ► upsample_bilinear2d → [B, 256, out_size, out_size]
///
/// Part branch: Conv2d(256→num_parts+1, 1×1) → part logits
/// UV branch: Conv2d(256→num_parts*2, 1×1) → sigmoid → UV ∈ [0,1]
/// ```
struct DensePoseHead {
shared_conv1: nn::Conv2D,
shared_bn1: nn::BatchNorm,
shared_conv2: nn::Conv2D,
shared_bn2: nn::BatchNorm,
part_out: nn::Conv2D,
uv_out: nn::Conv2D,
}
impl DensePoseHead {
fn new(vs: nn::Path, in_ch: i64, num_parts: i64) -> Self {
let shared_conv1 = nn::conv2d(
&vs / "shared_conv1",
in_ch,
256,
3,
nn::ConvConfig {
padding: 1,
bias: false,
..Default::default()
},
);
let shared_bn1 = nn::batch_norm2d(&vs / "shared_bn1", 256, Default::default());
let shared_conv2 = nn::conv2d(
&vs / "shared_conv2",
256,
256,
3,
nn::ConvConfig {
padding: 1,
bias: false,
..Default::default()
},
);
let shared_bn2 = nn::batch_norm2d(&vs / "shared_bn2", 256, Default::default());
// num_parts + 1: 24 body-part classes + 1 background class
let part_out = nn::conv2d(&vs / "part_out", 256, num_parts + 1, 1, Default::default());
// num_parts * 2: U and V channel for each of the 24 body parts
let uv_out = nn::conv2d(&vs / "uv_out", 256, num_parts * 2, 1, Default::default());
DensePoseHead {
shared_conv1,
shared_bn1,
shared_conv2,
shared_bn2,
part_out,
uv_out,
}
}
/// Returns `(part_logits, uv_coords)`.
fn forward_t(&self, x: &Tensor, out_size: i64, train: bool) -> (Tensor, Tensor) {
let f = x
.apply(&self.shared_conv1)
.apply_t(&self.shared_bn1, train)
.relu()
.apply(&self.shared_conv2)
.apply_t(&self.shared_bn2, train)
.relu();
// Upsample shared features to output resolution
let f = f.upsample_bilinear2d(&[out_size, out_size], false, None, None);
let parts = f.apply(&self.part_out);
// Sigmoid constrains UV predictions to [0, 1]
let uv = f.apply(&self.uv_out).sigmoid();
(parts, uv)
}
}
// ---------------------------------------------------------------------------
// Tests
// ---------------------------------------------------------------------------
#[cfg(test)]
mod tests {
use super::*;
use crate::config::TrainingConfig;
use tch::Device;
fn tiny_config() -> TrainingConfig {
let mut cfg = TrainingConfig::default();
cfg.num_subcarriers = 8;
cfg.window_frames = 4;
cfg.num_antennas_tx = 1;
cfg.num_antennas_rx = 1;
cfg.heatmap_size = 12;
cfg.backbone_channels = 64;
cfg.num_epochs = 2;
cfg.warmup_epochs = 1;
cfg
}
#[test]
fn model_forward_output_shapes() {
tch::manual_seed(0);
let cfg = tiny_config();
let device = Device::Cpu;
let model = WiFiDensePoseModel::new(&cfg, device);
let batch = 2_i64;
let antennas = (cfg.num_antennas_tx * cfg.num_antennas_rx * cfg.window_frames) as i64;
let n_sub = cfg.num_subcarriers as i64;
let amp = Tensor::ones([batch, antennas, n_sub], (Kind::Float, device));
let ph = Tensor::zeros([batch, antennas, n_sub], (Kind::Float, device));
let out = model.forward_t(&amp, &ph);
// Keypoints: [B, 17, heatmap_size, heatmap_size]
assert_eq!(out.keypoints.size()[0], batch);
assert_eq!(out.keypoints.size()[1], cfg.num_keypoints as i64);
assert_eq!(out.keypoints.size()[2], cfg.heatmap_size as i64);
assert_eq!(out.keypoints.size()[3], cfg.heatmap_size as i64);
// Part logits: [B, num_body_parts+1, heatmap_size, heatmap_size]
assert_eq!(out.part_logits.size()[0], batch);
assert_eq!(out.part_logits.size()[1], (cfg.num_body_parts + 1) as i64);
// UV: [B, num_body_parts*2, heatmap_size, heatmap_size]
assert_eq!(out.uv_coords.size()[0], batch);
assert_eq!(out.uv_coords.size()[1], (cfg.num_body_parts * 2) as i64);
}
#[test]
fn model_has_nonzero_parameters() {
tch::manual_seed(0);
let cfg = tiny_config();
let model = WiFiDensePoseModel::new(&cfg, Device::Cpu);
let n = model.num_parameters();
assert!(n > 0, "model must have trainable parameters");
}
#[test]
fn inference_mode_gives_same_shapes() {
tch::manual_seed(0);
let cfg = tiny_config();
let model = WiFiDensePoseModel::new(&cfg, Device::Cpu);
let batch = 1_i64;
let antennas = (cfg.num_antennas_tx * cfg.num_antennas_rx * cfg.window_frames) as i64;
let n_sub = cfg.num_subcarriers as i64;
let amp = Tensor::rand([batch, antennas, n_sub], (Kind::Float, Device::Cpu));
let ph = Tensor::rand([batch, antennas, n_sub], (Kind::Float, Device::Cpu));
let out = model.forward_inference(&amp, &ph);
assert_eq!(out.keypoints.size()[0], batch);
assert_eq!(out.part_logits.size()[0], batch);
assert_eq!(out.uv_coords.size()[0], batch);
}
#[test]
fn uv_coords_bounded_zero_one() {
tch::manual_seed(0);
let cfg = tiny_config();
let model = WiFiDensePoseModel::new(&cfg, Device::Cpu);
let batch = 2_i64;
let antennas = (cfg.num_antennas_tx * cfg.num_antennas_rx * cfg.window_frames) as i64;
let n_sub = cfg.num_subcarriers as i64;
let amp = Tensor::rand([batch, antennas, n_sub], (Kind::Float, Device::Cpu));
let ph = Tensor::rand([batch, antennas, n_sub], (Kind::Float, Device::Cpu));
let out = model.forward_inference(&amp, &ph);
let uv_min: f64 = out.uv_coords.min().double_value(&[]);
let uv_max: f64 = out.uv_coords.max().double_value(&[]);
assert!(uv_min >= 0.0 - 1e-5, "UV min should be >= 0, got {uv_min}");
assert!(uv_max <= 1.0 + 1e-5, "UV max should be <= 1, got {uv_max}");
}
#[test]
fn phase_sanitize_zeros_first_column() {
let ph = Tensor::ones([2, 3, 8], (Kind::Float, Device::Cpu));
let out = phase_sanitize(&ph);
let first_col = out.slice(2, 0, 1, 1);
let max_abs: f64 = first_col.abs().max().double_value(&[]);
assert!(max_abs < 1e-6, "first diff column should be 0");
}
#[test]
fn phase_sanitize_captures_ramp() {
// φ[k] = k → diffs should all be 1.0 (except the padded zero)
let ph = Tensor::arange(8, (Kind::Float, Device::Cpu))
.reshape([1, 1, 8])
.expand([2, 3, 8], true);
let out = phase_sanitize(&ph);
let tail = out.slice(2, 1, 8, 1);
let min_val: f64 = tail.min().double_value(&[]);
let max_val: f64 = tail.max().double_value(&[]);
assert!(
(min_val - 1.0).abs() < 1e-5,
"expected 1.0 diff, got {min_val}"
);
assert!(
(max_val - 1.0).abs() < 1e-5,
"expected 1.0 diff, got {max_val}"
);
}
#[test]
fn save_and_load_roundtrip() {
use tempfile::tempdir;
tch::manual_seed(42);
let cfg = tiny_config();
let mut model = WiFiDensePoseModel::new(&cfg, Device::Cpu);
let tmp = tempdir().expect("tempdir");
// safetensors, not .pt: this torch build's .pt roundtrip is broken on
// Windows (torch 2.11 GenericDict internal assert).
let path = tmp.path().join("weights.safetensors");
model.save(&path).expect("save should succeed");
model.load(&path).expect("load should succeed");
// After loading, a forward pass should still work.
let batch = 1_i64;
let antennas = (cfg.num_antennas_tx * cfg.num_antennas_rx * cfg.window_frames) as i64;
let n_sub = cfg.num_subcarriers as i64;
let amp = Tensor::rand([batch, antennas, n_sub], (Kind::Float, Device::Cpu));
let ph = Tensor::rand([batch, antennas, n_sub], (Kind::Float, Device::Cpu));
let out = model.forward_inference(&amp, &ph);
assert_eq!(out.keypoints.size()[0], batch);
}
#[test]
fn varstore_accessible() {
let cfg = tiny_config();
let mut model = WiFiDensePoseModel::new(&cfg, Device::Cpu);
// Both varstore() and varstore_mut() must compile and return the store.
let _vs = model.varstore();
let _vs_mut = model.varstore_mut();
}
}