Posted on
Artificial Intelligence

Artificial Intelligence Metrics Visualisation

Author
  • User
    linuxbash
    Posts by this author
    Posts by this author

Visualizing AI Metrics from the Linux Command Line

Your model trains for hours, the GPU fans are roaring, but… are you actually improving? Without clear, timely visualizations of key metrics, you’re flying blind. In this post, we’ll show how to turn raw training logs into live, meaningful plots—all from a Linux bash workflow. You’ll get practical, distro-friendly installation steps and several ready-to-run snippets to visualize loss curves, accuracies, and experiment performance.

Why AI Metrics Visualization Matters (Especially on Linux)

  • Faster feedback loops: Spot divergence, overfitting, or dead learning rates early.

  • Reproducible science: Commit your plots and pipelines; colleagues can reproduce on any server.

  • Works where you work: Most training happens on Linux servers without GUIs. CLI-first tooling keeps you fast and focused.

  • Bridges development and ops: Consistent logs and lightweight dashboards make it easy to share progress with your team.

Prerequisites and Installation

You only need a few dependable tools. Choose the commands that match your distro.

  • Debian/Ubuntu (apt):

    sudo apt update
    sudo apt install -y python3 python3-pip gnuplot jq python3-matplotlib
    # Extra Python tools via pip (per-user installs):
    python3 -m pip install --user tensorboard tensorboardX mlflow
    
  • Fedora/RHEL/CentOS Stream (dnf):

    sudo dnf install -y python3 python3-pip gnuplot jq python3-matplotlib
    # Extra Python tools via pip (per-user installs):
    python3 -m pip install --user tensorboard tensorboardX mlflow
    
  • openSUSE (zypper):

    sudo zypper refresh
    sudo zypper install -y python3 python3-pip gnuplot jq python3-matplotlib
    # Extra Python tools via pip (per-user installs):
    python3 -m pip install --user tensorboard tensorboardX mlflow
    

Tip: Prefer a virtual environment for project-local installs:

python3 -m venv .venv
. .venv/bin/activate
pip install tensorboard tensorboardX mlflow matplotlib

Actionable Recipes

1) Standardize Your Logs (CSV/JSONL) So They’re Easy to Plot

Pick one log format and stick to it. CSV is easy for gnuplot; JSONL (one JSON per line) is flexible for complex metrics.

  • Generate a sample CSV you can reuse:

    python3 - <<'PY'
    import csv, math, random, time
    with open("metrics.csv","w", newline="") as f:
    w = csv.writer(f)
    w.writerow(["step","train_loss","val_loss","accuracy","lr"])
    for i in range(201):
        train = 2.3*math.exp(-i/80) + 0.05*random.random()
        val   = 2.4*math.exp(-i/100)+ 0.10*random.random()
        acc   = 0.1 + 0.9*(1-math.exp(-i/120)) + 0.02*random.random()
        lr    = 0.001
        w.writerow([i, round(train,4), round(val,4), round(acc,4), lr])
        time.sleep(0.05)
    PY
    
  • If your training emits JSONL, convert to CSV with jq:

    # train.jsonl contains lines like: {"step": 1, "metrics": {"loss": 1.23, "val_loss": 1.45, "acc": 0.62}}
    printf "step,train_loss,val_loss,accuracy\n" > metrics.csv
    jq -r '[.step, .metrics.loss, .metrics.val_loss, .metrics.acc] | @csv' train.jsonl >> metrics.csv
    

Now you have a single “source of truth” file for all downstream plots.

2) Live, No-GUI Plots Right In Your Terminal (gnuplot)

When you’re SSH’d into a remote box, you still can visualize. gnuplot can redraw from CSV in a loop using a text (dumb) terminal.

  • Live terminal plot of train vs. val loss: ``` gnuplot -persist <<'GNUPLOT' set datafile separator "," set key left top set term dumb 120 30 # text-mode plot, width x height set title "Loss (train vs val)" set xlabel "step" set ylabel "loss"

plot "metrics.csv" using 1:2 with lines title "train_loss", \ "metrics.csv" using 1:3 with lines title "val_loss"

pause 2 reread GNUPLOT ```

This rereads metrics.csv every 2 seconds. Run it while training appends new rows and you’ll see curves evolve in real-time.

  • Prefer a file output (PNG/SVG) for reports: gnuplot <<'GNUPLOT' set datafile separator "," set term pngcairo size 1280,720 set output "loss.png" set grid set xlabel "step" set ylabel "loss" set title "Training and Validation Loss" plot "metrics.csv" using 1:2 with lines lw 2 lc rgb "#1f77b4" title "train", \ "metrics.csv" using 1:3 with lines lw 2 lc rgb "#ff7f0e" title "val" GNUPLOT This generates loss.png for emails, wikis, or papers.

3) Spin Up a Browser Dashboard in Minutes (TensorBoard and MLflow)

Some questions need dashboards: filtering runs, zooming, and comparing experiments.

  • TensorBoard (lightweight example using tensorboardX): ``` # Create a demo run with scalar logs (no TF/PyTorch required) python3 - <<'PY' from tensorboardX import SummaryWriter import math, random w = SummaryWriter("runs/demo") for step in range(200): w.add_scalar("loss/train", 2.3math.exp(-step/80)+0.05random.random(), step) w.add_scalar("loss/val", 2.4math.exp(-step/100)+0.10random.random(), step) w.add_scalar("acc/val", 0.1 + 0.9(1-math.exp(-step/120)) + 0.02random.random(), step) w.close() PY

Start TensorBoard

tensorboard --logdir runs --port 6006 --bind_all ``` Then open http://SERVER_IP:6006 in your browser. You’ll see scalars, smoothing, and comparisons if you add more runs.

  • MLflow for experiment tracking: ``` # Log a demo run python3 - <<'PY' import mlflow, math, random mlflow.set_tracking_uri("file:./mlruns") # local folder backend with mlflow.start_run(run_name="demo"): for step in range(200): mlflow.log_metric("loss", 2.3math.exp(-step/80)+0.05random.random(), step=step) mlflow.log_metric("val_loss",2.4math.exp(-step/100)+0.10random.random(), step=step) mlflow.log_metric("acc", 0.1+0.9(1-math.exp(-step/120))+0.02random.random(), step=step) PY

Launch the UI

mlflow ui --backend-store-uri ./mlruns --port 5000 ``` Open http://SERVER_IP:5000 to compare runs, parameters, and metrics side-by-side.

Note: When exposing ports on remote servers, follow your org’s network and security policies.

4) Publication-Ready Figures (Matplotlib Heatmaps, Curves)

Sometimes you need more control over style and composition. Use matplotlib to generate reusable figures from your CSV.

  • Loss curves and accuracy subplot: ``` python3 - <<'PY' import csv import matplotlib.pyplot as plt

steps, train, val, acc = [], [], [], [] with open("metrics.csv") as f: r = csv.DictReader(f) for row in r: steps.append(int(row["step"])) train.append(float(row["train_loss"])) val.append(float(row["val_loss"])) acc.append(float(row["accuracy"]))

fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12,4)) ax1.plot(steps, train, label="train_loss") ax1.plot(steps, val, label="val_loss") ax1.set_title("Loss") ax1.set_xlabel("step"); ax1.set_ylabel("loss"); ax1.grid(True); ax1.legend()

ax2.plot(steps, acc, color="#2ca02c", label="accuracy") ax2.set_title("Validation Accuracy") ax2.set_xlabel("step"); ax2.set_ylabel("acc"); ax2.grid(True); ax2.legend()

plt.tight_layout() plt.savefig("metrics_summary.png", dpi=160) print("Saved metrics_summary.png") PY ```

  • Confusion matrix heatmap (if you save predictions/labels): ``` python3 - <<'PY' import csv, numpy as np, matplotlib.pyplot as plt

predictions.csv with: true,label_pred

y_true, y_pred = [], [] with open("predictions.csv") as f: r = csv.DictReader(f) for row in r: y_true.append(int(row["true"])) y_pred.append(int(row["label_pred"]))

classes = sorted(set(y_true) | set(y_pred)) cm = np.zeros((len(classes), len(classes)), dtype=int) idx = {c:i for i,c in enumerate(classes)} for t,p in zip(y_true,y_pred): cm[idx[t], idx[p]] += 1

fig, ax = plt.subplots(figsize=(5,4)) im = ax.imshow(cm, cmap="Blues") ax.set_xlabel("Predicted"); ax.set_ylabel("True") ax.set_xticks(range(len(classes))); ax.set_yticks(range(len(classes))) ax.set_xticklabels(classes); ax.set_yticklabels(classes) for i in range(len(classes)): for j in range(len(classes)): ax.text(j, i, cm[i,j], ha='center', va='center', color='black', fontsize=8) plt.colorbar(im, ax=ax, fraction=0.046, pad=0.04) plt.tight_layout() plt.savefig("confusion_matrix.png", dpi=160) print("Saved confusion_matrix.png") PY ```

Real-World Tips

  • Log early, log always: Even simple CSVs unlock real-time plotting and rapid iteration.

  • Keep one file per run: e.g., runs/exp_2026-07-10/metrics.csv so you can compare later.

  • Automate live plots: Kick off a gnuplot watcher in tmux while training appends new rows.

  • Version your visualization scripts: Treat gnuplot and Python plotting snippets as code artifacts.

Conclusion and Next Steps

Clear metrics visualization can save you compute time, guide hyperparameter tuning, and surface regressions before they become expensive. You now have:

  • Terminal-native plots with gnuplot for SSH sessions.

  • Browser dashboards with TensorBoard and MLflow.

  • Polished figures with matplotlib.

Your next step: 1) Add CSV/JSONL logging to your training loop. 2) Drop the gnuplot “live loop” snippet into a tmux pane. 3) Stand up TensorBoard or MLflow to compare experiments across runs. 4) Commit your plots and scripts to your repo so the team shares a single, reproducible workflow.

If you want a follow-up, ask for a one-command Bash launcher that starts training, logs metrics, and opens the right visualizer for your stack.