当前位置:网站首页>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官方数据集(下载数据集方法)
边栏推荐
- 【硬十宝典】——1.【基础知识】电源的分类
- Haskell lightweight threads overhead and use on multicores
- 神经网络-最大池化的使用
- 神经网络-卷积层
- Seven crimes of counting software R & D Efficiency
- 206. reverse linked list
- LM small programmable controller software (based on CoDeSys) note 19: errors do not match the profile of the target
- 2022.2.7-2.13 AI industry weekly (issue 84): family responsibilities
- Shell之Unix运维常用命令
- Applications and features of VR online exhibition
猜你喜欢
![[pat (basic level) practice] - [simple simulation] 1064 friends](/img/37/0ef0f8aae15ae574be1d76c97497c9.jpg)
[pat (basic level) practice] - [simple simulation] 1064 friends

This sideline workload is small, 10-15k, free unlimited massage

2022 t elevator repair new version test questions and t elevator repair simulation test question bank

slf4j 简单实现

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

Maixll-Dock 快速上手

How to do the performance pressure test of "Health Code"

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

Maixll-Dock 使用方法

Kodori tree board
随机推荐
Grey correlation cases and codes
selenium打开chrome浏览器时弹出设置页面:Mircrosoft Defender 防病毒要重置您的设置
数据加载及预处理
Task04 | statistiques mathématiques
JS rotation chart
Registration for R2 mobile pressure vessel filling test in 2022 and R2 mobile pressure vessel filling free test questions
[2020 overview] overview of link prediction based on knowledge map embedding
pytorch神经网络搭建 模板
一些小知识点
Why is Internet thinking not suitable for AI products?
软件研发的十大浪费:研发效能的另一面
Codeforces Round #721 (Div. 2)B1. Palindrome Game (easy version)B2. Palindrome game (hard version)
Haskell lightweight threads overhead and use on multicores
TCP/IP 详解(第 2 版) 笔记 / 3 链路层 / 3.4 桥接器与交换机 / 3.4.2 多属性注册协议(Multiple Registration Protocol (MRP))
2022 tea master (intermediate) examination question bank and tea master (intermediate) examination questions and analysis
Openresty rewrites the location of 302
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
2022 Shanghai safety officer C certificate examination question simulation examination question bank and answers
CF1638E. Colorful operations Kodori tree + differential tree array