error: python module tensorflow.keras was not found. detected python configuration
目录
error: python module tensorflow.keras was not found. detected python configuration
问题:
原来的安装有问题,程序如法运行;
原来的安装方式为:
install.packages('keras')
install.packages('tensorflow')
删除已经安装的keras和tensorflow包。
remove.packages('package_name')
library(DAAG)
head(ais)
# standardise
minmax <- function(x) (x - min(x))/(max(x) - min(x))
x_train <- apply(ais[,1:11], 2, minmax)
library(keras)
# set training data
x_train <- as.matrix(x_train)
# set model
model <- keras_model_sequential()
model %>%
layer_dense(units = 6, activation = "tanh", input_shape = ncol(x_train)) %>%
layer_dense(units = 2, activation = "tanh", name = "bottleneck") %>%
layer_dense(units = 6, activation = "tanh") %>%
layer_dense(units = ncol(x_train))
# view model layers
summary(model)
解决:
安装tensorflow和keras
devtools::install_github("rstudio/tensorflow")
devtools::install_github("rstudio/keras")
接着执行如下程序:
tensorflow::install_tensorflow()
tensorflow::tf_config()
接着在library(keras)的时候又发生错误:
需要从windows的指定地址下载匹配的文件处理;
Latest supported Visual C++ Redistributable downloads | Microsoft Learn
library(DAAG)
head(ais)
# standardise
minmax <- function(x) (x - min(x))/(max(x) - min(x))
x_train <- apply(ais[,1:11], 2, minmax)
library(keras)
# set training data
x_train <- as.matrix(x_train)
# set model
model <- keras_model_sequential()
model %>%
layer_dense(units = 6, activation = "tanh", input_shape = ncol(x_train)) %>%
layer_dense(units = 2, activation = "tanh", name = "bottleneck") %>%
layer_dense(units = 6, activation = "tanh") %>%
layer_dense(units = ncol(x_train))
# view model layers
summary(model)
正确的输出:
> model <- keras_model_sequential()
2022-12-04 17:59:02.205597: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2022-12-04 17:59:02.205841: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2022-12-04 17:59:12.769104: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'nvcuda.dll'; dlerror: nvcuda.dll not found
2022-12-04 17:59:12.769266: W tensorflow/stream_executor/cuda/cuda_driver.cc:263] failed call to cuInit: UNKNOWN ERROR (303)
2022-12-04 17:59:12.773317: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: XA311683
2022-12-04 17:59:12.773378: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: XA311683
2022-12-04 17:59:12.776187: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
> model %>%
+ layer_dense(units = 6, activation = "tanh", input_shape = ncol(x_train)) %>%
+ layer_dense(units = 2, activation = "tanh", name = "bottleneck") %>%
+ layer_dense(units = 6, activation = "tanh") %>%
+ layer_dense(units = ncol(x_train))
> # view model layers
> summary(model)
Model: "sequential"
_________________________________________________________________________________
Layer (type) Output Shape Param #
=================================================================================
dense_2 (Dense) (None, 6) 72
bottleneck (Dense) (None, 2) 14
dense_1 (Dense) (None, 6) 18
dense (Dense) (None, 11) 77
=================================================================================
Total params: 181
Trainable params: 181
Non-trainable params: 0
_________________________________________________________________________________
>
完整错误:
error: python module tensorflow.keras was not found. detected python configuration
参考:Keras @ Error: Python module tensorflow.keras was not found. - Posit Cloud - RStudio Community
参考:keras
参考:tensorflow
参考:tensorflow/README.md at master · rstudio/tensorflow · GitHub