MCPcopy Create free account
hub / github.com/mindee/doctr / plot_samples

Function plot_samples

references/classification/utils.py:12–34  ·  view source on GitHub ↗
(images, targets)

Source from the content-addressed store, hash-verified

10
11
12def plot_samples(images, targets):
13 # Unnormalize image
14 num_samples = min(len(images), 12)
15 num_cols = min(len(images), 8)
16 num_rows = int(math.ceil(num_samples / num_cols))
17 _, axes = plt.subplots(num_rows, num_cols, figsize=(20, 5))
18 for idx in range(num_samples):
19 img = (255 * images[idx].numpy()).round().clip(0, 255).astype(np.uint8)
20 if img.shape[0] == 3 and img.shape[2] != 3:
21 img = img.transpose(1, 2, 0)
22
23 row_idx = idx // num_cols
24 col_idx = idx % num_cols
25
26 ax = axes[row_idx] if num_rows > 1 else axes
27 ax = ax[col_idx] if num_cols > 1 else ax
28
29 ax.imshow(img)
30 ax.set_title(targets[idx])
31 # Disable axis
32 for ax in axes.ravel():
33 ax.axis("off")
34 plt.show()
35
36
37def plot_recorder(lr_recorder, loss_recorder, beta: float = 0.95, **kwargs) -> None:

Callers 2

mainFunction · 0.90
mainFunction · 0.90

Calls 1

showMethod · 0.45

Tested by

no test coverage detected