MNIST数据库介绍及转换(2)

for (int i = 0; i < vec_test_images.size(); i++) {
  int number = vec_test_labels[i];
  string image_name = GetImageName(number, count_digits);
  image_name = save_test_images_path + image_name + ".jpg";

cv::imwrite(image_name, vec_test_images[i]);
 }

//train images and train labels
 //read MNIST image into OpenCV Mat vector
 string filename_train_images = "D:/Download/train-images-idx3-ubyte/train-images.idx3-ubyte";
 int number_of_train_images = 60000;
 vector<cv::Mat> vec_train_images;

read_Mnist(filename_train_images, vec_train_images);

//read MNIST label into int vector
 string filename_train_labels = "D:/Download/train-labels-idx1-ubyte/train-labels.idx1-ubyte";
 vector<int> vec_train_labels(number_of_train_images);

read_Mnist_Label(filename_train_labels, vec_train_labels);

if (vec_train_images.size() != vec_train_labels.size()) {
  cout<<"parse MNIST train file error"<<endl;
  return -1;
 }

//save train images
 for (int i = 0; i < 10; i++)
  count_digits[i] = 0;

string save_train_images_path = "D:/Download/MNIST/train_images/";

for (int i = 0; i < vec_train_images.size(); i++) {
  int number = vec_train_labels[i];
  string image_name = GetImageName(number, count_digits);
  image_name = save_train_images_path + image_name + ".jpg";

cv::imwrite(image_name, vec_train_images[i]);
 }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/20ff44dfbb425d3dba9a6c6120670d0a.html