当前位置:网站首页>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)。
边栏推荐
猜你喜欢
随机推荐
2022 T Elevator Repair Exam Questions and Mock Exams
元宇宙 | 你能通过图灵测试吗?
2022山东省安全员C证考试题及模拟考试
栈与队列 | 用栈实现队列 | 用队列实现栈 | 基础理论与代码原理
线性代数(四)
Stacks and Queues | Implementing Queues with Stacks | Implementing Stacks with Queues | Basic Theory and Code Principles
线程(下):读写者模型\环形队列\线程池
如何取得某月的最后一天
awk of the Three Musketeers of Shell Programming
Mysql CDC (2.1.1) inital snapshot database set up five concurrent degree, se
ctf-pikachu-file_inclusion
法定代表人和股东是什么关系
盼他一切安好
The time for flinkcdc to read pgsql is enlarged. Does anyone know what happened? gmt_create':1
解决“File has been changed outside the editor, reload?”提示
各位大佬,idea中测试使用FlinkCDC SQL 读取Mysql 数据写入Kafka中,代码中创
电流探头如何设置示波器参数
取消了这次
深度学习——循环神经网络RNN 未完待续
Acwing 59. 把数字翻译成字符串 计数类DP







