当前位置:网站首页>pytorch 学习
pytorch 学习
2022-08-10 05:02:00 【小王的进阶之路】
这里写目录标题
1. dataset
dataset:提供一种方式去获取数据及其 label
- 获取每一个数据及其 label
- 告诉我们总共有多少的数据
from torch.utils.data import Dataset
from PIL import Image
import os
class MyData(Dataset):
# 初始化
def __init__(self,root_dir,label_dir):
self.root_dir = root_dir
self.label_dir = label_dir
# 路径拼接
self.path = os.path.join(self.root_dir,self.label_dir)
# 获得所有图片的列表
self.img_path = os.listdir(self.path)
def __getitem__(self, idx):
img_name = self.img_path[idx]
img_item_path = os.path.join(self.root_dir,self.label_dir,img_name)
img = Image.open(img_item_path)
label = self.label_dir
return img,label
def __len__(self):
return len(self.img_path)
root_dir = "dataset\\train"
blur_label_dir = 'blur'
sharp_label_dir = 'sharp'
blur_dataset = MyData(root_dir,blur_label_dir)
sharp_dataset = MyData(root_dir,sharp_label_dir)
img,label = blur_dataset[1]
img.show()
2. dataloader
dataloader:为后面的网络提供不同的数据形式(打包)
CLASStorch.utils.data.DataLoader(dataset, batch_size=1, shuffle=None, sampler=None, batch_sampler=None, num_workers=0, collate_fn=None, pin_memory=False, drop_last=False, timeout=0, worker_init_fn=None, multiprocessing_context=None, generator=None, *, prefetch_factor=2, persistent_workers=False, pin_memory_device='')
shuffle:是否打乱,false,不打乱(default: False)。
num_workers:加载数据的时候有多少个进程(default: 0)。
drop_last:最后按 batch_size 取数据的话,看最后是否会有剩余。true,剩下的不够batch_size的数据不会取出,false,剩下的数据也会取出( default: False)。
边栏推荐
- ctf-pikachu-file_inclusion
- 2022 R2 transportable pressure vessel filling operation examination question bank simulation platform
- Ask you guys.The FlinkCDC2.2.0 version in the CDC community has a description of the supported sqlserver version, please
- 咨询cdc 2.0 for mysql不执行flush with read lock.怎么保证bin
- 十年架构五年生活-06 离职的冲动
- JS gets the year, month, day, time, etc. of the current time
- 添加路由的2种方式--router
- 线程(下):读写者模型\环形队列\线程池
- 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
- leetcode每天5题-Day12
猜你喜欢
webrtc学习--websocket服务器
添加路由的2种方式--router
万字总结:分布式系统的38个知识点
60行从零开始自己动手写FutureTask是什么体验?
机器学习之聚类——双聚类简介及简单案例
虚假新闻检测论文阅读(七):A temporal ensembling based semi-supervised ConvNet for the detection of fake news
ctf-pikachu-file_inclusion
栈与队列 | 有效的括号、删除字符串中的所有相邻元素、逆波兰表达式求值、滑动窗口的最大值、前K个高频元素 | leecode刷题笔记
LeetCode 6138. 最长理想子序列 动态规划
LeetCode·124.二叉树中的最大路径和·递归
随机推荐
抽象问题方法论
JS gets the year, month, day, time, etc. of the current time
什么是SRM?有什么作用?在企业管理中能实现哪些功能?
兴盛优选监控场景的时序数据库选型与落地实践
22牛客多校3 A.Ancestor(LCA + 枚举)
栈与队列 | 有效的括号、删除字符串中的所有相邻元素、逆波兰表达式求值、滑动窗口的最大值、前K个高频元素 | leecode刷题笔记
各位大佬,idea中测试使用FlinkCDC SQL 读取Mysql 数据写入Kafka中,代码中创
leetcode每天5题-Day12
Unity实现UI的边缘检测和拖拽拉伸功能
About the problem that the mongodb driver count method of rust cannot be used with the near condition
使用 DatePicker 日期控件,发生 Prop being mutated: “placement“ 报错问题
Pulsar中游标的工作原理
今天月亮很美
`id` bigint(20) unsigned NOT NULL COMMENT '数据库主键',
webrtc学习--websocket服务器(二) (web端播放h264)
curl命令介绍
软考考生注意!2022年下半年报名详细流程来了!
cmake
文献 | 关于心理活动符号学,你知道多少?
ctf-pikachu-file_inclusion