当前位置:网站首页>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()
边栏推荐
- Super detailed steps for pushing wechat official account H5 messages
- MySQL combat optimization expert 04 uses the execution process of update statements in the InnoDB storage engine to talk about what binlog is?
- 安装OpenCV时遇到的几种错误
- A necessary soft skill for Software Test Engineers: structured thinking
- NLP路线和资源
- In fact, the implementation of current limiting is not complicated
- Installation de la pagode et déploiement du projet flask
- MySQL combat optimization expert 07 production experience: how to conduct 360 degree dead angle pressure test on the database in the production environment?
- Write your own CPU Chapter 10 - learning notes
- C miscellaneous shallow copy and deep copy
猜你喜欢
四川云教和双师模式
高并发系统的限流方案研究,其实限流实现也不复杂
Complete web login process through filter
Not registered via @enableconfigurationproperties, marked (@configurationproperties use)
14 医疗挂号系统_【阿里云OSS、用户认证与就诊人】
UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xd0 in position 0成功解决
颜值爆表,推荐两款JSON可视化工具,配合Swagger使用真香
MySQL实战优化高手04 借着更新语句在InnoDB存储引擎中的执行流程,聊聊binlog是什么?
Installation of pagoda and deployment of flask project
MySQL combat optimization expert 12 what does the memory data structure buffer pool look like?
随机推荐
简单解决phpjm加密问题 免费phpjm解密工具
MySQL的存储引擎
16 医疗挂号系统_【预约下单】
四川云教和双师模式
MySQL combat optimization expert 02 in order to execute SQL statements, do you know what kind of architectural design MySQL uses?
Bugku web guide
cmooc互联网+教育
Retention policy of RMAN backup
[after reading the series of must know] one of how to realize app automation without programming (preparation)
Windchill配置远程Oracle数据库连接
Redis集群方案应该怎么做?都有哪些方案?
MySQL实战优化高手02 为了执行SQL语句,你知道MySQL用了什么样的架构设计吗?
高并发系统的限流方案研究,其实限流实现也不复杂
Security design verification of API interface: ticket, signature, timestamp
MySQL combat optimization expert 06 production experience: how does the production environment database of Internet companies conduct performance testing?
宝塔的安装和flask项目部署
Not registered via @enableconfigurationproperties, marked (@configurationproperties use)
Not registered via @EnableConfigurationProperties, marked(@ConfigurationProperties的使用)
NLP routes and resources
美疾控中心:美国李斯特菌疫情暴发与冰激凌产品有关