当前位置:网站首页>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
边栏推荐
- 神经网络-卷积层
- 2022 G2 power station boiler stoker examination question bank and G2 power station boiler stoker simulation examination question bank
- Shell之Unix运维常用命令
- 解决qiankun中子应用外链文件无法获取
- Openresty rewrites the location of 302
- The index is invalid
- 2022 polymerization process test questions and simulation test
- slf4j 简单实现
- How to do the performance pressure test of "Health Code"
- 2022年T电梯修理题库及模拟考试
猜你喜欢

分布式-总结列表
![[pat (basic level) practice] - [simple simulation] 1064 friends](/img/37/0ef0f8aae15ae574be1d76c97497c9.jpg)
[pat (basic level) practice] - [simple simulation] 1064 friends

Section 27 remote access virtual private network workflow and experimental demonstration

About the transmission pipeline of stage in spark

【硬十宝典】——2.【基础知识】开关电源各种拓扑结构的特点

Sorting out 49 reports of knowledge map industry conference | AI sees the future with wisdom

Daily algorithm & interview questions, 28 days of special training in large factories - the 13th day (array)

神经网络-非线性激活

Dede collection plug-in does not need to write rules

先有网络模型的使用及修改
随机推荐
STM32扩展板 数码管显示
Basic usage, principle and details of session
Codeforces Round #771 (Div. 2) ABCD|E
MySQL winter vacation self-study 2022 12 (5)
LM small programmable controller software (based on CoDeSys) note 19: errors do not match the profile of the target
VIM easy to use tutorial
Ten wastes of software research and development: the other side of research and development efficiency
How to do the performance pressure test of "Health Code"
2022 polymerization process test questions and simulation test
Maixll-Dock 快速上手
Kodori tree board
Some tools that research dogs may need
Dede collection plug-in does not need to write rules
2022年G1工业锅炉司炉特种作业证考试题库及在线模拟考试
2022 t elevator repair new version test questions and t elevator repair simulation test question bank
Summary of acl2021 information extraction related papers
LeetCode_35(搜索插入位置)
Daily question - line 10
C - detailed explanation of operators and summary of use cases
STM32 光敏电阻传感器&两路AD采集