1. torchvision数据集介绍

① torchvision中有很多数据集,当我们写代码时指定相应的数据集指定一些参数,它就可以自行下载。

② CIFAR-10数据集包含60000张32×32的彩色图片,一共10个类别,其中50000张训练图片,10000张测试图片。

2. torchvision数据集使用

① 在 Anaconda 终端里面,激活py3.6.3环境,再跳转到该项目的路径下。

② 运行python。导入torchvision包,输入

train_set = torchvision.datasets.CIFAR10(root="./dataset",train=True,download=True)

命令,即下载数据集到到该文件夹下。

import torchvision
help(torchvision.datasets.CIFAR10)
Help on class CIFAR10 in module torchvision.datasets.cifar:

class CIFAR10(torchvision.datasets.vision.VisionDataset)
| `CIFAR10 <https://www.cs.toronto.edu/~kriz/cifar.html>`_ Dataset.
|
| Args:
| 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.
|
| Method resolution order:
| CIFAR10
| torchvision.datasets.vision.VisionDataset
| torch.utils.data.dataset.Dataset
| typing.Generic
| builtins.object
|
| Methods defined here:
|
| __getitem__(self, index:int) -> Tuple[Any, Any]
| Args:
| index (int): Index
|
| Returns:
| tuple: (image, target) where target is index of the target class.
|
| __init__(self, root:str, train:bool=True, transform:Union[Callable, NoneType]=None, target_transform:Union[Callable, NoneType]=None, download:bool=False) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| __len__(self) -> int
|
| download(self) -> None
|
| extra_repr(self) -> str
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __abstractmethods__ = frozenset()
|
| __args__ = None
|
| __extra__ = None
|
| __next_in_mro__ = <class 'object'>
| The most base type
|
| __orig_bases__ = (torchvision.datasets.vision.VisionDataset,)
|
| __origin__ = None
|
| __parameters__ = ()
|
| __tree_hash__ = -9223371924072727236
|
| base_folder = 'cifar-10-batches-py'
|
| filename = 'cifar-10-python.tar.gz'
|
| meta = {'filename': 'batches.meta', 'key': 'label_names', 'md5': '5ff9...
|
| test_list = [['test_batch', '40351d587109b95175f43aff81a1287e']]
|
| tgz_md5 = 'c58f30108f718f92721af3b95e74349a'
|
| train_list = [['data_batch_1', 'c99cafc152244af753f735de768cd75f'], ['...
|
| url = 'https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz'
|
| ----------------------------------------------------------------------
| Methods inherited from torchvision.datasets.vision.VisionDataset:
|
| __repr__(self) -> str
| Return repr(self).
|
| ----------------------------------------------------------------------
| Methods inherited from torch.utils.data.dataset.Dataset:
|
| __add__(self, other:'Dataset[T_co]') -> 'ConcatDataset[T_co]'
|
| __getattr__(self, attribute_name)
|
| ----------------------------------------------------------------------
| Class methods inherited from torch.utils.data.dataset.Dataset:
|
| register_datapipe_as_function(function_name, cls_to_register, enable_df_api_tracing=False) from typing.GenericMeta
|
| register_function(function_name, function) from typing.GenericMeta
|
| ----------------------------------------------------------------------
| Data descriptors inherited from torch.utils.data.dataset.Dataset:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from torch.utils.data.dataset.Dataset:
|
| __annotations__ = {'functions': typing.Dict[str, typing.Callable]}
|
| functions = {'concat': functools.partial(<function Dataset.register_da...
|
| ----------------------------------------------------------------------
| Static methods inherited from typing.Generic:
|
| __new__(cls, *args, **kwds)
| Create and return a new object. See help(type) for accurate signature.

3. 查看CIFAR10数据集内容

import torchvision
train_set = torchvision.datasets.CIFAR10(root="./dataset",train=True,download=True) # root为存放数据集的相对路线
test_set = torchvision.datasets.CIFAR10(root="./dataset",train=False,download=True) # train=True是训练集,train=False是测试集 print(test_set[0]) # 输出的3是target
print(test_set.classes) # 测试数据集中有多少种 img, target = test_set[0] # 分别获得图片、target
print(img)
print(target) print(test_set.classes[target]) # 3号target对应的种类
img.show()
Files already downloaded and verified
Files already downloaded and verified
(<PIL.Image.Image image mode=RGB size=32x32 at 0x1A4275AAF28>, 3)
['airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck']
<PIL.Image.Image image mode=RGB size=32x32 at 0x1A4275AAA58>
3
cat

4. Tensorboard查看内容

import torchvision
from torch.utils.tensorboard import SummaryWriter dataset_transform = torchvision.transforms.Compose([torchvision.transforms.ToTensor()])
train_set = torchvision.datasets.CIFAR10(root="./dataset",train=True,transform=dataset_transform,download=True) # 将ToTensor应用到数据集中的每一张图片,每一张图片转为Tensor数据类型
test_set = torchvision.datasets.CIFAR10(root="./dataset",train=False,transform=dataset_transform,download=True) writer = SummaryWriter("logs")
for i in range(10):
img, target = test_set[i]
writer.add_image("test_set",img,i)
print(img.size()) writer.close() # 一定要把读写关闭,否则显示不出来图片
Files already downloaded and verified
Files already downloaded and verified
torch.Size([3, 32, 32])
torch.Size([3, 32, 32])
torch.Size([3, 32, 32])
torch.Size([3, 32, 32])
torch.Size([3, 32, 32])
torch.Size([3, 32, 32])
torch.Size([3, 32, 32])
torch.Size([3, 32, 32])
torch.Size([3, 32, 32])
torch.Size([3, 32, 32])

① 在 Anaconda 终端里面,激活py3.6.3环境,再输入

tensorboard --logdir=C:\Users\wangy\Desktop\03CV\logs   #绝对地址
或者使用下面指令:
tensorboard --logdir=logs #相对地址

命令,将网址赋值浏览器的网址栏,回车,即可查看tensorboard显示日志情况。

4-torchvision数据集使用的更多相关文章

  1. torchvision库简介(翻译)

    部分跟新于:4.24日    torchvision 0.2.2.post3 torchvision是独立于pytorch的关于图像操作的一些方便工具库. torchvision的详细介绍在:http ...

  2. PyTorch教程之Training a classifier

    我们已经了解了如何定义神经网络,计算损失并对网络的权重进行更新. 接下来的问题就是: 一.What about data? 通常处理图像.文本.音频或视频数据时,可以使用标准的python包将数据加载 ...

  3. PyTorch进行深度学习入门

    一.PyTorch是什么? 这是一个基于Python的科学计算软件包,针对两组受众: ①.NumPy的替代品,可以使用GPU的强大功能 ②.深入学习研究平台,提供最大的灵活性和速度 二.入门 ①.张量 ...

  4. pytorch例子学习——TRAINING A CLASSIFIER

    参考:https://pytorch.org/tutorials/beginner/blitz/cifar10_tutorial.html#sphx-glr-beginner-blitz-cifar1 ...

  5. 【PyTorch深度学习60分钟快速入门 】Part4:训练一个分类器

      太棒啦!到目前为止,你已经了解了如何定义神经网络.计算损失,以及更新网络权重.不过,现在你可能会思考以下几个方面: 0x01 数据集 通常,当你需要处理图像.文本.音频或视频数据时,你可以使用标准 ...

  6. 【pytorch】pytorch学习笔记(一)

    原文地址:https://pytorch.org/tutorials/beginner/deep_learning_60min_blitz.html 什么是pytorch? pytorch是一个基于p ...

  7. 【PyTorch v1.1.0文档研习】60分钟快速上手

    阅读文档:使用 PyTorch 进行深度学习:60分钟快速入门. 本教程的目标是: 总体上理解 PyTorch 的张量库和神经网络 训练一个小的神经网络来进行图像分类 PyTorch 是个啥? 这是基 ...

  8. PyTorch深度学习:60分钟入门(Translation)

    这是https://zhuanlan.zhihu.com/p/25572330的学习笔记. Tensors Tensors和numpy中的ndarrays较为相似, 因此Tensor也能够使用GPU来 ...

  9. pytorch资料

    torchvision是独立于pytorch的关于图像操作的一些方便工具库. torchvision的详细介绍在:https://pypi.org/project/torchvision/ torch ...

  10. [PyTorch入门之60分钟入门闪击战]之训练分类器

    训练分类器 目前为止,你已经知道如何定义神经网络.计算损失和更新网络的权重.现在你可能在想,那数据呢? What about data? 通常,当你需要处理图像.文本.音频或者视频数据时,你可以使用标 ...

随机推荐

  1. JLabel展示文本和图片--java进阶day03

    1.JLabel 我们想要在窗体中展示图片或者文本是不能直接展示的,文本和图片必须要放在JLabel这个组件中 JLabel实质是窗体中的一块区域,创建了一个JLabel对象意味着在窗体中开辟了一块区 ...

  2. study Rust-9【组织管理】

    Rust中三个组织管理的概念:箱(Crate).包(Package).模块(module) Crate: "箱"是二进制程序文件或者库文件,存在于"包"中. & ...

  3. lombok用法

    加入 maven 依赖 <dependency> <groupId>org.projectlombok</groupId> <artifactId>lo ...

  4. 【U-Boot】解决U-Boot的“Unknown command 'help' - try 'help'”问题

    [U-Boot]解决U-Boot的"Unknown command 'help' - try 'help'"问题 零.起因 最近在玩U-Boot,自己编译U-Boot之后输入hel ...

  5. SpringSecurity5(14-Gateway整合)

    MVC 与 WebFlux 关系 SpringSecurity 设置要采用响应式配置,基于 WebFlux 中 WebFilter 实现,与 Spring MVC 的 Security 是通过 Ser ...

  6. mybatis插入数据返回id的实现方式

    一. useGeneratedKeys="true" <insert id="saveUser" parameterType="com.apcs ...

  7. php和thinkphp实现页面调转

    1.原生PHP https://www.cnblogs.com/jade640/p/7118565.html 2.thinkPHP跳转方法及重定向 https://blog.csdn.net/Wake ...

  8. 《Deep Learning Inference on Embedded Devices: Fixed-Point vs Posit》(一)

    After the success of performing deep learning inference by using an 8-bit precision representation o ...

  9. WPF 解决PasswordBox 属性Password无法绑定到后台的问题

    在 WPF 中,你可以使用密码框的 Password 属性来绑定到后台,但是由于安全性考虑,WPF 的密码框不直接支持双向绑定.然而,你仍然可以通过其他方式实现将密码框的内容绑定到后台. 一种常见的方 ...

  10. 操作系统综合题之“采用短进程优先调度算法(Shortest-Process-First,SPF)和先来先服务调度算法(First-Come,First-Served,FCFS)计算开始运行时间、结束时间、等待时间、周转时间、带权周转时间、平均周转时间”

    一.问题:某系统中有四个进程,他们进入系统的时间和需要服务的时间如题下表所示(表中数值均为十进制) 进程 进入系统的时间 需要服务的时间 P1 0 100 P2 10 60 P3 25 25 P4 3 ...