当前位置:网站首页>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 polymerization process test questions and simulation test
- Construction of Meizhou nursing laboratory: equipment configuration
- 2022年上海市安全员C证考试题模拟考试题库及答案
- Some tools that research dogs may need
- LM小型可编程控制器软件(基于CoDeSys)笔记二十:plc通过驱动器控制步进电机
- 2022年G1工业锅炉司炉特种作业证考试题库及在线模拟考试
- js解决浮点数相乘精度丢失问题
- STM32扩展版 按键扫描
- How do I sort a list of strings in dart- How can I sort a list of strings in Dart?
- This sideline workload is small, 10-15k, free unlimited massage
猜你喜欢

VIM easy to use tutorial

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

2022.2.7-2.13 AI industry weekly (issue 84): family responsibilities

RuntimeError: “max_pool2d“ not implemented for ‘Long‘

C -- array

Pytorch(四) —— 可视化工具 Visdom

软件研发的十大浪费:研发效能的另一面

分布式锁的实现

C - detailed explanation of operators and summary of use cases

Software testing needs more and more talents. Why do you still not want to take this path?
随机推荐
pytorch神经网络搭建 模板
How to use maixll dock
Daily algorithm & interview questions, 28 days of special training in large factories - the 13th day (array)
分布式全局唯一ID解决方案详解
Tencent has five years of testing experience. It came to the interview to ask for 30K, and saw the so-called software testing ceiling
JS image path conversion Base64 format
All in all, the low code still needs to solve these four problems
Registration for R2 mobile pressure vessel filling test in 2022 and R2 mobile pressure vessel filling free test questions
常用的Transforms中的方法
LM small programmable controller software (based on CoDeSys) note 19: errors do not match the profile of the target
Day 52 - tree problem
Thoughts on the construction of Meizhou cell room
Dede collection plug-in does not need to write rules
2022 tea master (intermediate) examination question bank and tea master (intermediate) examination questions and analysis
2022.2.7-2.13 AI industry weekly (issue 84): family responsibilities
2022 polymerization process test questions and simulation test
Common interview questions ①
Caijing 365 stock internal reference | the first IPO of Beijing stock exchange; the subsidiary of the recommended securities firm for gambling and gambling, with a 40% discount
解决qiankun中子应用外链文件无法获取
slf4j 简单实现