当前位置:网站首页>PyTorch入门:(四)torchvision中数据集的使用
PyTorch入门:(四)torchvision中数据集的使用
2022-08-08 18:59:00 【Here_SDUT】
前言:本文为学习 PyTorch深度学习快速入门教程(绝对通俗易懂!)【小土堆】时记录的 Jupyter 笔记,部分截图来自视频中的课件。
dataset的使用
在 Torchvision 中有很多经典数据集可以下载使用,在官方文档中可以看到具体有哪些数据集可以使用:
下面以CIFAR10数据集为例,演示下载使用的流程,在官方文档中可以看到,下载CIFAR10数据集需要的参数:
- root表示下载路径
- train表示下载数据为数据集还是训练集
- download表示是否下载(如果本地有则不需要下载)
import torchvision
train_set = torchvision.datasets.CIFAR10(root="./dataset_CIFAR10", train=True, download=True) # 下载训练集
test_set = torchvision.datasets.CIFAR10(root="./dataset_CIFAR10", train=False, download=True) # 下载测试集
Downloading https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz to ./dataset_CIFAR10\cifar-10-python.tar.gz
98.7%
Files already downloaded and verified
可以看到在终端中会显示正在下载,如果下载缓慢的话,可以将连接复制到离线下载软件(如迅雷)中进行下载。
# 查看图片和label
img,target = test_set[0]
img
test_set.classes[target]
'cat'
from torch.utils.tensorboard import SummaryWriter
dataset_transform = torchvision.transforms.Compose([
torchvision.transforms.ToTensor()
])
train_set = torchvision.datasets.CIFAR10(root="./dataset_CIFAR10", train=True,transform=dataset_transform, download=False) # 转换训练集
test_set = torchvision.datasets.CIFAR10(root="./dataset_CIFAR10", train=False,transform=dataset_transform, download=False) # 转换测试集
writer = SummaryWriter("dataset_CIFAR10_tensor")
for i in range(10):
img, target = train_set[i]
writer.add_image("test_set", img, i)
writer.close()
在tensorboard输出后,在终端中输入命令启动tensorboard,然后可以查看图片:
dataloader的使用
主要参数:
边栏推荐
- Goose Factory Robot Dog Fancy Crossing 10m Plum Blossom Pile: Front Flip, Single Pile Jump, Get Up and Bow... No stumble in the whole process
- Laravel queue consumption instance and timed task add task consumption
- 01. Preface
- 最长子串(长沙理工大学第十一届程序设计竞赛 离线 做了n天.....崩溃了)
- oracle视图v$active_session_history,dba_hist_active_session_history如何记录IP地址
- ABAP 报表中如何给报表的输入参数增添 F4 Value Help
- USB CY68013设备描述符识别失败
- 请问shake数据库中mongoshake同步过程中,src_mongo挂了,同步服务不会退出吗?
- n个数取出r个数排列
- [极客大挑战 2019]BuyFlag&&[HCTF 2018]admin
猜你喜欢
企业进行知识共享的好处有哪些?
How to add F4 Value Help to the input parameters of the report in the ABAP report
Lecture 4: Database Definition Language of DDL Type of SQL Statements
架构设计基本原则
ABAP 报表中如何给报表的输入参数增添 F4 Value Help
Build DG will increase the amount of lead to archive log problem
Research on ORACLE subqueries that lead to inability to push predicates
在Unity URP中实现Forward+
Rethinking HTAP database caused by rereading GPDB and TiDB papers
[MRCTF2020]你传你码呢
随机推荐
Flush can buy stock?Is it safe to buy stocks?
n个数取出r个数排列
一起了解分层架构&SOA架构
Smobiler的复杂控件的由来与创造
架构设计基本原则
Dataworks上的ODPS spark处理数据会比直接用ODPS SQL效率高吗?
Monaco-Editor 多人协作 编辑器
【761. 特殊的二进制序列】
LabVIEW报错“仪器IO助手未正确安装”
Laravel 5.8 Notes
Is it safe to open an account with Qiniu Business School?Is it reliable to open an account?
hdu2018 母牛的故事(模拟)
OpenSSH生成的私钥如何在putty中使用?
Advanced CAD practice (2)
nyoj 712 探 寻 宝 藏(双线dp 第六届河南省程序设计大赛)
请问在MAXCOMPUTE SQL 里有没有函数判断string 是否为数字?
请问shake数据库中mongoshake同步过程中,src_mongo挂了,同步服务不会退出吗?
oracle视图v$active_session_history,dba_hist_active_session_history如何记录IP地址
Monaco-Editor Multiplayer Collaboration Editor
对话框管理器第六章:消息循环中的细节