mirror of
https://github.com/clearml/clearml
synced 2025-02-07 13:23:40 +00:00
Add PyTorch Tensorboard toy example
This commit is contained in:
parent
9cff3d44d9
commit
5270ca3cdc
26
examples/tensorboard_toy_pytorch.py
Normal file
26
examples/tensorboard_toy_pytorch.py
Normal file
@ -0,0 +1,26 @@
|
||||
import numpy as np
|
||||
from PIL import Image
|
||||
from torch.utils.tensorboard import SummaryWriter
|
||||
|
||||
from trains import Task
|
||||
task = Task.init(project_name='examples', task_name='pytorch tensorboard toy example')
|
||||
|
||||
|
||||
writer = SummaryWriter(log_dir='/tmp/tensorboard_logs')
|
||||
|
||||
# convert to 4d [batch, col, row, RGB-channels]
|
||||
image_open = Image.open('./samples/picasso.jpg')
|
||||
image = np.asarray(image_open)
|
||||
image_gray = image[:, :, 0][np.newaxis, :, :, np.newaxis]
|
||||
image_rgba = np.concatenate((image, 255*np.atleast_3d(np.ones(shape=image.shape[:2], dtype=np.uint8))), axis=2)
|
||||
image_rgba = image_rgba[np.newaxis, :, :, :]
|
||||
image = image[np.newaxis, :, :, :]
|
||||
|
||||
writer.add_image("test/first", image[0], dataformats='HWC')
|
||||
writer.add_image("test_gray/second", image_gray[0], dataformats='HWC')
|
||||
writer.add_image("test_rgba/third", image_rgba[0], dataformats='HWC')
|
||||
# writer.add_image("image/first_series", image, max_outputs=10)
|
||||
# writer.add_image("image_gray/second_series", image_gray, max_outputs=10)
|
||||
# writer.add_image("image_rgba/third_series", image_rgba, max_outputs=10)
|
||||
|
||||
print('Done!')
|
Loading…
Reference in New Issue
Block a user