当前位置:网站首页>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.2.7-2.13 AI industry weekly (issue 84): family responsibilities
- Shell之Unix运维常用命令
- 分布式事务-解决方案
- TCP server communication flow
- Basic exercise of test questions hexadecimal to decimal
- js解决浮点数相乘精度丢失问题
- 2022 a special equipment related management (elevator) simulation test and a special equipment related management (elevator) certificate examination
- CF1638E. Colorful operations Kodori tree + differential tree array
- LeetCode_53(最大子数组和)
- LeetCode_ 28 (implement strstr())
猜你喜欢
Research on medical knowledge atlas question answering system (I)
Tencent has five years of testing experience. It came to the interview to ask for 30K, and saw the so-called software testing ceiling
LM小型可编程控制器软件(基于CoDeSys)笔记十九:报错does not match the profile of the target
Maixll-Dock 快速上手
先有网络模型的使用及修改
The junior college students were angry for 32 days, four rounds of interviews, five hours of soul torture, and won Ali's offer with tears
2022年T电梯修理题库及模拟考试
MySQL winter vacation self-study 2022 12 (5)
2022 hoisting machinery command registration examination and hoisting machinery command examination registration
STM32 extended key scan
随机推荐
2022 tea master (intermediate) examination question bank and tea master (intermediate) examination questions and analysis
无器械健身
数据加载及预处理
OdeInt与GPU
Annual inventory review of Alibaba cloud's observable practices in 2021
LM小型可编程控制器软件(基于CoDeSys)笔记二十:plc通过驱动器控制步进电机
Simple implementation of slf4j
Difference between cookie and session
2022.2.7-2.13 AI industry weekly (issue 84): family responsibilities
The index is invalid
One click shell to automatically deploy any version of redis
LM小型可编程控制器软件(基于CoDeSys)笔记十九:报错does not match the profile of the target
2022年化工自动化控制仪表操作证考试题库及答案
How to view the changes and opportunities in the construction of smart cities?
How to do the performance pressure test of "Health Code"
Overview of the construction details of Meizhou veterinary laboratory
【硬十宝典】——2.【基础知识】开关电源各种拓扑结构的特点
Some tools that research dogs may need
CUDA development and debugging tool
神经网络的基本骨架-nn.Moudle的使用