当前位置:网站首页>Use of dataset of pytorch
Use of dataset of pytorch
2022-07-06 10:24:00 【How about a song without trace】
from torch.utils.data import Dataset
from PIL import Image
import os
class MyData():
def __init__(self, root_dir, label_dir):
# Use self It is equivalent to creating a global variable for the following ones, which can also be used
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)
# Get every picture
def __getitem__(self, index):
# adopt index Get image address
img_name = self.img_path[index] # Path of each picture
img_item_path = os.path.join(self.root_dir, self.label_dir, img_name)
print(img_item_path)
# Read the picture
img = Image.open(img_item_path)
img.show
label = self.label_dir
return img, label
def __len__(self): # How long is the dataset
return len(self.img_path)
root_dir = "D:\\ Data sets \\hymenoptera_data\\train"
ant_lable_dair = "ants"
bees_label_dir = "bees"
ant_dataset = MyData(root_dir, ant_lable_dair)
bees_dataset = MyData(root_dir,bees_label_dir)
ant_dataset.__getitem__(0)
for i in range(1,100):
bees_dataset.__getitem__(i)
img, label = ant_dataset[0]
img.show()
边栏推荐
- 评估方法的优缺点
- Anaconda3 安装cv2
- MySQL real battle optimization expert 08 production experience: how to observe the machine performance 360 degrees without dead angle in the process of database pressure test?
- Transactions have four characteristics?
- 第一篇博客
- Installation of pagoda and deployment of flask project
- Const decorated member function problem
- Software test engineer development planning route
- 华南技术栈CNN+Bilstm+Attention
- pytorch的Dataset的使用
猜你喜欢
14 medical registration system_ [Alibaba cloud OSS, user authentication and patient]
docker MySQL解决时区问题
Security design verification of API interface: ticket, signature, timestamp
实现以form-data参数发送post请求
Sichuan cloud education and double teacher model
MySQL实战优化高手12 Buffer Pool这个内存数据结构到底长个什么样子?
A necessary soft skill for Software Test Engineers: structured thinking
Contest3145 - the 37th game of 2021 freshman individual training match_ B: Password
Carolyn Rosé博士的社交互通演讲记录
[after reading the series of must know] one of how to realize app automation without programming (preparation)
随机推荐
MySQL实战优化高手05 生产经验:真实生产环境下的数据库机器配置如何规划?
Not registered via @enableconfigurationproperties, marked (@configurationproperties use)
Sed text processing
[programmers' English growth path] English learning serial one (verb general tense)
华南技术栈CNN+Bilstm+Attention
What is the difference between TCP and UDP?
MySQL实战优化高手04 借着更新语句在InnoDB存储引擎中的执行流程,聊聊binlog是什么?
CDC: the outbreak of Listeria monocytogenes in the United States is related to ice cream products
Installation of pagoda and deployment of flask project
Not registered via @EnableConfigurationProperties, marked(@ConfigurationProperties的使用)
15 医疗挂号系统_【预约挂号】
Technology | diverse substrate formats
Pytorch LSTM实现流程(可视化版本)
13 medical registration system_ [wechat login]
MySQL combat optimization expert 06 production experience: how does the production environment database of Internet companies conduct performance testing?
flask运维脚本(长时间运行)
如何让shell脚本变成可执行文件
Solution to the problem of cross domain inaccessibility of Chrome browser
C miscellaneous shallow copy and deep copy
A necessary soft skill for Software Test Engineers: structured thinking