Download example.py from Ahus-AIM/echo-mae-3d: direct link, hf CLI and curl.
- Browser
- Download file 844 Bytes
-
https://huggingface.co/Ahus-AIM/echo-mae-3d/resolve/main/example.py
- Command line
-
hf download hf://Ahus-AIM/echo-mae-3d/example.py
-
curl -L -o example.py https://huggingface.co/Ahus-AIM/echo-mae-3d/resolve/main/example.py
844 Bytes
| 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) | |