# How to Monitor PFLD Training Progress Using TensorBoard

> Monitor PFLD training progress with TensorBoard. See train/test loss, mean error, and failure rate logged automatically during model execution. Learn more now.

- Repository: [Guoqiang QI/pfld](https://github.com/guoqiangqi/pfld)
- Tags: how-to-guide
- Published: 2026-03-03

---

**You can monitor PFLD training progress by launching TensorBoard against the `./tensorboard` directory while executing [`train_model.py`](https://github.com/guoqiangqi/pfld/blob/main/train_model.py), which automatically logs scalars for train/test loss, mean error, and failure rate using TensorFlow's summary API.**

The guoqiangqi/pfld repository integrates TensorFlow's summary operations directly into its training pipeline. This allows you to visualize **loss curves**, **learning-rate schedules**, and performance metrics in real time without modifying the source code.

## How TensorBoard Logging is Implemented in PFLD

The training script [`train_model.py`](https://github.com/guoqiangqi/pfld/blob/main/train_model.py) contains the complete instrumentation logic. It uses the legacy TensorFlow 1.x summary API to capture scalar metrics at each epoch.

### Log Directory Configuration

At the start of the script, the output location for TensorBoard event files is defined:

```python
log_dir = './tensorboard'          # train_model.py#L24

```

This relative path stores all summary data generated during the training session. You can modify this variable to change the output location, though the default works with the README instructions.

### Scalar Summaries and FileWriter Setup

The script registers multiple scalar summaries to track model performance. Between lines 116-122, it creates summary operations for test loss, mean error, failure rate, and training losses using `tf.summary.scalar`.

After building the computation graph, the script merges all summaries and initializes a `FileWriter`:

```python
merged = tf.summary.merge_all()                     # train_model.py#L51

train_write = tf.summary.FileWriter(log_dir,
                                    sess.graph)    # train_model.py#L52

```

The `sess.graph` argument preserves the full model architecture for visualization in TensorBoard's Graphs tab.

### Writing Metrics During Training Epochs

During each training epoch, the script executes the merged summary operation alongside metric assignments:

```python
summary, _, _, _, _, _ = sess.run(
    [merged,
     test_mean_error.assign(test_ME),
     test_failure_rate.assign(test_FR),
     test_10_loss.assign(test_loss),
     train_loss.assign(train_L),
     train_loss_l2.assign(train_L2)
    ])
train_write.add_summary(summary, epoch)            # train_model.py#L76

```

This writes the current values of **train_loss**, **train_loss_l2**, **test_mean_error**, **test_failure_rate**, and **test_10_loss** to disk, timestamped by the current epoch number.

## Launching TensorBoard for Real-Time Monitoring

To view the metrics, you must run TensorBoard in a separate terminal while training is active.

### Install Dependencies

Ensure you have the correct TensorBoard version specified in [`requirement.txt`](https://github.com/guoqiangqi/pfld/blob/main/requirement.txt):

```bash
pip install tensorboard==1.13.1   # requirement.txt#L39

```

Alternatively, install all requirements at once:

```bash
pip install -r requirement.txt

```

### Start Training

Execute the training script using the provided shell wrapper or invoke Python directly:

```bash

# Option 1: Using the helper script

bash train.sh

# Option 2: Direct execution with custom arguments

python train_model.py --model_dir models/exp1

```

The script will begin writing event files to `./tensorboard/` immediately.

### Launch TensorBoard

Open a new terminal window and start the TensorBoard server, pointing to the log directory:

```bash
tensorboard --logdir=./tensorboard/   # README.md#L22

```

Navigate to `http://localhost:6006` in your browser. The **Scalars** dashboard displays real-time curves for all logged metrics, while the **Graphs** tab shows the model architecture captured from `sess.graph`.

## Customizing the Log Directory

If you need to run multiple experiments simultaneously, modify the `log_dir` variable in [`train_model.py`](https://github.com/guoqiangqi/pfld/blob/main/train_model.py) or pass a custom path via command-line arguments (requires adding an argument parser to the script):

```python

# Example modification in train_model.py

import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--log_dir', default='./tensorboard')
args = parser.parse_args()
log_dir = args.log_dir

```

Then launch TensorBoard pointing to your custom location:

```bash
tensorboard --logdir=./my_experiment_logs/

```

## Summary

- **Instrumentation location**: [`train_model.py`](https://github.com/guoqiangqi/pfld/blob/main/train_model.py) lines 24, 51-52, and 76 handle all TensorBoard setup and writing operations.
- **Default log path**: The script writes to `./tensorboard/` using `tf.summary.FileWriter`.
- **Tracked metrics**: Train loss (L2 and standard), test loss, mean error, and failure rate are logged every epoch.
- **Version requirement**: Use TensorBoard 1.13.1 as specified in [`requirement.txt`](https://github.com/guoqiangqi/pfld/blob/main/requirement.txt) for compatibility with the TensorFlow 1.x summary API.
- **Launch command**: Run `tensorboard --logdir=./tensorboard/` in a separate terminal while training is active.

## Frequently Asked Questions

### Where does PFLD store TensorBoard log files?

By default, the repository stores event files in the `./tensorboard/` directory relative to the execution path. This is hardcoded in [`train_model.py`](https://github.com/guoqiangqi/pfld/blob/main/train_model.py) at line 24. You can change this path by modifying the `log_dir` variable or extending the script to accept a command-line argument.

### Which metrics can I visualize when monitoring PFLD training?

The script logs five primary scalar metrics: `train_loss`, `train_loss_l2`, `test_mean_error`, `test_failure_rate`, and `test_10_loss`. These appear in the TensorBoard Scalars dashboard, allowing you to track convergence and detect overfitting by comparing training and validation curves.

### Do I need to modify the code to enable TensorBoard logging?

No. The guoqiangqi/pfld repository includes TensorBoard instrumentation by default. As long as you have TensorBoard 1.13.1 installed (per [`requirement.txt`](https://github.com/guoqiangqi/pfld/blob/main/requirement.txt)), simply run the training script and launch TensorBoard with `--logdir=./tensorboard/` to begin monitoring.

### Can I view the model architecture in TensorBoard?

Yes. The `FileWriter` is initialized with `sess.graph` at line 52 of [`train_model.py`](https://github.com/guoqiangqi/pfld/blob/main/train_model.py), which serializes the complete TensorFlow graph definition. Open the Graphs tab in TensorBoard to inspect the PFLD model structure, node connections, and device placement.