当前位置:网站首页>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
边栏推荐
- 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
- 2022-02-15 (399. Division evaluation)
- How to do the performance pressure test of "Health Code"
- RuntimeError: mean(): input dtype should be either floating point or complex dtypes.Got Long instead
- VR线上展览所具备应用及特色
- LeetCode_28(实现 strStr())
- Dual contractual learning: text classification via label aware data augmentation reading notes
- [difficult] sqlserver2008r2, can you recover only some files when recovering the database?
- Shell之分析服务器日志命令集锦
- Selenium opens the Chrome browser and the settings page pops up: Microsoft defender antivirus to reset your settings
猜你喜欢
随机推荐
Codeworks round 449 (Div. 1) C. Kodori tree template
All in all, the low code still needs to solve these four problems
[ue4] event distribution mechanism of reflective event distributor and active call event mechanism
【FTP】FTP连接时出现“227 Entering Passive Mode”的解决方法
How do I sort a list of strings in dart- How can I sort a list of strings in Dart?
2022危险化学品生产单位安全生产管理人员题库及答案
RDF query language SPARQL
总结全了,低代码还需要解决这4点问题
LM small programmable controller software (based on CoDeSys) note 20: PLC controls stepping motor through driver
LeetCode_35(搜索插入位置)
LM小型可编程控制器软件(基于CoDeSys)笔记十九:报错does not match the profile of the target
Cmake selecting compilers and setting compiler options
TCP server communication flow
Difference between cookie and session
【硬十宝典】——2.【基础知识】开关电源各种拓扑结构的特点
Applications and features of VR online exhibition
Sorting out 49 reports of knowledge map industry conference | AI sees the future with wisdom
分布式事务-解决方案
pytorch神经网络搭建 模板
Question bank and online simulation examination for special operation certificate of G1 industrial boiler stoker in 2022









