欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 新车 > pytorch引用halcon写数据集

pytorch引用halcon写数据集

2025/2/13 18:49:21 来源:https://blog.csdn.net/Tianwen_running/article/details/145538474  浏览:    关键词: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)

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com