当前位置:网站首页>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()
边栏推荐
- ZABBIX introduction and installation
- MySQL combat optimization expert 10 production experience: how to deploy visual reporting system for database monitoring system?
- Sichuan cloud education and double teacher model
- NLP路线和资源
- Use JUnit unit test & transaction usage
- Simple solution to phpjm encryption problem free phpjm decryption tool
- Super detailed steps to implement Wechat public number H5 Message push
- If someone asks you about the consistency of database cache, send this article directly to him
- Implement context manager through with
- C miscellaneous dynamic linked list operation
猜你喜欢
A necessary soft skill for Software Test Engineers: structured thinking
用于实时端到端文本识别的自适应Bezier曲线网络
17 medical registration system_ [wechat Payment]
C miscellaneous dynamic linked list operation
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
Introduction tutorial of typescript (dark horse programmer of station B)
C杂讲 动态链表操作 再讲
Use JUnit unit test & transaction usage
If someone asks you about the consistency of database cache, send this article directly to him
Installation of pagoda and deployment of flask project
随机推荐
MySQL combat optimization expert 06 production experience: how does the production environment database of Internet companies conduct performance testing?
MySQL combat optimization expert 04 uses the execution process of update statements in the InnoDB storage engine to talk about what binlog is?
Software test engineer development planning route
C杂讲 浅拷贝 与 深拷贝
The appearance is popular. Two JSON visualization tools are recommended for use with swagger. It's really fragrant
Super detailed steps to implement Wechat public number H5 Message push
flask运维脚本(长时间运行)
If someone asks you about the consistency of database cache, send this article directly to him
Ueeditor internationalization configuration, supporting Chinese and English switching
C杂讲 文件 初讲
MySQL storage engine
MySQL实战优化高手12 Buffer Pool这个内存数据结构到底长个什么样子?
MySQL实战优化高手06 生产经验:互联网公司的生产环境数据库是如何进行性能测试的?
MySQL combat optimization expert 09 production experience: how to deploy a monitoring system for a database in a production environment?
Windchill配置远程Oracle数据库连接
oracle sys_ Context() function
UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xd0 in position 0成功解决
How to build an interface automation testing framework?
PyTorch RNN 实战案例_MNIST手写字体识别
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