当前位置:网站首页>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 question bank and answers for safety production management personnel of hazardous chemical production units
- 2022年T电梯修理题库及模拟考试
- CF1638E. Colorful operations Kodori tree + differential tree array
- Pytorch(三) —— 函数优化
- This sideline workload is small, 10-15k, free unlimited massage
- [difficult] sqlserver2008r2, can you recover only some files when recovering the database?
- 【FTP】FTP连接时出现“227 Entering Passive Mode”的解决方法
- LeetCode_53(最大子数组和)
- 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小型可编程控制器软件(基于CoDeSys)笔记十九:报错does not match the profile of the target
猜你喜欢

LM小型可编程控制器软件(基于CoDeSys)笔记十九:报错does not match the profile of the target

神经网络-非线性激活

Research on medical knowledge atlas question answering system (I)

Applications and features of VR online exhibition

神经网络的基本骨架-nn.Moudle的使用

Openresty rewrites the location of 302

OdeInt与GPU

Pytorch(三) —— 函数优化

How to do the performance pressure test of "Health Code"

2022年上海市安全员C证考试题模拟考试题库及答案
随机推荐
细数软件研发效能的七宗罪
【FTP】FTP连接时出现“227 Entering Passive Mode”的解决方法
软件研发的十大浪费:研发效能的另一面
The design points of voice dialogue system and the importance of multi round dialogue
Execution failed for task ‘:app:processDebugResources‘. > A failure occurred while executing com. and
Fitness without equipment
slf4j 简单实现
Introduction to JVM stack and heap
技术分享| 融合调度中的广播功能设计
How to do the performance pressure test of "Health Code"
LM small programmable controller software (based on CoDeSys) note 20: PLC controls stepping motor through driver
Odeint and GPU
RDF query language SPARQL
VR线上展览所具备应用及特色
CF1638E. Colorful operations Kodori tree + differential tree array
JS rotation chart
Leecode question brushing record 1310 subarray XOR query
2022 a special equipment related management (elevator) simulation test and a special equipment related management (elevator) certificate examination
2022.2.7-2.13 AI industry weekly (issue 84): family responsibilities
How to use maixll dock