模仿mnist資料集製作自己的資料集
阿新 • • 發佈:2019-02-05
程式碼執行效果如下:#include "Image_to_BinaryData.h" int main() { Image2BinaryData IBD(28,28); //設定圖片大小(Height,Width) /*------------生成訓練集檔案--------------------------*/ printf("----------生成訓練集檔案-------------\n"); string trainfilefolder = "C:\\Users\\lyf\\Desktop\\mnist\\train_images"; //訓練圖片檔案路徑 vector<string> trainfileLists = IBD.getFileLists(trainfilefolder); //獲得檔名列表 const int train_size_list = trainfileLists.size(); cout << "Images Number: " << train_size_list << endl; //輸出檔案個數 string trainimagebinfilepath = "C:\\Users\\lyf\\Desktop\\train-images-idx3-ubyte"; //訓練圖片轉換儲存路徑 string trainlabelbinfilepath = "C:\\Users\\lyf\\Desktop\\train-labels-idx1-ubyte"; //訓練標籤轉換儲存路徑 vector<cv::Mat> TrainImagesMat; //用來儲存訓練圖片畫素值 vector<int> train_image_labels(train_size_list); //用來儲存訓練類標籤列表 IBD.ReadImage(trainfilefolder, trainfileLists, train_image_labels, TrainImagesMat); //讀取訓練圖片 IBD.Image2BinaryFile(trainimagebinfilepath, TrainImagesMat, train_image_labels); //訓練圖片轉二進位制檔案 IBD.Label2BinaryFile(trainlabelbinfilepath, train_image_labels); //訓練標籤轉二進位制檔案 /*------------生成測試集檔案--------------------------*/ printf("\n\n----------生成測試集檔案-------------\n"); string testfilefolder = "C:\\Users\\lyf\\Desktop\\mnist\\test_images"; //測試圖片檔案路徑 vector<string> testfileLists = IBD.getFileLists(testfilefolder); //獲得檔名列表 const int test_size_list = testfileLists.size(); cout << "Images Number: " << test_size_list << endl; //輸出檔案個數 string testimagebinfilepath = "C:\\Users\\lyf\\Desktop\\t10k-images-idx3-ubyte"; //測試圖片轉換儲存路徑 string testlabelbinfilepath = "C:\\Users\\lyf\\Desktop\\t10k-labels-idx1-ubyte"; //測試標籤轉換儲存路徑 vector<cv::Mat> TestImagesMat; //用來儲存測試圖片畫素值 vector<int> test_image_labels(test_size_list); //用來儲存測試類標籤列表 IBD.ReadImage(testfilefolder, testfileLists, test_image_labels, TestImagesMat); //讀取測試圖片 IBD.Image2BinaryFile(testimagebinfilepath, TestImagesMat, test_image_labels); //測試圖片轉二進位制檔案 IBD.Label2BinaryFile(testlabelbinfilepath, test_image_labels); //測試標籤轉二進位制檔案 return 0; }