当前位置:网站首页>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()
边栏推荐
- 如何搭建接口自动化测试框架?
- MySQL实战优化高手11 从数据的增删改开始讲起,回顾一下Buffer Pool在数据库里的地位
- Flash operation and maintenance script (running for a long time)
- Security design verification of API interface: ticket, signature, timestamp
- flask运维脚本(长时间运行)
- Anaconda3 安装cv2
- C miscellaneous shallow copy and deep copy
- Introduction tutorial of typescript (dark horse programmer of station B)
- A new understanding of RMAN retention policy recovery window
- 17 医疗挂号系统_【微信支付】
猜你喜欢

数据库中间件_Mycat总结

Contest3145 - the 37th game of 2021 freshman individual training match_ C: Tour guide

Pytorch LSTM实现流程(可视化版本)

解决在window中远程连接Linux下的MySQL

cmooc互联网+教育

History of object recognition

华南技术栈CNN+Bilstm+Attention

基于Pytorch肺部感染识别案例(采用ResNet网络结构)

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

If someone asks you about the consistency of database cache, send this article directly to him
随机推荐
jar运行报错no main manifest attribute
Solve the problem of remote connection to MySQL under Linux in Windows
MySQL combat optimization expert 05 production experience: how to plan the database machine configuration in the real production environment?
MySQL实战优化高手10 生产经验:如何为数据库的监控系统部署可视化报表系统?
C miscellaneous dynamic linked list operation
MySQL combat optimization expert 06 production experience: how does the production environment database of Internet companies conduct performance testing?
Mexican SQL manual injection vulnerability test (mongodb database) problem solution
cmooc互联网+教育
Compress decompress
第一篇博客
Use JUnit unit test & transaction usage
Anaconda3 安装cv2
Safety notes
14 medical registration system_ [Alibaba cloud OSS, user authentication and patient]
简单解决phpjm加密问题 免费phpjm解密工具
C杂讲 文件 初讲
oracle sys_ Context() function
Technology | diverse substrate formats
软件测试工程师必备之软技能:结构化思维
AI的路线和资源