How to read MNIST database in R?

后端 未结 5 692
迷失自我
迷失自我 2021-02-05 22:31

I\'m currently working on a case study for which I need to work on the MNIST database.
The files in this site are said to be in IDX file format. I tried to take a look at th

5条回答
  •  猫巷女王i
    2021-02-05 23:14

    I tried the above, using:

    data <- readBin(to.read, integer(), size = 1, n = 784, endian="big")
    

    but ended up with both positive and negative integers in the image. Consequently, when plotted, using:

    plot(as.cimg(data))
    

    I get a grey background with the character in pixels that are darker or lighter than the background.

    I then used: (see [1]https://tensorflow.rstudio.com/tfestimators/articles/examples/mnist.html)

    data <- readBin(to.read, what = "raw", n = 784, endian="big")
    conv <- as.integer(data)
    mm <- matrix(conv, 28, 28)
    

    Now I have only positive values (0 to 255), and the plot gives a proper white character on a black background. Which is what I wanted.

提交回复
热议问题