当前位置:网站首页>pytorch的Dataset的使用
pytorch的Dataset的使用
2022-07-06 09:11:00 【一曲无痕奈何】
from torch.utils.data import Dataset
from PIL import Image
import os
class MyData():
def __init__(self, root_dir, label_dir):
#使用self相当于创建一个全局变量给后面的也可以使用
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)
#获取其中每一个图片
def __getitem__(self, index):
#通过index获取图片地址
img_name = self.img_path[index] #每个图片的路径
img_item_path = os.path.join(self.root_dir, self.label_dir, img_name)
print(img_item_path)
#读取图片
img = Image.open(img_item_path)
img.show
label = self.label_dir
return img, label
def __len__(self): #数据集有多长
return len(self.img_path)
root_dir = "D:\\数据集\\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()
边栏推荐
- Flash operation and maintenance script (running for a long time)
- Control the operation of the test module through the panel in canoe (Advanced)
- Solve the problem of remote connection to MySQL under Linux in Windows
- Simple solution to phpjm encryption problem free phpjm decryption tool
- MySQL实战优化高手03 用一次数据更新流程,初步了解InnoDB存储引擎的架构设计
- Canoe cannot automatically identify serial port number? Then encapsulate a DLL so that it must work
- Time complexity (see which sentence is executed the most times)
- Tianmu MVC audit II
- MySQL ERROR 1040: Too many connections
- MySQL的存储引擎
猜你喜欢
![[Julia] exit notes - Serial](/img/d0/87f0d57ff910a666fbb67c0ae8a838.jpg)
[Julia] exit notes - Serial

寶塔的安裝和flask項目部署

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

CAPL script pair High level operation of INI configuration file
![[flask] crud addition and query operation of data](/img/fc/7a12ede31befed5f42b32b94ae5ecf.jpg)
[flask] crud addition and query operation of data

The appearance is popular. Two JSON visualization tools are recommended for use with swagger. It's really fragrant

Installation of pagoda and deployment of flask project

MySQL real battle optimization expert 11 starts with the addition, deletion and modification of data. Review the status of buffer pool in the database

Download address of canoe, download and activation of can demo 16, and appendix of all canoe software versions

CAPL script printing functions write, writeex, writelineex, writetolog, writetologex, writedbglevel do you really know which one to use under what circumstances?
随机推荐
A necessary soft skill for Software Test Engineers: structured thinking
flask运维脚本(长时间运行)
Super detailed steps for pushing wechat official account H5 messages
MySQL实战优化高手09 生产经验:如何为生产环境中的数据库部署监控系统?
MySQL实战优化高手07 生产经验:如何对生产环境中的数据库进行360度无死角压测?
MySQL实战优化高手10 生产经验:如何为数据库的监控系统部署可视化报表系统?
[flask] crud addition and query operation of data
MySQL learning diary (II)
112 pages of mathematical knowledge sorting! Machine learning - a review of fundamentals of mathematics pptx
软件测试工程师必备之软技能:结构化思维
MySQL ERROR 1040: Too many connections
Bugku web guide
Tianmu MVC audit I
Retention policy of RMAN backup
MySQL实战优化高手06 生产经验:互联网公司的生产环境数据库是如何进行性能测试的?
oracle sys_ Context() function
[after reading the series of must know] one of how to realize app automation without programming (preparation)
MySQL combat optimization expert 02 in order to execute SQL statements, do you know what kind of architectural design MySQL uses?
Canoe CAPL file operation directory collection
C miscellaneous two-way circular linked list