【03】google Colab |pytorch TensorBoard add_image 代码实战 免费GPU google Colaboratory 使用教程

0 前言

接着上一篇:【02】google Colab |pytorch Dataset类代码实战 免费GPU google Colaboratory 使用教程

这次要说的是pytorch TensorBoard add_image 代码实战,还是在google Colab (免费GPU)上操作。
b站操作视频:

1 数据集下载

蚂蚁蜜蜂/练手数据集:链接: https://pan.baidu.com/s/1jZoTmoFzaTLWh4lKBHVbEA 密码: 5suq

2 代码与结果

# Mount google drive
from google.colab import drive
drive.flush_and_unmount()
drive.mount('/content/drive', force_remount=False)
from torch.utils.tensorboard import SummaryWriter
import numpy as np
from PIL import Image

writer = SummaryWriter('logs')
image_path = './drive/MyDrive/AI/practice_dataset/train/ants_image/1030023514_aad5c608f9.jpg'
img_PIL = Image.open(image_path)
img_array = np.array(img_PIL)
print(img_array.shape)

writer.add_image('test',img_array,1,dataformats='HWC')
writer.close()
image_path = './drive/MyDrive/AI/practice_dataset/train/ants_image/1269756697_0bce92cdab.jpg'
img_PIL = Image.open(image_path)
img_array = np.array(img_PIL)
print(img_array.shape)

writer.add_image('test',img_array,2,dataformats='HWC')
writer.close()


在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

3 参考

https://www.bilibili.com/video/BV1hE411t7RN?p=9

猜你喜欢

转载自blog.csdn.net/WhiffeYF/article/details/127344940