当前位置:网站首页>pytorch中常用数据集的使用方法
pytorch中常用数据集的使用方法
2022-07-01 04:35:00 【booze-J】
文章
对于pytorch数据集的使用,示例代码如下:
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()])
# 关于官方数据集的使用还是关键要看pytorch的官方文档
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)
# 查看测试数据集中的第一个数据
# print(test_set[0])
# 查看测试数据集中的分类情况
# print(test_set.classes)
#
# 取出第一个数据中的图片(img)和分类结果(target)
# img,target = test_set[0]
# 查看图片数据的类型
# print(img)
# print(target)
# 输出类别
# print(test_set.classes[target])
# 查看图片
# img.show()
# 使用tensorboard显示tensor数据类型的图片
writer = SummaryWriter("logs")
for i in range(10):
# 取出数据中的图片(img)和分类结果(target)
img,target = test_set[i]
writer.add_image("test_set",img,i)
writer.close()
上述代码运行结果在tensorboard可视化:
代码train_set = torchvision.datasets.CIFAR10(root="./CIFAR10",train=True,transform=dataset_transform,download=True)中常用参数讲解
root:根目录,存放数据集的位置
train:若为True,则划分为训练数据集,若为False,则划分为测试数据集
transform:指定输入数据集处理方式
download:若为True,则会将数据集下载到root指定的目录下,否则不会下载
官方文档对参数的解释:
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.
注意
- 关于官方数据集的使用还是关键要看pytorch的官方文档
- 下载数据集的细节之处:知道下载链接(下载链接可以在源码中查看)之后可以不用使用代码下载了,使用迅雷来下载可能会更快。
- 要学会使用Pycharm中的
ctrl+p和ctrl+alt这两个快捷键 - pytorch官网
- pytorch官方数据集(下载数据集方法)
边栏推荐
- About the transmission pipeline of stage in spark
- Cmake selecting compilers and setting compiler options
- Why is Internet thinking not suitable for AI products?
- Difficulties in the development of knowledge map & the importance of building industry knowledge map
- TCP server communication flow
- Registration of P cylinder filling examination in 2022 and analysis of P cylinder filling
- 2. Use of classlist (element class name)
- Seven crimes of counting software R & D Efficiency
- Sorting out 49 reports of knowledge map industry conference | AI sees the future with wisdom
- Simple implementation of slf4j
猜你喜欢

2022.2.7-2.13 AI industry weekly (issue 84): family responsibilities

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

Tip of edge browser: enter+ctrl can automatically convert the address bar into a web address

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

js 图片路径转换base64格式

Offline installation of Wireshark 2.6.10

2022 G2 power station boiler stoker examination question bank and G2 power station boiler stoker simulation examination question bank

JVM栈和堆简介

Daily algorithm & interview questions, 28 days of special training in large factories - the 13th day (array)

Question bank and online simulation examination for special operation certificate of G1 industrial boiler stoker in 2022
随机推荐
VIM简易使用教程
Maixll-Dock 快速上手
Knowledge supplement: redis' basic data types and corresponding commands
JS rotation chart
Question bank and online simulation examination for special operation certificate of G1 industrial boiler stoker in 2022
Seven crimes of counting software R & D Efficiency
为什么香港服务器最适合海外建站使用
RDF query language SPARQL
Difficulties in the development of knowledge map & the importance of building industry knowledge map
MySQL advanced -- you will have a new understanding of MySQL
Odeint and GPU
扩展-Fragment
Leetcode learning - day 36
Concurrent mode of different performance testing tools
RuntimeError: “max_pool2d“ not implemented for ‘Long‘
Common UNIX Operation and maintenance commands of shell
LM small programmable controller software (based on CoDeSys) note 19: errors do not match the profile of the target
【硬十宝典】——2.【基础知识】开关电源各种拓扑结构的特点
2022 question bank and answers for safety production management personnel of hazardous chemical production units
Tip of edge browser: enter+ctrl can automatically convert the address bar into a web address