Download example.py from Ahus-AIM/echo-mae-2d: direct link, hf CLI and curl.
- Browser
- Download file 899 Bytes
-
https://huggingface.co/Ahus-AIM/echo-mae-2d/resolve/main/example.py
- Command line
-
hf download hf://Ahus-AIM/echo-mae-2d/example.py
-
curl -L -o example.py https://huggingface.co/Ahus-AIM/echo-mae-2d/resolve/main/example.py
899 Bytes
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| import torch | |
| from model import EchoMAE2D | |
| model = EchoMAE2D() | |
| model.load_state_dict(torch.load("model.pt", weights_only=True)) | |
| model.eval() | |
| frame = torch.from_numpy(np.load("sample.npy")).float()[None, None] / 255 # 1 x 1 x 256 x 128 | |
| torch.manual_seed(0) | |
| mask = (torch.rand(1, 1, 16, 8) < 0.5).float() # hide half of the 16 x 16 pixel blocks | |
| mask = mask.repeat_interleave(16, 2).repeat_interleave(16, 3) | |
| with torch.no_grad(): | |
| reconstruction = model(frame * (1 - mask)) | |
| panels = {"Input": frame, "Masked": frame * (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], cmap="gray", vmin=0, vmax=1) | |
| axis.set_title(title) | |
| axis.axis("off") | |
| figure.tight_layout() | |
| figure.savefig("reconstruction.png", dpi=150) | |