MCPcopy Create free account
hub / github.com/AlmondGod/tinyworlds / visualize_batch

Function visualize_batch

scripts/visualize_batch.py:9–48  ·  view source on GitHub ↗
(frames, save_path=None, title="Video Sequences Batch", max_batch_size=8, max_seq_length=8)

Source from the content-addressed store, hash-verified

7from datasets.data_utils import load_data_and_data_loaders
8
9def visualize_batch(frames, save_path=None, title="Video Sequences Batch", max_batch_size=8, max_seq_length=8):
10 # move to CPU and get dimensions
11 frames = frames.detach().cpu()
12 batch_size, seq_len, C, H, W = frames.shape
13 batch_size = min(batch_size, max_batch_size)
14 seq_len = min(seq_len, max_seq_length)
15 frames = frames[:batch_size, :seq_len]
16
17 # denormalize from [-1, 1] to [0, 1]
18 frames = (frames + 1) / 2
19 frames = torch.clamp(frames, 0, 1)
20 fig, axes = plt.subplots(batch_size, seq_len, figsize=(2 * seq_len, 2 * batch_size))
21
22 # single row/column case
23 if batch_size == 1:
24 axes = axes.reshape(1, -1)
25 if seq_len == 1:
26 axes = axes.reshape(-1, 1)
27
28 # plot frames
29 for i in range(batch_size):
30 for j in range(seq_len):
31 frame = frames[i, j].permute(1, 2, 0).numpy() # [H, W, C]
32
33 axes[i, j].imshow(frame)
34 axes[i, j].set_title(f'B{i}, T{j}', fontsize=10)
35 axes[i, j].axis('off')
36
37 # row and column labels
38 for i in range(batch_size):
39 axes[i, 0].set_ylabel(f'Batch {i}', fontsize=12, fontweight='bold')
40 for j in range(seq_len):
41 axes[0, j].set_title(f'Timestep {j}', fontsize=12, fontweight='bold')
42 plt.suptitle(title, fontsize=16, fontweight='bold')
43 plt.tight_layout()
44 if save_path:
45 plt.savefig(save_path, dpi=150, bbox_inches='tight')
46 print(f"Visualization saved to: {save_path}")
47
48 plt.show()
49
50def visualize_batch_with_stats(frames, save_path=None, title="Video Sequences Batch with Statistics"):
51 # Move to CPU and get dimensions

Callers 2

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected