Pytorch基础:数据读取与预处理——调用PyTorch官方数据集

news2024/10/1 21:41:28

数据读取与预处理——调用PyTorch官方数据集

  • 1. 从网络端下载 FashionMNIST 数据集到本地
  • 2. 数据集可视化

1. 从网络端下载 FashionMNIST 数据集到本地

(base) PS C:\Users\孙明阳> conda activate yang
(yang) PS C:\Users\孙明阳> python
Python 3.11.5 | packaged by Anaconda, Inc. | (main, Sep 11 2023, 13:26:23) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> from torchvision import datasets
>>> from torch.utils.data import Dataset
>>> from torchvision.transforms import ToTensor
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>>
>>> training_data = datasets.FashionMNIST(
...     root="data/FashionMNIST/",
...     train=True,
...     download=True,
...     transform=ToTensor()
... )
Downloading http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-images-idx3-ubyte.gz
Downloading http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-images-idx3-ubyte.gz to data/FashionMNIST/FashionMNIST\raw\train-images-idx3-ubyte.gz
100.0%
Extracting data/FashionMNIST/FashionMNIST\raw\train-images-idx3-ubyte.gz to data/FashionMNIST/FashionMNIST\raw

Downloading http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-labels-idx1-ubyte.gz
Downloading http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-labels-idx1-ubyte.gz to data/FashionMNIST/FashionMNIST\raw\train-labels-idx1-ubyte.gz
100.0%
Extracting data/FashionMNIST/FashionMNIST\raw\train-labels-idx1-ubyte.gz to data/FashionMNIST/FashionMNIST\raw

Downloading http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-images-idx3-ubyte.gz
Downloading http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-images-idx3-ubyte.gz to data/FashionMNIST/FashionMNIST\raw\t10k-images-idx3-ubyte.gz
100.0%
Extracting data/FashionMNIST/FashionMNIST\raw\t10k-images-idx3-ubyte.gz to data/FashionMNIST/FashionMNIST\raw

Downloading http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-labels-idx1-ubyte.gz
Downloading http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-labels-idx1-ubyte.gz to data/FashionMNIST/FashionMNIST\raw\t10k-labels-idx1-ubyte.gz
100.0%
Extracting data/FashionMNIST/FashionMNIST\raw\t10k-labels-idx1-ubyte.gz to data/FashionMNIST/FashionMNIST\raw

在这里插入图片描述

2. 数据集可视化

(base) PS C:\Users\阳> conda activate yang
(yang) PS C:\Users\阳> python
Python 3.11.5 | packaged by Anaconda, Inc. | (main, Sep 11 2023, 13:26:23) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> from torchvision import datasets
>>> from torch.utils.data import Dataset
>>> from torchvision.transforms import ToTensor
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> training_data = datasets.FashionMNIST(
...     root="data/FashionMNIST/",
...     train=True,
...     download=True,
...     transform=ToTensor()
... )
Downloading http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-images-idx3-ubyte.gz
Downloading http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-images-idx3-ubyte.gz to data/FashionMNIST/FashionMNIST\raw\train-images-idx3-ubyte.gz
100.0%
Extracting data/FashionMNIST/FashionMNIST\raw\train-images-idx3-ubyte.gz to data/FashionMNIST/FashionMNIST\raw

Downloading http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-labels-idx1-ubyte.gz
Downloading http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-labels-idx1-ubyte.gz to data/FashionMNIST/FashionMNIST\raw\train-labels-idx1-ubyte.gz
100.0%
Extracting data/FashionMNIST/FashionMNIST\raw\train-labels-idx1-ubyte.gz to data/FashionMNIST/FashionMNIST\raw

Downloading http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-images-idx3-ubyte.gz
Downloading http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-images-idx3-ubyte.gz to data/FashionMNIST/FashionMNIST\raw\t10k-images-idx3-ubyte.gz
100.0%
Extracting data/FashionMNIST/FashionMNIST\raw\t10k-images-idx3-ubyte.gz to data/FashionMNIST/FashionMNIST\raw

Downloading http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-labels-idx1-ubyte.gz
Downloading http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-labels-idx1-ubyte.gz to data/FashionMNIST/FashionMNIST\raw\t10k-labels-idx1-ubyte.gz
100.0%
Extracting data/FashionMNIST/FashionMNIST\raw\t10k-labels-idx1-ubyte.gz to data/FashionMNIST/FashionMNIST\raw

>>> labels_map = {
...     0: "T-Shirt",
...     1: "Trouser",
...     2: "Pullover",
...     3: "Dress",
...     4: "Coat",
...     5: "Sandal",
...     6: "Shirt",
...     7: "Sneaker",
...     8: "Bag",
...     9: "Ankle Boot",
... }
>>> figure = plt.figure(figsize=(7, 7))
>>> cols, rows = 3, 3
>>> # 根据数据集的数据量len(training_data),随机生成9个位置坐标
>>> positions = np.random.randint(0, len(training_data), (9,))
>>> for i in range(9):
...     img, label = training_data[positions[i]]
...     plt.subplot(rows, cols, i + 1)
...     plt.tight_layout(pad=0.05)
...     # 每个子图的标题设置为对应图像的标签
...     plt.title(labels_map[label])
...     plt.axis("off")
...     plt.imshow(img.squeeze(), cmap="gray")
>>> plt.savefig("D:\\fashion_mnist2.png")
>>> plt.show()

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1378285.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Vue-9、Vue事件修饰符

1、prevent 阻止默认事件 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><title>事件修饰符</title><!--引入vue--><script type"text/javascript" src"https://cdn.jsdeliv…

创建了使用说明书之后,怎样才能监测用户的行为和反馈?

在当今数字化的时代&#xff0c;了解用户的行为和反馈对于产品和服务的质量提升至关重要。对于使用说明书而言&#xff0c;仅仅创建出来是远远不够的&#xff0c;还需要持续地监测用户的行为和反馈&#xff0c;以便不断优化和改进。那怎样才能有效地监测用户的行为和反馈呢&…

Java十大经典算法—KMP

字符串匹配问题&#xff1a; 1.暴力匹配 public class ViolenceMatch {public static void main(String[] args) {String str1 "硅硅谷 尚硅谷你尚硅 尚硅谷你尚硅谷你尚硅你好";String str2 "尚硅谷你尚硅你好";int index violenceMatch(str1, str2);S…

Web开发:SQLsugar的安装和使用

一、安装 第一步&#xff0c;在你的项目中找到解决方案&#xff0c;右键-管理解决方案的Nuget 第二步&#xff0c;下载对应的包&#xff0c;注意你的框架是哪个就下载哪个的包&#xff0c;一个项目安装一次包即可 点击应用和确定 安装好后会显示sqlsugar的包 二、使用&#xf…

嵌入式培训机构四个月实训课程笔记(完整版)-Linux网络编程第一天-socket编程(物联技术666)

更多配套资料CSDN地址:点赞+关注,功德无量。更多配套资料,欢迎私信。 物联技术666-CSDN博客物联技术666擅长嵌入式C语言开发,嵌入式培训笔记,嵌入式硬件,等方面的知识,物联技术666关注机器学习,arm开发,物联网,嵌入式硬件,单片机领域.https://blog.csdn.net/weixin_3980490…

Unity Shader 开发入门3 —— 坐标空间变换

文章目录 一、变换矩阵1.1 齐次坐标1.2 平移矩阵1.3 旋转矩阵1.4 缩放矩阵1.5 复合变换 二、世界空间变换三、观察空间变换四、裁剪空间变换4.1 视椎体4.2 齐次裁剪空间4.3 视椎体投影方式 五、屏幕空间变换 ​ 在 Shader 开发中存在不同的坐标空间&#xff0c;包括&#xff1a…

代码随想录 516. 最长回文子序列

题目 给你一个字符串 s &#xff0c;找出其中最长的回文子序列&#xff0c;并返回该序列的长度。 子序列定义为&#xff1a;不改变剩余字符顺序的情况下&#xff0c;删除某些字符或者不删除任何字符形成的一个序列。 示例 1&#xff1a; 输入&#xff1a;s “bbbab” 输出&…

docker容器运行elaticsearch和kibana,又把ECS跑爆了

就运行了两个容器一个elasticsearch应一个就是可视化的kibana 开始还好好的后来cpu又爆了 最后只有重启ECS然后再启动这两个服务就好了 去网上找了下解决方法。说是正常情况Kibana第一加载非常耗资源。

openssl快速生成自签名证书

系统&#xff1a;Centos 7.6 确保已安装openssl openssl version生成私钥文件 private.key &#xff08;文件名自定义&#xff09; openssl genpkey -algorithm RSA -out private.key -pkeyopt rsa_keygen_bits:2048-out private.key&#xff1a;生成的私钥文件-algorithm RS…

Vue-14、Vue绑定style样式

1、对象写法 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><title>绑定css样式</title><!--引入vue--><script type"text/javascript" src"https://cdn.jsdelivr.net/npm/v…

Win10系统读不出U盘的四种解决方法

有用户特别喜欢用U盘来保存重要的内容&#xff0c;但有用户反映自己的Win10电脑读取不了U盘&#xff0c;这样用户就不能将Win10电脑上的内容传输到U盘了。下面小编带来四种简单有效的解决方法&#xff0c;解决后Win10电脑上的U盘就能被正常识别&#xff0c;从而恢复对U盘的使用…

揭露欧拉骗局4.“Σ1/n²=π²/6”里的猫腻

自然数平方倒数求和Σ1/n是一个并不复杂的问题&#xff0c;但它困扰了欧洲大陆整整90年&#xff0c;在欧系数学里它被称为“巴塞尔级数”。 解决巴塞尔级数让欧拉一战成名&#xff0c;然而欧拉采用的方法对数学这门学问是严重的侮辱。数学是工具学科&#xff0c;数学的宗旨是化…

NAND Separate Command Address (SCA) 接口数据传输解读

在采用Separate Command Address (SCA) 接口的存储产品中&#xff0c;DQ input burst和DQ output burst又是什么样的策略呢&#xff1f; DQ Input Burst: 在读取操作期间&#xff0c;数据以一种快速并行的方式通过DQ总线传送到控制器。在SCA接口下&#xff0c;虽然命令和地址信…

AI绘画软件Stable Diffusion模型/Lora/VAE文件存放位置

型下载说明&#xff08;下载模型后输入对应参数即可生成&#xff09; 建议直接去civitai.com找模型&#xff0c;如果无法找到可以在幕后模型区找也可以去&#xff0c; 下载好后放入对应的文件夹。进入127.0.0.1:7680 左上角刷新即可看到新的模型。 模型种类 大模型 大模型特…

启动Vue项目,报错:‘vue-cli-service‘ 不是内部或外部命令,也不是可运行的程序

前言&#xff1a; 最近在打开一个Vue项目的时候&#xff0c;打开之后输入命令行&#xff1a;npm run serve之后发现&#xff0c;报错&#xff1a;vue-cli-service 不是内部或外部命令&#xff0c;也不是可运行的程序&#xff0c;以下是解决方案&#xff1a; 报错图片截图&…

【方差分析原理简介】

文章目录 方差分析&#xff08;Analysis of Variance&#xff0c;简称ANOVA&#xff09;1 方差分析流程2 借助sklean进行基于方差分析的特征筛选3 总结 方差分析&#xff08;Analysis of Variance&#xff0c;简称ANOVA&#xff09; 卡方检验更多的会考虑在衡量两个离散变量是…

redis系列:01 数据类型及操作

redis的数据类型有哪些 string,list,set,sorted_set,hash 操作 sting: set name maliao get name exists name expire name 5 ttl name del name setex name 10 maliao 设置key和过期时间 setnx name maliao 当key不存在时才添加list&#xff1a; lpush letter a lpush le…

FPN网络的实现原理详解

1 前言 FPN网络是一种常见的特征融合模块&#xff0c;在很多模型中都有运用&#xff0c;今天我们就结合代码和论文详细的搞清楚它到底是怎么一回事。 2 原理 原理直接看这一张图就可以了&#xff0c;很直观主要就是把对不同层的特征进行融合&#xff0c;重点还是在于代码的理…

SpringBoot项目如何防止反编译?

SpringBoot项目如何防止反编译&#xff1f; 场景方案项目操作启动方式反编译效果绑定机器启动 场景 最近项目要求部署到其他公司的服务器上&#xff0c;但是又不想将源码泄露出去。要求对正式环境的启动包进行安全性处理&#xff0c;防止客户直接通过反编译工具将代码反编译出…

【服务器】服务器管理 - cockpit开启

开启cockpit #!/bin/bashsed -i s/is():where()/is(*):where(*)/ /usr/share/cockpit/static/login.jssystemctl enable --now cockpit.socket #开启cockpit服务systemctl start cockpit.socket 登录 https://ip:9090