当前位置: 首页 > news >正文

pytorch引用halcon写数据集

****加粗样式虽然啰嗦一点,但好歹halcon自己熟悉,不会忘记,用os 和 pil会导致脑子记得东西太多

import halcon as ha
import torch
from torch.utils.data import Datasetpath0 = r'E:\BaiduNetdiskDownload\cell'
class MyDataset(Dataset):def __init__(self, path0):self.path = path0self.image_files = ha.list_files(path0 + '\masks','files')def __len__(self):number= ha.tuple_length(self.image_files)return numberdef __getitem__(self, index):path1=self.image_files[index]print('path1',path1)image_marks = ha.read_image(path1)#### 这里要注意的是分割符  “\\”tuple_string = ha.tuple_split(path1,"\\")leng = ha.tuple_length(tuple_string)name_string =ha.tuple_select(tuple_string,leng-1)name_s = ha.tuple_split(name_string,'.')name = name_s[0]test_image_files = ha.list_files(self.path + '\imgs','files')path = ha.tuple_regexp_select(test_image_files, name+'.')###如果数据集是0,1.。。。。200这样的话 0,10,100,110是比较麻烦的,建议命名用 n+数字  也就是英文字母加数字的形式更方便一些if int(name) <10:path=path[0]print(path)image_text =ha.read_image(path)imagetext_np = ha.himage_as_numpy_array(image_text)image_marks_np = ha.himage_as_numpy_array(image_marks)return  imagetext_np,image_marks_np,dataset = MyDataset(path0)
print(dataset.__len__())
text,marks =dataset.__getitem__(0)
print('text',text)
print('marks',marks)
http://www.lryc.cn/news/534244.html

相关文章:

  • 让文物“活”起来,以3D数字化技术传承文物历史文化!
  • aarch64 Ubuntu20.04 安装docker
  • JAVA:CloseableHttpClient 进行 HTTP 请求的技术指南
  • Mac上搭建k8s环境——Minikube
  • 经典排序算法复习----C语言
  • 自动驾驶数据集三剑客:nuScenes、nuImages 与 nuPlan 的技术矩阵与生态协同
  • [LUA ERROR] bad light userdata pointer
  • 【Java八股】JVM
  • 集成学习(一):从理论到实战(附代码)
  • Netty:高性能网络应用框架的深度解析
  • 神经网络常见激活函数 3-ReLU函数(修正线性单元)
  • Android开发获取缓存,删除缓存
  • 如何通过PHP接入DeepSeek的API
  • 一种基于Leaflet.Legend的图例动态更新方法
  • Spring Boot: 使用 @Transactional 和 TransactionSynchronization 在事务提交后发送消息到 MQ
  • LQB(2)-python-枚举
  • MongoDB开发规范
  • 为什么DeepSeek服务器繁忙?
  • 律所录音证据归集工具:基于PyQt6与多线程的自动化音频管理解决方案
  • 【含开题报告+文档+PPT+源码】基于SpringBoot+Vue旅游管理网站
  • unity碰撞的监测和监听
  • DeepSeek-R1 32B Windows+docker本地部署
  • C++11新特性之unique_ptr智能指针
  • Vue与Konva:解锁Canvas绘图的无限可能
  • python绘图之柱状堆积图的绘制
  • 剪辑学习整理
  • DeepSeek从入门到精通:全面掌握AI大模型的核心能力
  • AI大模型训练实战:分布式与微调指南
  • 整合 Redis 分布式锁:从数据结构到缓存问题解决方案
  • 并查集题目