当前位置:网站首页>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()
边栏推荐
- Chrome浏览器端跨域不能访问问题处理办法
- C miscellaneous shallow copy and deep copy
- 使用OVF Tool工具从Esxi 6.7中导出虚拟机
- Safety notes
- Simple solution to phpjm encryption problem free phpjm decryption tool
- 如何搭建接口自动化测试框架?
- C miscellaneous two-way circular linked list
- UEditor国际化配置,支持中英文切换
- 美疾控中心:美国李斯特菌疫情暴发与冰激凌产品有关
- Vscode common instructions
猜你喜欢
![17 medical registration system_ [wechat Payment]](/img/b4/f9abfa0fb0447d727078069d888b57.png)
17 medical registration system_ [wechat Payment]

【C语言】深度剖析数据存储的底层原理

MySQL实战优化高手03 用一次数据更新流程,初步了解InnoDB存储引擎的架构设计

Record the first JDBC

MySQL combat optimization expert 02 in order to execute SQL statements, do you know what kind of architectural design MySQL uses?

Notes of Dr. Carolyn ROS é's social networking speech

MySQL实战优化高手02 为了执行SQL语句,你知道MySQL用了什么样的架构设计吗?

寶塔的安裝和flask項目部署

MySQL combat optimization expert 03 uses a data update process to preliminarily understand the architecture design of InnoDB storage engine

实现以form-data参数发送post请求
随机推荐
[after reading the series of must know] one of how to realize app automation without programming (preparation)
Target detection -- yolov2 paper intensive reading
[programmers' English growth path] English learning serial one (verb general tense)
MySQL实战优化高手08 生产经验:在数据库的压测过程中,如何360度无死角观察机器性能?
Ueeditor internationalization configuration, supporting Chinese and English switching
MySQL实战优化高手12 Buffer Pool这个内存数据结构到底长个什么样子?
MySQL ERROR 1040: Too many connections
Upload vulnerability
MySQL底层的逻辑架构
Software test engineer development planning route
Vscode common instructions
Use JUnit unit test & transaction usage
Installation of pagoda and deployment of flask project
What should the redis cluster solution do? What are the plans?
C miscellaneous lecture continued
Flash operation and maintenance script (running for a long time)
Windchill配置远程Oracle数据库连接
MySQL combat optimization expert 10 production experience: how to deploy visual reporting system for database monitoring system?
MySQL实战优化高手03 用一次数据更新流程,初步了解InnoDB存储引擎的架构设计
Pointer learning