Skip to content

Commit 0d1afe8

Browse files
committed
Accelerate gif
1 parent 7e86ffc commit 0d1afe8

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

cinema/examples/inference/landmark_heatmap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def plot_heatmaps(images: np.ndarray, probs: np.ndarray, filepath: Path) -> None
5353
plt.close(fig)
5454

5555
# Create GIF directly from memory arrays
56-
with imageio.get_writer(filepath, mode="I", duration=100, loop=0) as writer:
56+
with imageio.get_writer(filepath, mode="I", duration=50, loop=0) as writer:
5757
for frame in tqdm(frames, desc="Creating heatmap GIF"):
5858
writer.append_data(frame)
5959

@@ -98,7 +98,7 @@ def plot_landmarks(images: np.ndarray, coords: np.ndarray, filepath: Path) -> No
9898
plt.close(fig)
9999

100100
# Create GIF directly from memory arrays
101-
with imageio.get_writer(filepath, mode="I", duration=100, loop=0) as writer:
101+
with imageio.get_writer(filepath, mode="I", duration=50, loop=0) as writer:
102102
for frame in tqdm(frames, desc="Creating landmark GIF"):
103103
writer.append_data(frame)
104104

cinema/examples/inference/segmentation_lax_4c.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def plot_segmentations(images: np.ndarray, labels: np.ndarray, filepath: Path) -
8282
plt.close(fig)
8383

8484
# Create GIF directly from memory arrays
85-
with imageio.get_writer(filepath, mode="I", duration=100, loop=0) as writer:
85+
with imageio.get_writer(filepath, mode="I", duration=50, loop=0) as writer:
8686
for frame in tqdm(frames, desc="Creating GIF"):
8787
writer.append_data(frame)
8888

cinema/examples/inference/segmentation_sax.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
from cinema import ConvUNetR
1616

1717

18-
def plot_segmentations(images: np.ndarray, labels: np.ndarray, filepath: Path) -> None:
18+
def plot_segmentations(images: np.ndarray, labels: np.ndarray, t_step: int, filepath: Path) -> None:
1919
"""Plot segmentations as animated GIF.
2020
2121
Args:
2222
images: (x, y, z, t)
2323
labels: (x, y, z, t)
24+
t_step: step size for frames
2425
filepath: path to save the GIF file.
2526
"""
2627
n_slices, n_frames = labels.shape[-2:]
@@ -72,7 +73,7 @@ def plot_segmentations(images: np.ndarray, labels: np.ndarray, filepath: Path) -
7273
plt.close(fig)
7374

7475
# Create GIF directly from memory arrays
75-
with imageio.get_writer(filepath, mode="I", duration=200, loop=0) as writer:
76+
with imageio.get_writer(filepath, mode="I", duration=50 * t_step, loop=0) as writer:
7677
for frame in tqdm(frames, desc="Creating segmentation GIF"):
7778
writer.append_data(frame)
7879

@@ -145,7 +146,7 @@ def run(trained_dataset: str, seed: int, device: torch.device, dtype: torch.dtyp
145146
labels = torch.stack(labels_list, dim=-1).detach().to(torch.float32).cpu().numpy() # (x, y, z, t)
146147

147148
# visualise segmentations
148-
plot_segmentations(images, labels, Path(f"segmentation_{view}_animation_{trained_dataset}_{seed}.gif"))
149+
plot_segmentations(images, labels, t_step, Path(f"segmentation_{view}_animation_{trained_dataset}_{seed}.gif"))
149150

150151
# visualise volume changes
151152
plot_volume_changes(labels, t_step, Path(f"segmentation_{view}_mask_volume_{trained_dataset}_{seed}.png"))

0 commit comments

Comments
 (0)