当前位置:网站首页>Use of dataloader
Use of dataloader
2022-07-01 04:44:00 【booze-J】
List of articles
Dataloder Official documents
Dataloader The example code of using is as follows :
from torch.utils.data import DataLoader
from torch.utils.tensorboard import SummaryWriter
import torchvision
# Prepared test data set
test_data = torchvision.datasets.CIFAR10(root="./CIFAR10",train=False,transform=torchvision.transforms.ToTensor(),download=True)
# Preparation for loading dataset
test_loader = DataLoader(dataset=test_data,batch_size=4,shuffle=True,num_workers=0,drop_last=False)
'''
batch_size: How many pieces of data to process each time
shuffle: When fetching data in the second cycle , Whether the order is out of order ,True To disrupt
num_workers: Number of processes selected
drop_last: Whether to remove the redundant data in the tail ,True To remove
'''
# The first picture and classification results in the test data set
img,target = test_data[0]
print(img.shape)
print(target)
writer = SummaryWriter("logs")
step = 0
# Premise batch_size=4
for data in test_loader:
imgs,targets = data
# example :torch.Size([4, 3, 32, 32]) 4 representative 4 A picture 3 Number of channels representing the picture The size is 32*32 Pictures of the
print(imgs.shape)
# example :tensor([3, 1, 9, 0]) Categories of four pictures
print(targets)
# Use tensorboard Visualizing
writer.add_images("test_data",imgs,step) # Pay attention to the use of add_images instead of add_image Oh , because imgs yes 4 individual tensor A collection of data type pictures
step+=1
writer.close()
The above code results in tensorboard visualization :

Every step is 4 Zhang , It can also be seen here that dataloader in batch_size The function of parameters !

dataloader in batch_size It's the equivalent of dataset pack , Take the whole packaged part every time for subsequent operations , The figure above is easy to understand , take batch_size Set the value of the number of pictures (img) And classification results (target) Pack them separately into imgs,targets.
The above code should Be careful The place of :
- writer.add_images(“test_data”,imgs,step) # Pay attention to the use of add_images instead of add_image Oh , because imgs yes 4 individual tensor A collection of data type pictures
- Learn to read official documents :Dataloder Official documents
边栏推荐
- Shell之分析服务器日志命令集锦
- 【FTP】FTP常用命令,持续更新中……
- 2022危险化学品生产单位安全生产管理人员题库及答案
- Fitness without equipment
- Daily algorithm & interview questions, 28 days of special training in large factories - the 13th day (array)
- Summary of acl2021 information extraction related papers
- 先有网络模型的使用及修改
- [FTP] the solution to "227 entering passive mode" during FTP connection
- 数据加载及预处理
- STM32扩展板 数码管显示
猜你喜欢

Research on medical knowledge atlas question answering system (I)

LM小型可编程控制器软件(基于CoDeSys)笔记十九:报错does not match the profile of the target

Shell之一键自动部署Redis任意版本

分布式全局唯一ID解决方案详解

pytorch 卷积操作

Simple implementation of slf4j

Strategic suggestions and future development trend of global and Chinese vibration isolator market investment report 2022 Edition

Applications and features of VR online exhibition

分布式架构系统拆分原则、需求、微服务拆分步骤

Pytest automated testing - compare robotframework framework
随机推荐
分布式全局唯一ID解决方案详解
[FTP] common FTP commands, updating continuously
分布式-总结列表
pytorch神经网络搭建 模板
手动实现一个简单的栈
LM小型可编程控制器软件(基于CoDeSys)笔记二十:plc通过驱动器控制步进电机
科研狗可能需要的一些工具
扩展-Fragment
Section 27 remote access virtual private network workflow and experimental demonstration
Announcement on the list of Guangdong famous high-tech products to be selected in 2021
科研狗可能需要的一些工具
LM small programmable controller software (based on CoDeSys) note 19: errors do not match the profile of the target
测量三相永磁同步电机的交轴直轴电感
解决qiankun中子应用外链文件无法获取
Day 52 - tree problem
2022.2.7-2.13 AI industry weekly (issue 84): family responsibilities
Grey correlation cases and codes
Some tools that research dogs may need
Dual Contrastive Learning: Text Classification via Label-Aware Data Augmentation 阅读笔记
How to use maixll dock