2. Installation & Setup

This chapter gets your environment ready to run both scripts.

2.1. Create a Python environment

A dedicated Conda environment which keeps the dependencies isolated is recommended. Python 3.9 is a safe choice for the EchoNet-Dynamic stack. For example, we name the environment as echonet_dynamic.

conda create -n echonet_dynamic python=3.9
conda activate echonet_dynamic

Windows note

On this machine Conda lives at C:\Users\model\miniconda3. If the conda command is not recognised, open the β€œAnaconda Prompt” from the Start menu, or first run C:\Users\model\miniconda3\Scripts\activate.bat.


2.2. Install PyTorch

Install PyTorch matching your CUDA version for GPU acceleration. Check the official selector for the exact command. A typical CUDA 11.8 install:

pip install torch torchvision --index-url https://download.pytorch.org/whl/cu118

CPU-only (works, but video processing will be slow):

pip install torch torchvision

Verify the GPU is visible:

import torch
print(torch.__version__)
print("CUDA available:", torch.cuda.is_available())

2.3. Install the remaining dependencies

Both scripts rely on the following packages:

Package

Used for

Needed by

torch, torchvision

Models and inference

both

opencv-python (cv2)

Reading videos / images, drawing

both

numpy

Array maths

both

scipy

Systole peak detection (scipy.signal)

segmentation

scikit-image (skimage)

Drawing the trace marker on videos

segmentation

matplotlib

Saving the area-vs-time plots

segmentation

tqdm

Progress bars

segmentation, stats

pandas

Reading FileList.csv

CalculateStats.py

echonet

Saving annotated videos (echonet.utils.savevideo)

segmentation

Install them in one go:

pip install opencv-python numpy scipy scikit-image matplotlib tqdm pandas

2.3.1. Installing the echonet package

PredictSegmentation.py imports echonet to write annotated videos. Install it from the official repository:

git clone https://github.com/echonet/dynamic.git
cd dynamic
pip install -e .

Only need EF prediction?

PredictEF.py does not import echonet. If you only run EF prediction you can skip the echonet, scipy, skimage, matplotlib and tqdm installs.


2.4. Obtain the pretrained weights

Both scripts load a pretrained .pt checkpoint. Download both from the ModelFLOWs-cardiac releases page (also linked from the Downloads page). Save them into the project’s stats/ folder under the exact names below β€” that is the location each script’s WEIGHTS path points at (...\EchoNet-dynamic\stats\…).

Script

Expected weight

Architecture

PredictSegmentation.py

deeplabv3_resnet50_random.pt

DeepLabV3-ResNet50

PredictEF.py

r2plus1d_18_32_2_pretrained.pt

R(2+1)D-18

Use the matching checkpoint

The segmentation script builds a deeplabv3_resnet50 head with 1 output channel, and the EF script builds an r2plus1d_18 with a 1-unit final linear layer. Loading the wrong checkpoint into either will raise a state_dict size-mismatch error.


2.5. The project layout

The project is a single self-contained folder. With the scripts, weights and demo data in place it looks like this:

EchoNet-dynamic/
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ PredictSegmentation.py
β”‚   β”œβ”€β”€ PredictEF.py
β”‚   └── CalculateStats.py
β”œβ”€β”€ stats/
β”‚   β”œβ”€β”€ deeplabv3_resnet50_random.pt
β”‚   └── r2plus1d_18_32_2_pretrained.pt
└── demo/
    β”œβ”€β”€ video/   0X243FDE8AE0A05B6F.avi
    └── npy/     frame_0000.npy … (138)

Keep scripts/, stats/ and demo/ with these names so the paths shown in each script match. Don’t have the files yet? Grab the scripts, weights and demo data from the Downloads page.

You are now ready to prepare your input data (next chapter).