PyTorch
echocardiography
ultrasound
masked-autoencoder
3d
File size: 844 Bytes
c9e97e7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import matplotlib.pyplot as plt
import numpy as np
import torch

from model import EchoMAE3D

model = EchoMAE3D()
model.load_state_dict(torch.load("model.pt", weights_only=True))
model.eval()

volume = torch.from_numpy(np.load("sample.npy")).float()[None, None] / 255  # 1 x 1 x 256 x 64 x 64
torch.manual_seed(0)
with torch.no_grad():
    reconstruction, mask = model(volume)  # hides 75% of the 16 x 8 x 8 voxel patches

panels = {"Input": volume, "Masked": volume * (1 - mask), "Reconstruction": reconstruction}
figure, axes = plt.subplots(1, 3, figsize=(6, 4.4))
for axis, (title, image) in zip(axes, panels.items()):
    axis.imshow(image[0, 0, :, :, 32], cmap="gray", vmin=0, vmax=1, aspect=0.5)  # central elevation slice
    axis.set_title(title)
    axis.axis("off")
figure.tight_layout()
figure.savefig("reconstruction.png", dpi=150)