当前位置:网站首页>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
边栏推荐
- LeetCode_35(搜索插入位置)
- C - detailed explanation of operators and summary of use cases
- Construction of Meizhou nursing laboratory: equipment configuration
- Leecode question brushing record 1310 subarray XOR query
- Dual contractual learning: text classification via label aware data augmentation reading notes
- Question bank and answers for chemical automation control instrument operation certificate examination in 2022
- I also gave you the MySQL interview questions of Boda factory. If you need to come in and take your own
- Measurement of quadrature axis and direct axis inductance of three-phase permanent magnet synchronous motor
- 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
- LM small programmable controller software (based on CoDeSys) note 20: PLC controls stepping motor through driver
猜你喜欢
TCP server communication flow
2022危险化学品生产单位安全生产管理人员题库及答案
STM32扩展板 温度传感器和温湿度传感器的使用
Sorting out 49 reports of knowledge map industry conference | AI sees the future with wisdom
2022年G1工业锅炉司炉特种作业证考试题库及在线模拟考试
2022.2.7-2.13 AI industry weekly (issue 84): family responsibilities
Difficulties in the development of knowledge map & the importance of building industry knowledge map
Kodori tree board
LM小型可编程控制器软件(基于CoDeSys)笔记十九:报错does not match the profile of the target
Why is Internet thinking not suitable for AI products?
随机推荐
Fitness without equipment
LeetCode_28(实现 strStr())
Selenium opens the Chrome browser and the settings page pops up: Microsoft defender antivirus to reset your settings
分布式架构系统拆分原则、需求、微服务拆分步骤
Software testing needs more and more talents. Why do you still not want to take this path?
2022 question bank and answers for safety production management personnel of hazardous chemical production units
洗个冷水澡吧
RuntimeError: “max_pool2d“ not implemented for ‘Long‘
分布式全局唯一ID解决方案详解
VIM easy to use tutorial
[godot] unity's animator is different from Godot's animplayer
[FTP] common FTP commands, updating continuously
STM32 photoresistor sensor & two channel AD acquisition
JVM栈和堆简介
Shell之一键自动部署Redis任意版本
神经网络-最大池化的使用
LeetCode_66(加一)
slf4j 简单实现
2022.2.7-2.13 AI industry weekly (issue 84): family responsibilities
Openresty rewrites the location of 302