当前位置:网站首页>Pytorch framework learning record 4 - the use of datasets (torchvision.dataset)
Pytorch framework learning record 4 - the use of datasets (torchvision.dataset)
2022-07-30 03:58:00 【Yuzu Roo】
Pytorch框架学习记录4——数据集的使用(torchvision.dataset)
1. 数据集
在pytorch官网中我们可以看到pytorchThe situation of the data set it is equipped with,and the type of the dataset、使用方法等.在这里,We choose the smaller datasetCIFAR10as our example dataset.
The calling and usage code of this dataset is as follows:
torchvision.datasets.CIFAR10(root: str, train: bool = True, transform: Optional[Callable] = None, target_transform: Optional[Callable] = None, download: bool = False)
参数说明:
- root ( string ) – 数据集的根目录,
cifar-10-batches-py如果下载设置为 True,则该目录存在或将保存到该目录. - train ( bool,optional ) – 如果为真,则从训练集创建数据集,否则从测试集创建.
- transform ( callable,optional ) – 一个函数/转换,它接受 PIL 图像并返回转换后的版本.例如,
transforms.RandomCrop - target_transform ( callable,optional ) – 接收目标并对其进行转换的函数/转换.
- download ( bool,optional ) – 如果为 true,则从 Internet 下载数据集并将其放在根目录中.如果数据集已经下载,则不会再次下载.
2. 使用实例
下载CIFAR10数据集后,Convert its type to tensor类型,并在tensorboard中进行展示.
import torchvision
from torch.utils.tensorboard import SummaryWriter
from torchvision.transforms import transforms
dataset_transform = transforms.Compose([
transforms.ToTensor()
])
train_set = torchvision.datasets.CIFAR10(root='./dataset', train=True, transform=dataset_transform, download=True)
test_set = torchvision.datasets.CIFAR10(root='./dataset', train=False, transform=dataset_transform, download=True)
writer = SummaryWriter('logs')
for i in range(10):
img, label = train_set[i]
writer.add_image('train10', img, i)
writer.close()
此外,You can also download directly from the link using your browser,下载完毕后,Also name one in the current directorydatasetfolder and put in,The above code does not make any changes,Manually downloaded datasets are automatically decompressed and corrected.

边栏推荐
- EasyCVR启动时报错“no such file or directory”,该如何解决?
- Sentinel 流量防卫兵
- flutter 记录学习不一样的动画(一)
- Pytorch框架学习记录4——数据集的使用(torchvision.dataset)
- Nacos installation and deployment
- Chapter 51 - Knowing the request header parameter analysis【2022-07-28】
- 小程序毕设作品之微信二手交易小程序毕业设计成品(5)任务书
- LoadBalancer 负载均衡
- Process priority nice
- 小程序毕设作品之微信二手交易小程序毕业设计成品(8)毕业设计论文模板
猜你喜欢

Has been empty, a straightforward, continue to copy the top off!

OpenFeign realize load balance

组织在线化:组织数字化变革的新趋势

EasyNVR平台级联到EasyCVR,视频播放一会就无法播放是什么原因?

Mini Program Graduation Works WeChat Second-hand Trading Mini Program Graduation Design Finished Works (4) Opening Report
![[Switch] Protocol-Oriented Programming in Swift: Introduction](/img/7a/6db558231a77ad9e739b571cf328d6.png)
[Switch] Protocol-Oriented Programming in Swift: Introduction

Nacos 安装与部署

小程序毕设作品之微信积分商城小程序毕业设计成品(5)任务书

小程序毕设作品之微信积分商城小程序毕业设计成品(4)开题报告

How to solve the error "no such file or directory" when EasyCVR starts?
随机推荐
小程序毕设作品之微信积分商城小程序毕业设计成品(2)小程序功能
Pytorch框架学习记录1——Dataset类代码实战
Send it to your friends and let TA treat you to fried chicken!
Nacos集群分区
After 5 years of Ali internship interview~
Resampling a uniformly sampled signal
Small application project works WeChat integral mall small program of graduation design (4) the opening report of finished product
星光不问赶路人!武汉校区小姐姐三个月成功转行软件测试,收获9k+13薪!
发给你的好友,让 TA 请你吃炸鸡!
Mini Program Graduation Works WeChat Points Mall Mini Program Graduation Design Finished Work (5) Task Book
Tcp编程
Mini Program Graduation Works WeChat Second-hand Trading Mini Program Graduation Design Finished Works (7) Interim Inspection Report
Hystrix service circuit breaker
TCP congestion control technology and acceleration principle of BBR
Roperties类配置文件&DOS查看主机网络情况
传统项目转型
forward与redirect的区别
小程序毕设作品之微信积分商城小程序毕业设计成品(4)开题报告
Nacos实现高可用
Has been empty, a straightforward, continue to copy the top off!