How to add pictures add_image and add_images in the form of torch.Tensor in tensorboard in Pytorch
Pytorch in the use of tensorboard in the form of how to add torch.Tensor pictures add_image and add_images, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can get something.
Add_image and add_images
Code:
From torch.utils.tensorboard import SummaryWriterimport numpy as npimg = np.zeros ((3,100,100)) img [0] = np.arange (0,100,100) .reshape (100,100) / 10000img [1] = 1-np.arange (0,100,100) .reshape (100,100) / 10000img_HWC = np.zeros ((100,100,3)) img_HWC [:,: 0] = np.arange (0,100,100) .reshape (10000) / 10000img_HWC [:,: 1] = 1-np.arange (0, 10000). Reshape (100,100) / 10000writer = SummaryWriter () writer.add_image ('my_image', img, 0) # If you have non-default dimension setting, set the dataformats argument.writer.add_image (' my_image_HWC', img_HWC, 0, dataformats='HWC') writer.close () # tensorboard-- logdir=runs
Show the running results:
Code:
From torch.utils.tensorboard import SummaryWriterimport numpy as npimg_batch = np.zeros ((16,3,100,100) for i in range (16): img_batch [I, 0] = np.arange (0,100) .reshape (100,100) / 10000 / 16 * I img_batch [I, 1] = (1-np.arange (0,10000) .reshape (100,100) / 10000) / 16 * iwriter = SummaryWriter () writer.add_images ('my_image_batch', img_batch) 0) writer.close () # tensorboard-- logdir=runs
Show the running results:
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.