MCPcopy Create free account
hub / github.com/pytorch/tutorials / show_landmarks_batch

Function show_landmarks_batch

beginner_source/data_loading_tutorial.py:381–397  ·  view source on GitHub ↗

Show image with landmarks for a batch of samples.

(sample_batched)

Source from the content-addressed store, hash-verified

379
380# Helper function to show a batch
381def show_landmarks_batch(sample_batched):
382 """Show image with landmarks for a batch of samples."""
383 images_batch, landmarks_batch = \
384 sample_batched['image'], sample_batched['landmarks']
385 batch_size = len(images_batch)
386 im_size = images_batch.size(2)
387 grid_border_size = 2
388
389 grid = utils.make_grid(images_batch)
390 plt.imshow(grid.numpy().transpose((1, 2, 0)))
391
392 for i in range(batch_size):
393 plt.scatter(landmarks_batch[i, :, 0].numpy() + i * im_size + (i + 1) * grid_border_size,
394 landmarks_batch[i, :, 1].numpy() + grid_border_size,
395 s=10, marker='.', c='r')
396
397 plt.title('Batch from dataloader')
398
399# if you are using Windows, uncomment the next line and indent the for loop.
400# you might need to go back and change ``num_workers`` to 0.

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected