Train a fully connected, dense-only neural network in Keras/TensorFlow to predict thickness from 109-length numeric sequences stored in training_data.txt. We log metrics to Weights & Biases (wandb) and save a Keras model artifact.
- Ensure Python 3.10+ is available.
- Create & activate a virtual environment (PowerShell):
python -m venv .venv .\.venv\Scripts\Activate.ps1 python -m pip install --upgrade pip pip install -r requirements.txt
- W&B: either set
WANDB_API_KEYenv var or runwandb login. If you are offline, use--wandb-mode offlinewhen running the script.
- Training file:
training_data.txt(CSV with columnsthicknessandvalues, wherevaluesis a stringified list of 109 numbers). - The script automatically parses and standardizes features; no manual preprocessing needed.
Edit config.yaml to set all defaults (data path, epochs, batch size, dense layer widths, wandb mode, etc.). CLI flags override anything in the config.
python train.py --config config.yaml- Set
model_type: dense(default) to use the fully-connected stack defined bydense_sizes. - Set
model_type: cnn1dto use a 1D CNN; configurecnn1d_filters,cnn1d_kernel_sizes, andcnn1d_pool_sizeinconfig.yaml. - Learning-rate reduction: control with
lr_reduce_on_plateau,lr_patience,lr_factor,lr_mininconfig.yaml(ReduceLROnPlateau onval_loss).
CLI overrides (examples):
--epochs 10: override epochs from config.--dense-sizes 256 128 64 32: create 4 hidden Dense layers with those widths.--model-type cnn1d --cnn1d-filters 64 128 256 --cnn1d-kernel-sizes 7 5 3 --cnn1d-pool-size 2: run a 3-layer 1D CNN with custom kernels and pooling.--wandb-mode offline: set wandb mode for this run.
Validation metrics are reported at the end of training and logged to wandb (if enabled). To run an evaluation-only pass on the saved model:
python train.py --data-path training_data.txt --epochs 0 --load-existing artifacts/model.kerasThis will load the saved model, compute metrics on the held-out validation split, and exit.
- Loss: Mean Squared Error; optimizer: Adam; activations: ReLU on hidden layers, linear on the output for regression.
- The number of hidden Dense layers is determined by
dense_sizesinconfig.yaml(or CLI); provide any length list to build that many layers. - For
cnn1d, the feature vector is reshaped to(sequence_length, 1), then a stack of Conv1D + optional MaxPool layers (fromcnn1d_filters/cnn1d_kernel_sizes/cnn1d_pool_size) feeds into a Dense head for regression. - ReduceLROnPlateau is enabled by default; tune or disable it via config.
- Deterministic seeds are set for reproducibility; disable GPU nondeterminism separately if needed.