4. Computing Normalization Statistics

Both prediction scripts normalise every frame with a per-channel mean and standard deviation:

# Top of PredictEF.py and PredictSegmentation.py
MEAN = [0.128, 0.129, 0.130]
STD  = [0.196, 0.196, 0.197]

These defaults come from the EchoNet-Dynamic training set and work well on EchoNet-like data. If your videos come from a different scanner, view, or contrast, recomputing these statistics on your own data can reduce the domain shift and improve segmentation/EF accuracy. CalculateStats.py does exactly that.

Optional step

You only need this chapter if you want to retune the MEAN/STD for your own dataset. To just run the models on EchoNet-style data, keep the defaults and skip ahead to Segmentation.


4.1. Configure the paths

INPUT_DIR points at the demo videos; for meaningful statistics, point it at your full dataset instead:

INPUT_DIR = r"...\EchoNet-dynamic\demo\video"   # use your full Videos\ folder for real stats
CSV_PATH  = None                                # or r"...\FileList.csv" (TRAIN split only)

Variable

Meaning

INPUT_DIR

Folder containing the .avi/.mp4 videos to measure

CSV_PATH

Optional FileList.csv; keep None to use every video

The demo is just a smoke test β€” use the full dataset for real stats

Statistics from a single demo video are not representative. For real MEAN/STD values, set INPUT_DIR to the Videos/ folder of the open EchoNet-Dynamic dataset and set CSV_PATH to its FileList.csv β€” that file ships with the dataset and already contains the Split column used to pick the training set.


4.2. Two modes: training-only vs full scan

The script decides automatically how to pick videos:

  • Training Set Only β€” if CSV_PATH points to a CSV that has both a FileName and a Split column, only the rows where Split == TRAIN are used. Filenames without an extension get .avi appended, and missing files are skipped.

  • Full Dataset β€” used when no CSV is given, the file is missing, the required columns are absent, or no TRAIN rows are found. Every .avi/.mp4 in the folder is measured.

Why training-only matters

Statistics should be computed on the training split only, never the test set, to avoid leaking information. Provide a FileList.csv with a Split column to keep this clean.


4.3. Run the script

conda activate echonet
python scripts/CalculateStats.py

It streams every frame, converts BGR→RGB, resizes to 112 × 112, scales to [0, 1], and accumulates per-channel sums to compute:

\[\mu = \frac{1}{N}\sum x, \qquad \sigma = \sqrt{\frac{1}{N}\sum x^2 - \mu^2}\]

Typical output (pointed at the full EchoNet-Dynamic dataset):

πŸ“„ CSV file detected: ...\EchoNet-Dynamic\FileList.csv
🎯 Found 7460 training videos in CSV. Verifying local files...
πŸ“ Final count: 7460 videos ready for processing. Starting calculation...
============================================================
πŸŽ“ Normalization parameters for [Training Set Only] calculated!
============================================================
MEAN = [0.128, 0.129, 0.130]
STD  = [0.196, 0.196, 0.197]
============================================================

4.4. Use the result

Copy the printed MEAN and STD lines into the configuration block at the top of both PredictEF.py and PredictSegmentation.py, replacing the defaults. The next run of either script will use your dataset’s statistics.

Requires pandas

This script imports pandas to read the CSV. Install it with pip install pandas if you have not already (see Installation).