当前位置:网站首页>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官方数据集(下载数据集方法)
边栏推荐
- 206. reverse linked list
- AssertionError assert I.ndim == 4 and I.shape[1] == 3
- How to view the changes and opportunities in the construction of smart cities?
- [difficult] sqlserver2008r2, can you recover only some files when recovering the database?
- Tip of edge browser: enter+ctrl can automatically convert the address bar into a web address
- Maixll-Dock 快速上手
- How to do the performance pressure test of "Health Code"
- 神经网络-最大池化的使用
- 2022危险化学品生产单位安全生产管理人员题库及答案
- Shell之Unix运维常用命令
猜你喜欢

Dual Contrastive Learning: Text Classification via Label-Aware Data Augmentation 阅读笔记

Openresty rewrites the location of 302

Task04 | statistiques mathématiques

尺取法:有效三角形的个数

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

Difficulties in the development of knowledge map & the importance of building industry knowledge map

I also gave you the MySQL interview questions of Boda factory. If you need to come in and take your own

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

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

2022 a special equipment related management (elevator) simulation test and a special equipment related management (elevator) certificate examination
随机推荐
Applications and features of VR online exhibition
Dual Contrastive Learning: Text Classification via Label-Aware Data Augmentation 阅读笔记
C language games (I) -- guessing games
Talk about testdeploy
Caijing 365 stock internal reference | the first IPO of Beijing stock exchange; the subsidiary of the recommended securities firm for gambling and gambling, with a 40% discount
数据加载及预处理
What are permissions? What are roles? What are users?
[2020 overview] overview of link prediction based on knowledge map embedding
Codeworks round 449 (Div. 1) C. Kodori tree template
[learn C and fly] S1E20: two dimensional array
All in all, the low code still needs to solve these four problems
Odeint et GPU
Difference between cookie and session
如何看待智慧城市建设中的改变和机遇?
什么是uid?什么是Auth?什么是验证器?
[leetcode skimming] February summary (updating)
TCP/IP 详解(第 2 版) 笔记 / 3 链路层 / 3.4 桥接器与交换机 / 3.4.2 多属性注册协议(Multiple Registration Protocol (MRP))
OdeInt与GPU
Use winmtr software to simply analyze, track and detect network routing
Day 52 - tree problem