在Pytorch0.4版本的DARTS代码里,有一行代码是

trn_data = datasets.CIFAR10(root=data_path, train=True, download=False, transform=train_transform)
shape = trn_data.train_data.shape

在1.2及以上版本里,查看源码可知,CIFAR10这个类已经没有train_data这个属性了,取而代之的是data,因此要把第二行改成

shape = trn_data.data.shape

datasets.CIFAR10源码如下:

from __future__ import print_function
from PIL import Image
import os
import os.path
import numpy as np
import sys if sys.version_info[0] == 2:
import cPickle as pickle
else:
import pickle from .vision import VisionDataset
from .utils import check_integrity, download_and_extract_archive [docs]class CIFAR10(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. """
base_folder = 'cifar-10-batches-py'
url = "https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz"
filename = "cifar-10-python.tar.gz"
tgz_md5 = 'c58f30108f718f92721af3b95e74349a'
train_list = [
['data_batch_1', 'c99cafc152244af753f735de768cd75f'],
['data_batch_2', 'd4bba439e000b95fd0a9bffe97cbabec'],
['data_batch_3', '54ebc095f3ab1f0389bbae665268c751'],
['data_batch_4', '634d18415352ddfa80567beed471001a'],
['data_batch_5', '482c414d41f54cd18b22e5b47cb7c3cb'],
] test_list = [
['test_batch', '40351d587109b95175f43aff81a1287e'],
]
meta = {
'filename': 'batches.meta',
'key': 'label_names',
'md5': '5ff9c542aee3614f3951f8cda6e48888',
} def __init__(self, root, train=True, transform=None, target_transform=None,
download=False): super(CIFAR10, self).__init__(root, transform=transform,
target_transform=target_transform) self.train = train # training set or test set if download:
self.download() if not self._check_integrity():
raise RuntimeError('Dataset not found or corrupted.' +
' You can use download=True to download it') if self.train:
downloaded_list = self.train_list
else:
downloaded_list = self.test_list self.data = []
self.targets = [] # now load the picked numpy arrays
for file_name, checksum in downloaded_list:
file_path = os.path.join(self.root, self.base_folder, file_name)
with open(file_path, 'rb') as f:
if sys.version_info[0] == 2:
entry = pickle.load(f)
else:
entry = pickle.load(f, encoding='latin1')
self.data.append(entry['data'])
if 'labels' in entry:
self.targets.extend(entry['labels'])
else:
self.targets.extend(entry['fine_labels']) self.data = np.vstack(self.data).reshape(-1, 3, 32, 32)
self.data = self.data.transpose((0, 2, 3, 1)) # convert to HWC self._load_meta()

关于torchvision.datasets.CIFAR10的更多相关文章

  1. torchvision.datasets.ImageFolder数据加载

    ImageFolder 一个通用的数据加载器,数据集中的数据以以下方式组织 root/dog/xxx.png root/dog/xxy.png root/dog/xxz.png root/cat/12 ...

  2. torchvision.datasets

    转载  https://ptorch.com/docs/8/torchvision-datasets

  3. 试着用教程跑cifar10数据

    1.terminal里已经可import torchvision了,为什么Spyder里还是不能import torchvision 重启. 2. trainset = torchvision.dat ...

  4. PyTorch入门-CIFAR10图像分类

    CIFAR10数据集下载 CIFAR10数据集包含10个类别,图像尺寸为 3×32×32 官方下载地址很慢,这里给一个百度云: https://pan.baidu.com/s/1oTvW8wNa-VO ...

  5. PyTorch教程之Training a classifier

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

  6. 学习笔记-ResNet网络

    ResNet网络 ResNet原理和实现 总结 一.ResNet原理和实现 神经网络第一次出现在1998年,当时用5层的全连接网络LetNet实现了手写数字识别,现在这个模型已经是神经网络界的“hel ...

  7. 【转载】Pytorch tutorial 之Datar Loading and Processing

    前言 上文介绍了数据读取.数据转换.批量处理等等.了解到在PyTorch中,数据加载主要有两种方式: 1.自定义的数据集对象.数据集对象被抽象为Dataset类,实现自定义的数据集需要继承Datase ...

  8. PyTorch进行深度学习入门

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

  9. 深度学习(pytorch)-1.基于简单神经网络的图片自动分类

    这是pytorch官方的一个例子 官方教程地址:http://pytorch.org/tutorials/beginner/blitz/cifar10_tutorial.html#sphx-glr-b ...

随机推荐

  1. 多组件共享-vuex —— 使用vuex 报错 actions should be function or object with ”handler“

    vuex分模块使用时出现的问题,单文件暂时没有用到 原因是在action 文件中没有任何定义(即:文件为空)或则 action 没有任何方法返回,将action在模块引用时去掉即可 转自:https: ...

  2. logback.xml 配置详解(转)

    <?xml version="1.0" encoding="UTF-8"> <configuration> <!-- 设置控制台日 ...

  3. HDU 6034 - Balala Power! | 2017 Multi-University Training Contest 1

    /* HDU 6034 - Balala Power! [ 大数进位,贪心 ] 题意: 给一组字符串(小写英文字母),将上面的字符串考虑成26进制数,每个字母分配一个权值,问这组数字加起来的和最大是多 ...

  4. 漫话:什么是 https ?这应该是全网把 https 讲的最好的一篇文章了

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/m0_37907797/article/d ...

  5. 什么是URL百分号编码?

    ㈠什么是URL 统一资源定位系统(uniform resource locator;URL)是因特网的万维网服务程序上用于指定信息位置的表示方法. ㈡URL编码 url编码是一种浏览器用来打包表单输入 ...

  6. js的DOM操作整理(整理)

    js的DOM操作整理(整理) 一.总结 一句话总结: dom操作有用原生js的dom操作,也可以用对js封装过的jquery等插件来更加方便的进行dom操作 1.dom是什么? 对于JavaScrip ...

  7. Nowcoder的JS计时器题分析

    题目描述 实现一个打点计时器,要求1.从 start 到 end(包含 start 和 end),每隔 100 毫秒 console.log 一个数字,每次数字增幅为 12.返回的对象中需要包含一个 ...

  8. TTTTTTTTTTTTT CF#365 div2 B 统计点

    B. Mishka and trip time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  9. 三元环HDU 6184

    HDU - 6184 C - Counting Stars 题目大意:有n个点,m条边,问有一共有多少个‘structure’也就是满足V=(A,B,C,D) and E=(AB,BC,CD,DA,A ...

  10. matlab函数 bsxfun浅谈(转载)

    关于matlab函数 bsxfun本文来源:http://blog.sina.com.cn/s/blog_9e67285801010ttn.html a=[1 2 3];b=[1 2 3]';c=bs ...