|
读写Mnist保存为指定格式,图像数据如下:链接:https://pan.baidu.com/s/11UBOdsZ9FYi7PR0bGkn-JQ 提取码:y4v8- dev_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[0], ',', Substrings1)
- for i:= 0 to |ImageFiles|-1 by 1
- OCR_image_abspath := path + '/' + i + '.png'
- OCR_info := number(Substrings1[i])
- 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
复制代码
|
|