本文介绍了如何用C ++读取MNIST数据集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在阅读以下问题:

并且有一些C ++代码用于读取MNIST数据库。在尝试它时,我发现它工作正常,直到它开始读取数据的地方。

and there was some C++ code for reading the MNIST database. Upon trying it I found out that it worked fine until the place where it started reading the data.

这是以下代码:

 for(int i=0;i<number_of_images;++i)
      {
        for(int r=0;r<n_rows;++r)
        {
            for(int c=0;c<n_cols;++c)
            {
                unsigned char temp=0;
                file.read((char*)&temp,sizeof(temp));
                //cout<<(int)temp<<" "; //printing the pixel in integer format

            }
        }
    }


b $ b

我尝试打印出变量temp的整数值,但是我没有得到像素的正确数字(所有的都是零)。
我不知道有什么问题,每个像素需要一个字节的空间,然后我将其转换为一个int,它不工作。为什么会发生这种情况?提前感谢你

I tried printing out the integer value of the variable "temp" however I didn't get the correct number for the pixels(all of them were zero).I'm not sure what's wrong there, each pixel takes one bytes space and then I convert it to an int and it doesn't work. Why does this happen? thank you in advance

推荐答案

使用MNIST数据集时,我遇到了同样的问题。我可以读标签,但训练和测试集的图像大多是假的;训练集几乎完全填充175,并且测试集几乎完全填充0(除了前6个图像)。重新启动没有解决问题,我无法确定文件读取为何无法正常工作。

When working with the MNIST data set, I had the same problem that you had. I could read the labels, but the training and test set images were mostly bogus; the training set was filled almost entirely with 175, and the testing set was filled almost entirely with 0s (except for the first 6 images). Rebooting did not fix the problem and I was unable to determine why the file reading was not working correctly.

对于有相同问题的任何人,我建议改用数据文件,位于。数据已经按数量组织(不需要标签/图像关联),并且像素值的数组一个接一个地简单编码。知道每个数组是28x28,每个数字有1000个图像,你可以轻松地编写代码来输入像素值的单个图像数组。

For anyone with this same problem, I would suggest instead using the data files located at http://cis.jhu.edu/~sachin/digit/digit.html. The data is already organized by number (no label/image association required), and the arrays of pixel values are simply encoded one after the other. Knowing that each array is 28x28 and that there are 1000 images for each number, you can easily write code to input the individual image arrays of pixel values.

这篇关于如何用C ++读取MNIST数据集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 02:55