当前位置:网站首页>pytorch框架学习(4)torchvision模块&训练一个简单的自己的CNN (一)
pytorch框架学习(4)torchvision模块&训练一个简单的自己的CNN (一)
2022-08-10 05:29:00 【Time.Xu】
torchvision模块
不要担心自己的形象,只关心如何实现目标。——《原则》,生活原则
英文PyTorch文档的Libraries中有关于torchvision的介绍
实战讲解有以下几个部分
数据预处理部分
—数据增强
—数据预处理
网络模块设置
—加载预训练模型
> 模型训练、保存与测试(下一个文章里)
—选择性的保存
—读取模型并测试
在这个(torchvision)模块中有许多我们需要的功能,比如:torchvision.datasets(封装了一些常用的数据集 和 定义了数据存放的方法) , torchvision.models(包括了一些经典网络架构的实现,以及与训练模型) , torchvision.transfrom(数据预处理模块)
纯分类任务的数据类型可以参考ImageFolder模块。官网链接
当然不同的任务,数据集的构建可能是不一样的~~~
1 数据预处理
首先我们导入所需要的pip包,并定义好我们想用的数据集的路径
然后我们对图像进行 数据增强处理–ToTensor–Normalize

接下来我们构建数据集

目前我们的数据集里面全是1、2、3这种,我们可以读取json文件来把编号和名字对应起来

数据展示
- 注意:我们这里如果想要展示数据的话,必须将已经转换为temsor格式的数据还原为numpy格式,并且需要对标准化进行还原
- 其中transpose操作是把 C * H * W 还原为 H * W * C
- squeeze的作用是降维。具体可参考别人的博客
2 网络模型设置
边栏推荐
- pytorch 学习
- Advanced Feature Selection Techniques in Linear Models - Based on R
- AVL tree insertion--rotation notes
- Nexus_Warehouse Type
- How to simulate the background API call scene, very detailed!
- Joomla vulnerability reproduced
- WSTP初体验
- 栈与队列 | 有效的括号、删除字符串中的所有相邻元素、逆波兰表达式求值、滑动窗口的最大值、前K个高频元素 | leecode刷题笔记
- Pony语言学习(八):引用能力(Reference Capabilities)
- Matlab simulation of multi-factor house price prediction based on BP neural network
猜你喜欢
【Static proxy】
Pony语言学习(八):引用能力(Reference Capabilities)
Order table delete, insert and search operations
论文精度 —— 2016 CVPR 《Context Encoders: Feature Learning by Inpainting》
Qiskit学习笔记(三)
How does Jenkins play with interface automation testing?
基于Qiskit——《量子计算编程实战》读书笔记(三)
我用这一招让团队的开发效率提升了 100%!
Flutter development: error The following assertion was thrown resolving an image codec: Solution for Unable to...
最强大脑(1)
随机推荐
SQL数据库字段追加到主表
How to simulate the background API call scene, very detailed!
The sword refers to Offer 033. Variation array
咨询cdc 2.0 for mysql不执行flush with read lock.怎么保证bin
conda创建虚拟环境方法和pqi使用国内镜像源安装第三方库的方法教程
Joomla vulnerability reproduced
FPGA工程师面试试题集锦21~30
When oracle cdc, set the parallelism to 2 and the number of slots to 1, and the final task has only one tm. Is it because oracle does not support concurrency
树莓派入门(4)LED闪烁&呼吸灯
oracle cdc时,设置并行度2插槽数1,最终任务只有一个tm,是不是因为oracle不支持并发
每周推荐短视频:探索AI的应用边界
Flutter开发:报错The following assertion was thrown resolving an image codec:Unable to…的解决方法
Interface debugging also can play this?
基于Qiskit——《量子计算编程实战》读书笔记(六)
【静态代理】
canvas canvas drawing clock
Why are negative numbers in binary represented in two's complement form - binary addition and subtraction
Abstract problem methodology
MySql's json_extract function processes json fields
How does flinksql write that the value of redis has only the last field?