当前位置:网站首页>How to use common datasets in pytorch
How to use common datasets in pytorch
2022-07-01 04:44:00 【booze-J】
article
about pytorch Use of data sets , The sample code is as follows :
from torch.utils.tensorboard import SummaryWriter
from torchvision.transforms import Compose
from torchvision import transforms
import torchvision
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
dataset_transform = Compose([transforms.ToTensor()])
# The use of official data sets is still the key pytorch Official documents of
train_set = torchvision.datasets.CIFAR10(root="./CIFAR10",train=True,transform=dataset_transform,download=True)
test_set = torchvision.datasets.CIFAR10(root="./CIFAR10",train=False,transform=dataset_transform,download=True)
# View the first data in the test data set
# print(test_set[0])
# View the classification in the test data set
# print(test_set.classes)
#
# Take out the picture in the first data (img) And classification results (target)
# img,target = test_set[0]
# View the type of picture data
# print(img)
# print(target)
# Output category
# print(test_set.classes[target])
# view picture
# img.show()
# Use tensorboard Show tensor Pictures of data types
writer = SummaryWriter("logs")
for i in range(10):
# Take out the picture in the data (img) And classification results (target)
img,target = test_set[i]
writer.add_image("test_set",img,i)
writer.close()
The above code results in tensorboard visualization :
Code train_set = torchvision.datasets.CIFAR10(root="./CIFAR10",train=True,transform=dataset_transform,download=True) Explanation of common parameters in
root: root directory , Where to store the data set
train: if True, It is divided into training data sets , if False, It is divided into test data sets
transform: Specify how the input dataset is processed
download: if True, The data set will be downloaded to root Under the specified directory , Otherwise it won't download
Official documents Interpretation of parameters :
root (string) – Root directory of dataset where directory cifar-10-batches-py exists or will be saved to if download is set to True.
train (bool, optional) – If True, creates dataset from training set, otherwise creates from test set.
transform (callable, optional) – A function/transform that takes in an PIL image and returns a transformed version. E.g, transforms.RandomCrop
target_transform (callable, optional) – A function/transform that takes in the target and transforms it.
download (bool, optional) – If true, downloads the dataset from the internet and puts it in root directory. If dataset is already downloaded, it is not downloaded again.
Be careful
- The use of official data sets is still the key pytorch Official documents of
- Download the details of the dataset : Know the download link ( The download link can be viewed in the source code ) Then you can download without using the code , Using thunderbolt to download may be faster .
- Learn to use Pycharm Medium
ctrl+pandctrl+altBoth shortcuts - pytorch Official website
- pytorch Official data set ( Download dataset method )
边栏推荐
- 【FTP】FTP连接时出现“227 Entering Passive Mode”的解决方法
- Some tools that research dogs may need
- 2022年煤气考试题库及在线模拟考试
- Dual contractual learning: text classification via label aware data augmentation reading notes
- Daily question - line 10
- 神经网络的基本骨架-nn.Moudle的使用
- 无器械健身
- Leecode records the number of good segmentation of 1525 strings
- Basic exercise of test questions hexadecimal to decimal
- 神经网络-卷积层
猜你喜欢

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

STM32 photoresistor sensor & two channel AD acquisition

2022年上海市安全员C证考试题模拟考试题库及答案

This sideline workload is small, 10-15k, free unlimited massage

Research on medical knowledge atlas question answering system (I)
![[godot] unity's animator is different from Godot's animplayer](/img/51/48f40a7b6736d7f78040eabbbd3395.jpg)
[godot] unity's animator is different from Godot's animplayer

Section 27 remote access virtual private network workflow and experimental demonstration

LM small programmable controller software (based on CoDeSys) note 19: errors do not match the profile of the target

神经网络-使用Sequential搭建神经网络

pytorch中常用数据集的使用方法
随机推荐
2022 gas examination question bank and online simulation examination
Openresty rewrites the location of 302
Seven crimes of counting software R & D Efficiency
Common UNIX Operation and maintenance commands of shell
Take a cold bath
Selenium opens the Chrome browser and the settings page pops up: Microsoft defender antivirus to reset your settings
Cmake selecting compilers and setting compiler options
Maixll-Dock 快速上手
LM小型可编程控制器软件(基于CoDeSys)笔记二十:plc通过驱动器控制步进电机
分布式架构系统拆分原则、需求、微服务拆分步骤
Grey correlation cases and codes
Measurement of quadrature axis and direct axis inductance of three-phase permanent magnet synchronous motor
Question bank and answers for chemical automation control instrument operation certificate examination in 2022
分布式事务-解决方案
Dual Contrastive Learning: Text Classification via Label-Aware Data Augmentation 阅读笔记
神经网络-卷积层
2022 tea master (intermediate) examination question bank and tea master (intermediate) examination questions and analysis
2022年煤气考试题库及在线模拟考试
2022 t elevator repair new version test questions and t elevator repair simulation test question bank
The design points of voice dialogue system and the importance of multi round dialogue