Halcom 发表于 2023-2-5 20:01:54

读写Mnist保存为指定格式

读写Mnist保存为指定格式,图像数据如下:链接:https://pan.baidu.com/s/11UBOdsZ9FYi7PR0bGkn-JQ提取码:y4v8dev_update_off()
* 图像路径
path := 'D:/2-LearningCode/999-AI-Pytorch/10_OCR_Pytorch/OCR_Dataset/mnist-master/MNIST_data/Train/train'
* txt文本,每张图对应的label标签
train_label := 'D:/2-LearningCode/999-AI-Pytorch/10_OCR_Pytorch/OCR_Dataset/mnist-master/MNIST_data/Train/train_label.txt'
* 创建存储txt
File_Name := 'MNIST_data_train.txt'
file_exists(File_Name,FileExits)
if(FileExits)
    open_file(File_Name,'append',FileHandle_train)
else
    open_file(File_Name,'output',FileHandle_train)
endif
list_image_files(path, 'default', [], ImageFiles)
* 读取train_label
open_file (train_label, 'input', FileHandle)
IsEOF := 0
nums := []
while (IsEOF == 0)
    fread_string (FileHandle, Number, IsEOF)
    tuple_split(Number, '\n', Substrings)
    if(|Substrings|>0)
      tuple_split(Substrings, ',', Substrings1)
      for i:= 0 to |ImageFiles|-1 by 1
            OCR_image_abspath := path + '/' + i + '.png'
            OCR_info := number(Substrings1)
            fwrite_string(FileHandle_train, OCR_image_abspath + ',' + OCR_info + '\n')
      endfor
    endif
endwhile
close_file (FileHandle)
close_file (FileHandle_train)结果如下:
D:/2-LearningCode/999-AI-Pytorch/10_OCR_Pytorch/OCR_Dataset/mnist-master/MNIST_data/Train/train/0.png,5
D:/2-LearningCode/999-AI-Pytorch/10_OCR_Pytorch/OCR_Dataset/mnist-master/MNIST_data/Train/train/1.png,0
D:/2-LearningCode/999-AI-Pytorch/10_OCR_Pytorch/OCR_Dataset/mnist-master/MNIST_data/Train/train/2.png,4
D:/2-LearningCode/999-AI-Pytorch/10_OCR_Pytorch/OCR_Dataset/mnist-master/MNIST_data/Train/train/3.png,1
D:/2-LearningCode/999-AI-Pytorch/10_OCR_Pytorch/OCR_Dataset/mnist-master/MNIST_data/Train/train/4.png,9
D:/2-LearningCode/999-AI-Pytorch/10_OCR_Pytorch/OCR_Dataset/mnist-master/MNIST_data/Train/train/5.png,2



页: [1]
查看完整版本: 读写Mnist保存为指定格式