Search code examples
rtensorflowdatasetmnist

Loading MNIST data in R


I'm trying to download Mnist data in order to work with it futher. I need to see first 9 numbers of this dataset, but I received an error. Here is my code:

install.packages("tensorflow")
library(tensorflow)
datasets <- tf$contrib$learn$datasets
mnist <- datasets$mnist$read_data_sets("MNIST-data", one_hot = TRUE)
Data = mnist$train$images[1:5000,]
Labels = mnist$train$labels[1:5000,]%*%matrix(0:9, nrow = 10)

Here is an error: enter image description here


Solution

  • I installed miniconda via scoop, i.e.

    scoop install miniconda3
    

    Then it recommended that I run conda install -n root -c pscondaenvs pscondaenvs. First, I closed down the current cmd/terminal. Turned on a new one and ran

    conda install -n root -c pscondaenvs pscondaenvs
    

    Then re-ran the code you have above, and gotten an error saying Tensorflow module is not installed. I then ran conda install tensorflow in a cmd/terminal. (but it recommended to use tensorflow::install_tensorflow() within R, maybe try that here).

    Error after installing miniconda.

    Now, next is the fact that contrib is not part of the tensorflow module anymore.. But this is where you can get MNIST, using tfds. The installation instructions that I had to follow:

    remotes::install_github("rstudio/tfds")
    tfds::install_tfds()
    mnist <- tfds::tfds_load("mnist")