Error : Python module tensorflow.python.keras was not found

Viewed 4698

I want to convert some numeric values into category. I am using 'keras' package for image classification.

When I am using to_categorical(trainy), getting "Error: Python module tensorflow.python.keras was not found."

I have taken trainy <- c(0,0,0,0,0,1,1,1,1,1) and convert it into categorical values.

library(keras)
library(tensorflow)
trainy <- c(0,0,0,0,0,1,1,1,1,1)
trainLabels <- to_categorical(trainy)

The values in that vector should be converted into categorical values.

2 Answers

Your code works perfectly in my machine.

Please check that you used the install_keras() command to install keras and/or Tensorflow for R in your machine.

So your code would be like this:

library(keras)
library(tensorflow)

install_keras() # or install_tensorflow() depending on what you want

trainy <- c(0,0,0,0,0,1,1,1,1,1)
trainLabels <- to_categorical(trainy)

Hope this helps!

conda create -n tf tensorflow
conda activate tf

Or, to install the current release of GPU TensorFlow on Linux or Windows:

conda create -n tf-gpu tensorflow-gpu
conda activate tf-gpu

Install GPU TensorFlow on Windows using Anaconda prompt with above command.Then re install the tensorflow package in RStudio, load the library (tensorflow). Now run the command

trainLabels <- to_categorical(trainy)

This worked for me.

Related