跟着小土堆学pytorch(p9.Transforms的使用(二))

2.为什么使用Tensor数据类型

因为Tensor数据类型是复合结构,其中有用于计算梯度的参数

1.将代码放入pythong console中

 

Tensor:满足神经网络学习需要的参数的一种数据类型 

使用opencv中的cv2.imread()读取ndarray格式图片

import cv2
cv_img = cv2.imread(img_path)
from PIL import Image
from torch.utils.tensorboard import SummaryWriter
from torchvision import transforms

""""python的用法 ——》Tensor数据类型
    通过transform.ToTensor去解决两个问题
    1.transform如何使用
    2.为什么需要Tensor数据类型
"""

img_path = "dataset/train/bees/2822388965_f6dca2a275.jpg"
img = Image.open(img_path)
print(img)

writer = SummaryWriter("logs")

tensor_trans = transforms.ToTensor()
tensor_img = tensor_trans(img)

writer.add_image("Tensor_img",tensor_img)
writer.close()
(mypytorch) C:\Users\Administrator\PycharmProjects\learn_pytorch>tensorboard --logdir=logs 
TensorFlow installation not found - running with reduced feature set.
Serving TensorBoard on localhost; to expose to the network, use a proxy or pass --bind_all
TensorBoard 2.12.0 at http://localhost:6006/ (Press CTRL+C to quit)

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值