当前位置:网站首页>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).
边栏推荐
猜你喜欢
随机推荐
如何在不同场景下选择合适的示波器探头
基于 EasyCV 复现 DETR 和 DAB-DETR,Object Query 的正确打开方式
Using the DatePicker date control, Prop being mutated: "placement" error occurs
告诉你如何从keil工程知道使用了多少RAM和ROM空间
什么是“大小端字节序”存储模式?
软考考生注意!2022年下半年报名详细流程来了!
线性代数(四)
Unity implements UI edge detection and drag-and-drop functions
【无标题】
PHPCMS仿站从入门到精通,小白看这一套课程就够了
单页面应用
JavsSE => 多态
MySQL事务的保证机制
flex 相关
tensorflow分词深度学习——影评预测
Stacks and Queues | Implementing Queues with Stacks | Implementing Stacks with Queues | Basic Theory and Code Principles
成为黑客不得不学的语言,看完觉得你们还可吗?
ECMAScript6 Proxy和Reflect 对象操作拦截以及自定义
2022山东省安全员C证考试题及模拟考试
About the problem that the mongodb driver count method of rust cannot be used with the near condition









