当前位置:网站首页>Pytorch framework learning record 5 - the use of DataLoader
Pytorch framework learning record 5 - the use of DataLoader
2022-07-30 03:57:00 【Yuzu Roo】
Pytorch框架学习记录5——DataLoader的使用
1. DataLoader方法介绍
Pytorch官网上对DataLoader方法进行了详细的介绍,数据加载器.结合数据集和采样器,并提供给定数据集的可迭代对象.DataLoader支持具有单进程或多进程加载、自定义加载顺序和可选的自动批处理(整理)和内存固定的地图样式和可迭代样式数据集.
torch.utils.data.DataLoader(dataset, batch_size=1, shuffle=None, sampler=None, batch_sampler=None, num_workers=0, collate_fn=None, pin_memory=False, drop_last=False, timeout=0, worker_init_fn=None, multiprocessing_context=None, generator=None, *, prefetch_factor=2, persistent_workers=False, pin_memory_device='')
参数
- dataset ( Dataset ) – 从中加载数据的数据集.
- batch_size ( int,optional ) – 每批要加载多少样本(默认值:
1). - shuffle ( bool,optional ) – 设置为
True在每个 epoch 重新洗牌数据(默认值:False). - num_workers ( int,optional ) – 用于数据加载的子进程数.
0表示数据将在主进程中加载.(默认:0) - drop_last ( bool,optional ) –
True如果数据集大小不能被批次大小整除,则设置为丢弃最后一个不完整的批次.如果False数据集的大小不能被批大小整除,那么最后一批将更小.(默认:False)
2. 实例
这里使用CIFAR10数据集,通过DataLoadermethod to convert the dataset to64一组打包,在windows系统中num_workers=0,最后在tensorboardThe packaged images will be displayed in.
注意,For packaged pictures,使用的方法是add_images()方法,Use a single imageadd_image()方法
import torchvision
from torch.utils.data import DataLoader
from torch.utils.tensorboard import SummaryWriter
train_set = torchvision.datasets.CIFAR10(root='C:\\Users\\hp\\PycharmProjects\\pythonProject\\Pytorch_Learning\\p11-dataset_transform\\dataset',
train=True, transform=torchvision.transforms.ToTensor(), download=True)
train_loader = DataLoader(dataset=train_set, batch_size=64, shuffle=True, num_workers=0, drop_last=False)
writer = SummaryWriter("logs")
step = 0
for data in train_loader:
img, target = data
writer.add_images("test_data", img, step)
step += 1
writer.close()

边栏推荐
- 2022-07-29 第四小组 修身课 学习笔记(every day)
- Advanced Microservices Cloud Alibaba
- 小程序毕设作品之微信二手交易小程序毕业设计成品(3)后台功能
- 一起来学习flutter 的布局组件
- ospf map
- Mini Program Graduation Works WeChat Second-hand Trading Mini Program Graduation Design Finished Works (6) Question Opening Reply PPT
- Introduction to management for technical people 1: What is management
- 一直空、一直爽,继续抄顶告捷!
- 小程序毕设作品之微信二手交易小程序毕业设计成品(8)毕业设计论文模板
- Nacos集群分区
猜你喜欢
![[Switch] Protocol-Oriented Programming in Swift: Introduction](/img/7a/6db558231a77ad9e739b571cf328d6.png)
[Switch] Protocol-Oriented Programming in Swift: Introduction

Chapter 51 - Knowing the request header parameter analysis【2022-07-28】

Small application project works WeChat integral mall small program of graduation design (4) the opening report of finished product

对均匀采样信号进行重采样

Introduction to management for technical people 1: What is management

How to solve the error "no such file or directory" when EasyCVR starts?

Transformation of traditional projects

Mini Program Graduation Works WeChat Points Mall Mini Program Graduation Design Finished Products (3) Background Functions

弘玑再度入围Gartner 2022 RPA魔力象限并实现位置大幅跃升

LoadBalancer load balancing
随机推荐
spicy(二)unit hooks
TCP congestion control technology and acceleration principle of BBR
day10--在Linux上安装mysql
LoadBalancer 负载均衡
Taobao/Tmall get the list of sold product orders API
Nacos achieves high availability
小程序毕设作品之微信积分商城小程序毕业设计成品(2)小程序功能
2022-07-29 Group 4 Self-cultivation class study notes (every day)
Nacos 安装与部署
Nacos配置中心
RRU、BBU、AAU
Redis【超详解!!!】
小程序毕设作品之微信二手交易小程序毕业设计成品(6)开题答辩PPT
小程序毕设作品之微信二手交易小程序毕业设计成品(8)毕业设计论文模板
Operational configuration: How to run multiple EasyCVR programs as a service in one server?
Nacos集群分区
New interface - API interface for "Taote" keyword search
Boutique: Taobao/Tmall Get Order Details API for Purchased Products
护网行动基本介绍
TCP拥塞控制技术 与BBR的加速原理