当前位置:网站首页>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 )
边栏推荐
- 2022年化工自动化控制仪表操作证考试题库及答案
- Pytorch(三) —— 函数优化
- STM32扩展板 温度传感器和温湿度传感器的使用
- pytorch中常用数据集的使用方法
- How to do the performance pressure test of "Health Code"
- Dual contractual learning: text classification via label aware data augmentation reading notes
- Collect the annual summary of laws, regulations, policies and plans related to trusted computing of large market points (national, ministerial, provincial and municipal)
- 解决qiankun中子应用外链文件无法获取
- JS image path conversion Base64 format
- Sorting out 49 reports of knowledge map industry conference | AI sees the future with wisdom
猜你喜欢

神经网络-最大池化的使用

无器械健身

测量三相永磁同步电机的交轴直轴电感

分布式全局唯一ID解决方案详解

STM32扩展板 温度传感器和温湿度传感器的使用

One click shell to automatically deploy any version of redis

Question bank and online simulation examination for special operation certificate of G1 industrial boiler stoker in 2022

Registration of P cylinder filling examination in 2022 and analysis of P cylinder filling
![[2020 overview] overview of link prediction based on knowledge map embedding](/img/69/22983c5f37bb67a8dc0e2b87c73238.jpg)
[2020 overview] overview of link prediction based on knowledge map embedding

【硬十宝典】——2.【基础知识】开关电源各种拓扑结构的特点
随机推荐
LM小型可编程控制器软件(基于CoDeSys)笔记十九:报错does not match the profile of the target
C#读写应用程序配置文件App.exe.config,并在界面上显示
Tencent has five years of testing experience. It came to the interview to ask for 30K, and saw the so-called software testing ceiling
TCP server communication flow
神经网络-最大池化的使用
无器械健身
Registration for R2 mobile pressure vessel filling test in 2022 and R2 mobile pressure vessel filling free test questions
Question bank and online simulation examination for special operation certificate of G1 industrial boiler stoker in 2022
Pytorch(二) —— 激活函数、损失函数及其梯度
C language games (I) -- guessing games
Thoughts on the construction of Meizhou cell room
2022 hoisting machinery command registration examination and hoisting machinery command examination registration
先有网络模型的使用及修改
分布式架构系统拆分原则、需求、微服务拆分步骤
LeetCode_35(搜索插入位置)
The longest increasing subsequence and its optimal solution, total animal weight problem
slf4j 简单实现
Leecode record 1351 negative numbers in statistical ordered matrix
Dede collection plug-in does not need to write rules
神经网络-卷积层