- Python 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| NanoVNASaver | ||
| train_frontend | ||
| .gitignore | ||
| fe_interface.py | ||
| helper.py | ||
| pyproject.toml | ||
| README.md | ||
| recompute_features.py | ||
| uv.lock | ||
master_code
Runnable subset of the master's-thesis code: the VNA acquisition GUI
(fe_interface.py + helper.py) and the PyTorch training GUI
(train_frontend/). The vendored NanoVNASaver/ directory is reduced to the
modules these two applications import; no charts, windows, tests or LaTeX are
included.
Layout
| Path | Purpose |
|---|---|
fe_interface.py |
Acquisition GUI: connect, calibrate (SOL or loaded Touchstone calibration), measure, export one CSV row per scan. |
helper.py |
Acquisition library: serial sweeps, calibration, resonance/feature extraction, CSV export. |
train_frontend/ |
Training GUI and pure logic: data.py (CSV loading, 65D feature vector), models.py (four architectures), train.py, augment.py, evaluate.py, infer.py, explore.py, textout.py, gui.py. |
recompute_features.py |
Recomputes derived CSV columns from the stored raw complex reflection coefficient. |
NanoVNASaver/ |
Minimal subset of a modified NanoVNA-Saver fork (GPLv3): hardware drivers, serial layer, calibration, Touchstone, RF/SI helpers. |
pyproject.toml, uv.lock |
Dependency definition and pins. |
data/, calibrations/ |
Default folders for measurement CSVs and calibration files. |
Requirements
- Linux or macOS, Python 3.12–3.14.
- uv for the pinned environment.
- A USB VNA for acquisition only; the training GUI works from CSV files without hardware.
- No generated Qt resource files are needed: the copied code does not import the
vendored
Windows/package.
Setup
cd /root/Projects/master_code
uv venv --python 3.13
uv pip install --torch-backend cpu "torch==2.14.0"
uv pip install "PySide6==6.11.2" "numpy==2.5.2" "scipy==1.18.1" \
"matplotlib==3.11.1" "pyserial==3.5" "requests==2.34.2" "python-dotenv==1.2.3"
mkdir -p data calibrations
--torch-backend cpu installs the CPU build; omit it if a CUDA build is wanted.
This directory already contains a working .venv with these versions, so it
runs immediately; repeat the commands only on another machine. uv.lock is kept
for reference, but note that uv sync follows the lockfile and pulls the CUDA
wheels on Linux. Run the applications through the existing environment:
.venv/bin/python -m train_frontend
.venv/bin/python fe_interface.py
Training data and trained models
- Training data: jonaskoenig/Material_scans
on Hugging Face. Download the scan CSVs and load them through the Data tab,
or place them in
data/. - Trained models: VNA-Master/models.
Check out this repository to obtain the trained run folders and checkpoints;
the Eval tab expects the same run-folder layout that training produces.
Access may require credentials for
git.tni.dev.
Training GUI
.venv/bin/python -m train_frontend
Workflow, tab by tab:
- Data – load one measurement CSV or every
*.csvin a folder. All rows must share the exact samefrequency_hzgrid, otherwise loading fails. The published dataset from the link above is the reference input. - Explore – dataset overview, projections, label statistics.
- Augment – preview/apply synthetic class balancing. Augmentation only adds rows for classes below the target; classes above it are left untouched and no measured row is removed.
- Model & Train – choose one of
Feature MLP,PCA-MLP,Autoencoder-Classifier,Hybrid CNN-MLP; edit tunables; train. - Results – curves, history, report text, exported run folder.
- Eval – evaluate trained models on labelled scan CSVs, including new-material files.
Training writes a run folder (model checkpoint, report.txt, curve.png,
history.csv, params.json) next to the chosen output location. Optional
inference/evaluation entry points are train_frontend.infer and
train_frontend.evaluate; the GUI is the normal entry point.
Acquisition GUI
.venv/bin/python fe_interface.py
- Connect – pick the serial interface and connect. Discovery lists several
device families;
get_VNA()selects the driver from the interface comment. - Calibration – run SOL or load an existing Touchstone calibration from
calibrations/. - Measure – set labels in the CSV panel, sweep, inspect the S11 plot, save. Every save appends one row to the CSV.
Environment variables are read when helper.py is imported, so export them in
the shell before starting the GUI:
export DATA_FOLDER=/path/to/data
export CALIBRATIONS_FOLDER=/path/to/calibrations
export HA_TOKEN=... # optional Home Assistant sensor access
.env is loaded by fe_interface.py, but too late for the two folder variables;
HA_TOKEN is read later and may come from .env.
data/ is not created automatically on save if it is missing — create it as
shown above.
CSV contract
One row per scan. The same frequency_hz grid is required for every row. The
file contains:
- 10 spectral arrays (
frequency_hz,real,imaginary,s11_db,phase_rad,vswr,qfactor_per_point,impedance_re,impedance_im,group_delay); - labels (
material_type,trash_type,dirty); - background-difference arrays (
diff_real,diff_imaginary,diff_mag_db,diff_phase_rad); - 28 scalar band statistics;
- a fixed-width resonance block (
resonance_countplus six resonances); - Home Assistant cells (
temp_1,hum_1,pressure,temp_2,hum_2).
The trainer builds a 65-dimensional feature vector: 28 statistics + resonance count + 6 resonances × 6 subfields.
Recomputing derived columns
Useful after changing resonance detection or band edges; the raw real /
imaginary data is preserved and everything derived from it is rewritten:
.venv/bin/python recompute_features.py data/*.csv
.venv/bin/python recompute_features.py --out-dir data/recomputed data/
Not included
Tests, thesis sources and the rest of the vendored NanoVNA-Saver GUI are
intentionally absent. NanoVNASaver/ remains GPLv3; the original per-file
license headers are preserved.
Verification performed on this copy
- All copied Python files compile.
import helper,import fe_interface,import train_frontend.guiand the evaluation/inference modules import successfully.- Both GUIs start under
QT_QPA_PLATFORM=offscreenand stay in their event loop without tracebacks (they were killed by a timeout after 12 s). - Acquisition against a real VNA was not possible here, because no instrument is attached and no measurement data is included.