当前位置:网站首页>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()
边栏推荐
- Export virtual machines from esxi 6.7 using OVF tool
- 14 医疗挂号系统_【阿里云OSS、用户认证与就诊人】
- Installation de la pagode et déploiement du projet flask
- MySQL實戰優化高手04 借著更新語句在InnoDB存儲引擎中的執行流程,聊聊binlog是什麼?
- How to build an interface automation testing framework?
- Sed text processing
- jar运行报错no main manifest attribute
- South China Technology stack cnn+bilstm+attention
- Complete web login process through filter
- 软件测试工程师必备之软技能:结构化思维
猜你喜欢

Carolyn Rosé博士的社交互通演讲记录

实现微信公众号H5消息推送的超级详细步骤

UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xd0 in position 0成功解决

13 医疗挂号系统_【 微信登录】

Solve the problem of remote connection to MySQL under Linux in Windows

Super detailed steps to implement Wechat public number H5 Message push

A necessary soft skill for Software Test Engineers: structured thinking

Super detailed steps for pushing wechat official account H5 messages

Use JUnit unit test & transaction usage

Installation of pagoda and deployment of flask project
随机推荐
用于实时端到端文本识别的自适应Bezier曲线网络
Record the first JDBC
实现以form-data参数发送post请求
Installation de la pagode et déploiement du projet flask
C miscellaneous two-way circular linked list
Installation of pagoda and deployment of flask project
C杂讲 双向循环链表
Time complexity (see which sentence is executed the most times)
Typescript入门教程(B站黑马程序员)
Ueeditor internationalization configuration, supporting Chinese and English switching
Docker MySQL solves time zone problems
ByteTrack: Multi-Object Tracking by Associating Every Detection Box 论文阅读笔记()
The governor of New Jersey signed seven bills to improve gun safety
The 32-year-old fitness coach turned to a programmer and got an offer of 760000 a year. The experience of this older coder caused heated discussion
MySQL的存储引擎
MySQL实战优化高手09 生产经验:如何为生产环境中的数据库部署监控系统?
Cmooc Internet + education
text 文本数据增强方法 data argumentation
flask运维脚本(长时间运行)
The 32 year old programmer left and was admitted by pinduoduo and foreign enterprises. After drying out his annual salary, he sighed: it's hard to choose