File size: 899 Bytes
b080b8b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 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)
|