当前位置:网站首页>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官方数据集(下载数据集方法)
边栏推荐
- Why is Hong Kong server most suitable for overseas website construction
- 【LeetCode】100. Same tree
- Basic exercise of test questions hexadecimal to decimal
- The design points of voice dialogue system and the importance of multi round dialogue
- How to do the performance pressure test of "Health Code"
- Haskell lightweight threads overhead and use on multicores
- Section 27 remote access virtual private network workflow and experimental demonstration
- Pytest automated testing - compare robotframework framework
- RuntimeError: mean(): input dtype should be either floating point or complex dtypes.Got Long instead
- Knowledge supplement: redis' basic data types and corresponding commands
猜你喜欢

Dual contractual learning: text classification via label aware data augmentation reading notes

MySQL winter vacation self-study 2022 12 (5)

软件研发的十大浪费:研发效能的另一面

Odeint and GPU

【LeetCode】100. Same tree

Odeint et GPU

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

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

先有网络模型的使用及修改

How to do the performance pressure test of "Health Code"
随机推荐
Shell之Unix运维常用命令
2022年化工自动化控制仪表操作证考试题库及答案
How to choose the right server for website data collection?
Summary of acl2021 information extraction related papers
2022 Shanghai safety officer C certificate examination question simulation examination question bank and answers
总结全了,低代码还需要解决这4点问题
2022 hoisting machinery command registration examination and hoisting machinery command examination registration
VR线上展览所具备应用及特色
Strategic suggestions and future development trend of global and Chinese vibration isolator market investment report 2022 Edition
2022 a special equipment related management (elevator) simulation test and a special equipment related management (elevator) certificate examination
How to do the performance pressure test of "Health Code"
Question bank and online simulation examination for special operation certificate of G1 industrial boiler stoker in 2022
Rule method: number of effective triangles
Maixll dock quick start
Registration of P cylinder filling examination in 2022 and analysis of P cylinder filling
OdeInt与GPU
C language games (I) -- guessing games
Collect the annual summary of laws, regulations, policies and plans related to trusted computing of large market points (national, ministerial, provincial and municipal)
About the transmission pipeline of stage in spark
Basic usage, principle and details of session