当前位置:网站首页>pytorch learning
pytorch learning
2022-08-10 05:03:00 【Xiao Wang's Progressive Path】
这里写目录标题
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)
# Get a list of all pictures
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:How many processes are there when loading data(default: 0).
drop_last:最后按 batch_size 取数据的话,See if there is any leftovers at the end.true,not enough leftbatch_sizedata will not be retrieved,false,The rest of the data will also be fetched( default: False).
边栏推荐
- flinksql怎么写redis的value只有最后一个字段?
- 干货 | 查资料利器:线上图书馆
- 基于 EasyCV 复现 DETR 和 DAB-DETR,Object Query 的正确打开方式
- Ask you guys.The FlinkCDC2.2.0 version in the CDC community has a description of the supported sqlserver version, please
- cmake
- webrtc学习--一对一通话
- 大佬们,mysql cdc(2.2.1跟之前的版本)从savepoint起有时出现这种情况,有没有什
- leetcode每天5题-Day10
- Promise原理及实现
- 【u-boot】u-boot驱动模型分析(02)
猜你喜欢
webrtc学习--webrtc源码获取
LeetCode·124.二叉树中的最大路径和·递归
Order table delete, insert and search operations
What is the relationship between legal representative and shareholders?
MySQL使用简单教程
2022 security officer C certificate test and simulation test in shandong province
How to choose the right oscilloscope probe in different scenarios
MySQL simple tutorial
什么是遗留代码:有效地处理遗留代码的8个小贴士
栈与队列 | 有效的括号、删除字符串中的所有相邻元素、逆波兰表达式求值、滑动窗口的最大值、前K个高频元素 | leecode刷题笔记
随机推荐
How Current Probes Set Oscilloscope Parameters
SQL database field to append to main table
leetcode每天5题-Day13
GP如何进行数据比对?
【u-boot】u-boot驱动模型分析(02)
十年架构五年生活-07 年轻气盛的蜕变
What is the relationship between legal representative and shareholders?
mysql cdc (2.1.1)inital snapshot数据库的时候设置了5个并发度,se
软考考生注意!2022年下半年报名详细流程来了!
什么是遗留代码:有效地处理遗留代码的8个小贴士
About the problem that the mongodb driver count method of rust cannot be used with the near condition
成为黑客不得不学的语言,看完觉得你们还可吗?
redis basic data types
flinksql怎么写redis的value只有最后一个字段?
MySQL simple tutorial
FPGA工程师面试试题集锦31~40
【无标题】
解决“File has been changed outside the editor, reload?”提示
Thread.sleep, Thread.yield 作用解释
转型做产品,考NPDP靠谱吗?