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 |
|---|---|---|
|
Models and inference |
both |
|
Reading videos / images, drawing |
both |
|
Array maths |
both |
|
Systole peak detection ( |
segmentation |
|
Drawing the trace marker on videos |
segmentation |
|
Saving the area-vs-time plots |
segmentation |
|
Progress bars |
segmentation, stats |
|
Reading |
|
|
Saving annotated videos ( |
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 |
|---|---|---|
|
|
DeepLabV3-ResNet50 |
|
|
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).