Hello Mat

 找回密码
 立即注册
查看: 1014|回复: 0

读写Mnist保存为指定格式

[复制链接]

1294

主题

1520

帖子

110

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22633
发表于 2023-2-5 20:01:54 | 显示全部楼层 |阅读模式
读写Mnist保存为指定格式,图像数据如下:链接:https://pan.baidu.com/s/11UBOdsZ9FYi7PR0bGkn-JQ  提取码:y4v8
  1. dev_update_off()
  2. * 图像路径
  3. path := 'D:/2-LearningCode/999-AI-Pytorch/10_OCR_Pytorch/OCR_Dataset/mnist-master/MNIST_data/Train/train'
  4. * txt文本,每张图对应的label标签
  5. train_label := 'D:/2-LearningCode/999-AI-Pytorch/10_OCR_Pytorch/OCR_Dataset/mnist-master/MNIST_data/Train/train_label.txt'
  6. * 创建存储txt
  7. File_Name := 'MNIST_data_train.txt'
  8. file_exists(File_Name,FileExits)
  9. if(FileExits)
  10.     open_file(File_Name,'append',FileHandle_train)
  11. else
  12.     open_file(File_Name,'output',FileHandle_train)
  13. endif
  14. list_image_files(path, 'default', [], ImageFiles)
  15. * 读取train_label
  16. open_file (train_label, 'input', FileHandle)
  17. IsEOF := 0
  18. nums := []
  19. while (IsEOF == 0)
  20.     fread_string (FileHandle, Number, IsEOF)
  21.     tuple_split(Number, '\n', Substrings)
  22.     if(|Substrings|>0)
  23.         tuple_split(Substrings[0], ',', Substrings1)
  24.         for i:= 0 to |ImageFiles|-1 by 1
  25.             OCR_image_abspath := path + '/' + i + '.png'
  26.             OCR_info := number(Substrings1[i])
  27.             fwrite_string(FileHandle_train, OCR_image_abspath + ',' + OCR_info + '\n')
  28.         endfor
  29.     endif
  30. endwhile
  31. close_file (FileHandle)
  32. close_file (FileHandle_train)
复制代码
结果如下:
  1. D:/2-LearningCode/999-AI-Pytorch/10_OCR_Pytorch/OCR_Dataset/mnist-master/MNIST_data/Train/train/0.png,5
  2. D:/2-LearningCode/999-AI-Pytorch/10_OCR_Pytorch/OCR_Dataset/mnist-master/MNIST_data/Train/train/1.png,0
  3. D:/2-LearningCode/999-AI-Pytorch/10_OCR_Pytorch/OCR_Dataset/mnist-master/MNIST_data/Train/train/2.png,4
  4. D:/2-LearningCode/999-AI-Pytorch/10_OCR_Pytorch/OCR_Dataset/mnist-master/MNIST_data/Train/train/3.png,1
  5. D:/2-LearningCode/999-AI-Pytorch/10_OCR_Pytorch/OCR_Dataset/mnist-master/MNIST_data/Train/train/4.png,9
  6. D:/2-LearningCode/999-AI-Pytorch/10_OCR_Pytorch/OCR_Dataset/mnist-master/MNIST_data/Train/train/5.png,2
复制代码




算法QQ  3283892722
群智能算法链接http://halcom.cn/forum.php?mod=forumdisplay&fid=73
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Python|Opencv|MATLAB|Halcom.cn ( 蜀ICP备16027072号 )

GMT+8, 2024-4-28 03:51 , Processed in 0.227738 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表