TensorFlow-based 5D→1D regression trainer/tester with plotting.
Project description
fivedreg_tf (TensorFlow)
TensorFlow/Keras implementation of the 5D → 1D regressor with a simple training/testing API.
Modules
tf_model.py:build_tf_model(hidden_sizes, Lambda)builds a Sequential model with L2 regularisation and He/Xavier init.trainer_tf.py:TrainerTFloads/validates data, trains a TF model, and savesmodel_tf.kerasplus normalisation values. Optional early stopping, LR decay, batch size, and grad clipping.tester_tf.py:TesterTFloads the saved TF model and normalisation stats to make predictions on NumPy arrays or .pkl files.logger.py,utils.py: lightweight logging and decorators.- Synthetic data examples use the separate
interpy_synthpackage (installed automatically).
Installation (package)
From this backend/fivedreg_tf directory:
pip install -r requirements.lock # pinned CPU-only deps
pip install .
Headless environments: plotting is configured with the Agg backend, so no display is required.
GPU is not required or supported; the package depends on tensorflow-cpu.
For reproducibility, install via the pinned requirements.lock in backend/.
Docker (whole app):
cd ../..
./scripts/docker_build.sh
./scripts/docker_up.sh # backend on :8000 (includes TF if built with fivedreg_tf)
Usage
from fivedreg_tf.trainer_tf import TrainerTF
from fivedreg_tf.tester_tf import TesterTF
from interpy_synth import synthetic_5d_pickle
import os
out_dir = "outputs_tf"
os.makedirs(out_dir, exist_ok=True)
data_path = synthetic_5d_pickle(os.path.join(out_dir, "train.pkl"), n=1000, seed=42)
trainer = TrainerTF(
directory=out_dir,
hidden_sizes=[64, 32, 16],
epochs=100,
learning_rate=0.01,
early_stop_patience=10,
lr_decay=0.95,
seed=42,
)
train_rmse, val_rmse = trainer.train(data_path)
tester = TesterTF(directory=out_dir)
y_pred = tester.predict([0.1, 0.2, 0.3, 0.4, 0.5])
Note: Ensure TensorFlow is installed in your environment to use this package. Training also saves plots (rmse_vs_epochs.png, ytrue_vs_ypred.png) to the directory.
Metadata (tf_model_metadata.json) includes hidden sizes, Lambda, epochs run, best epoch, best train/val RMSE, baseline RMSE, and final train/val R².
Performance/ops tips:
- CPU-only build; choose modest hidden sizes/batch sizes for constrained CPUs.
- Batch size and grad clipping can help stabilise small datasets (see tests for small-batch config).
- Use
requirements.lockfor reproducibility; mount outputs_tf via Docker volumes in production.
FastAPI usage
/trainsupportsmodel_type=tfto train and save TF artifacts intobackend/outputs_tf/(including TF plots) when running the API./predictacceptsmodel_type=tfto run predictions using the TF model./artifacts/{filename}serves TF artifacts (model_tf.keras,normalisation_values_tf.npz,tf_model_metadata.json) as well as NumPy ones.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fivedreg_tf-0.1.0.tar.gz.
File metadata
- Download URL: fivedreg_tf-0.1.0.tar.gz
- Upload date:
- Size: 2.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c858ea63bcbfb42031f8c0bb75a539436d9385d7416b695ab4266b4d3c06193
|
|
| MD5 |
4800986a1250e9fc62ae9af4531b048b
|
|
| BLAKE2b-256 |
e4125d0ce550c4584aa3969793abd3e07e4f941a361593438d1861ecf32fd1f9
|
File details
Details for the file fivedreg_tf-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fivedreg_tf-0.1.0-py3-none-any.whl
- Upload date:
- Size: 2.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aef287e6bb050f0cdf1b407bf7ce0c760cb692d5c1b2857ca06ec707470a660b
|
|
| MD5 |
1183830a0597ecee5b442badec6bd845
|
|
| BLAKE2b-256 |
d5c2642e011c528f827b1b8e199691047b6ea53075c1c8974c9d807de2d88563
|