当前位置:网站首页>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 )
边栏推荐
- [2020 overview] overview of link prediction based on knowledge map embedding
- 神经网络-使用Sequential搭建神经网络
- LM小型可编程控制器软件(基于CoDeSys)笔记十九:报错does not match the profile of the target
- Announcement on the list of Guangdong famous high-tech products to be selected in 2021
- 2022年上海市安全员C证考试题模拟考试题库及答案
- Matters behind the construction of paint testing laboratory
- 数据加载及预处理
- 2022 a special equipment related management (elevator) simulation test and a special equipment related management (elevator) certificate examination
- Leecode question brushing record 1310 subarray XOR query
- Shell之一键自动部署Redis任意版本
猜你喜欢

2022年T电梯修理题库及模拟考试

C -- array

Registration for R2 mobile pressure vessel filling test in 2022 and R2 mobile pressure vessel filling free test questions

The design points of voice dialogue system and the importance of multi round dialogue

Measurement of quadrature axis and direct axis inductance of three-phase permanent magnet synchronous motor

JS image path conversion Base64 format

STM32 photoresistor sensor & two channel AD acquisition

Maixll-Dock 快速上手

Registration of P cylinder filling examination in 2022 and analysis of P cylinder filling

2022年化工自动化控制仪表操作证考试题库及答案
随机推荐
STM32扩展版 按键扫描
技术分享| 融合调度中的广播功能设计
slf4j 简单实现
神经网络-卷积层
Summary of acl2021 information extraction related papers
Grey correlation cases and codes
All in all, the low code still needs to solve these four problems
Extension fragment
Matters behind the construction of paint testing laboratory
LeetCode_58(最后一个单词的长度)
Summary of testing experience - Testing Theory
Execution failed for task ‘:app:processDebugResources‘. > A failure occurred while executing com. and
【硬十宝典】——1.【基础知识】电源的分类
科研狗可能需要的一些工具
Maixll-Dock 使用方法
Shell之一键自动部署Redis任意版本
2022.2.7-2.13 AI industry weekly (issue 84): family responsibilities
STM32扩展板 温度传感器和温湿度传感器的使用
PR 2021 quick start tutorial, learn about the and functions of the timeline panel
[difficult] sqlserver2008r2, can you recover only some files when recovering the database?