当前位置:网站首页>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 )
边栏推荐
- Software testing needs more and more talents. Why do you still not want to take this path?
- Shell之分析服务器日志命令集锦
- Measurement of quadrature axis and direct axis inductance of three-phase permanent magnet synchronous motor
- 【FTP】FTP连接时出现“227 Entering Passive Mode”的解决方法
- Daily algorithm & interview questions, 28 days of special training in large factories - the 13th day (array)
- OdeInt与GPU
- Leecode question brushing record 1332 delete palindrome subsequence
- Matters behind the construction of paint testing laboratory
- 2022年化工自动化控制仪表操作证考试题库及答案
- 神经网络-非线性激活
猜你喜欢

Daily question - line 10

2022年化工自动化控制仪表操作证考试题库及答案

Pytorch(一) —— 基本语法

Research on medical knowledge atlas question answering system (I)

Sorting out 49 reports of knowledge map industry conference | AI sees the future with wisdom

【硬十宝典】——1.【基础知识】电源的分类

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

The junior college students were angry for 32 days, four rounds of interviews, five hours of soul torture, and won Ali's offer with tears

Pytorch(三) —— 函数优化

常用的Transforms中的方法
随机推荐
Maixll dock quick start
数据加载及预处理
Thoughts on the construction of Meizhou cell room
Difficulties in the development of knowledge map & the importance of building industry knowledge map
LeetCode_58(最后一个单词的长度)
VR线上展览所具备应用及特色
Ten wastes of software research and development: the other side of research and development efficiency
2022年化工自动化控制仪表操作证考试题库及答案
Execution failed for task ‘:app:processDebugResources‘. > A failure occurred while executing com. and
Openresty rewrites the location of 302
如何看待智慧城市建设中的改变和机遇?
科研狗可能需要的一些工具
Advanced application of ES6 modular and asynchronous programming
The longest increasing subsequence and its optimal solution, total animal weight problem
Common UNIX Operation and maintenance commands of shell
pytorch 卷积操作
STM32扩展版 按键扫描
科研狗可能需要的一些工具
2022 t elevator repair question bank and simulation test
【硬十宝典】——1.【基础知识】电源的分类