首页 > 解决方案 > py_call_impl(callable, dots\$args, dots\$keywords) 中的错误 - 与 Leprechault 类似的情况,但

问题描述

我面临一个几个小时都无法解决的问题……我想我需要一些帮助。我从R 示例中的示例 Keras开始,该示例在我的环境中运行良好

然后我使用下面的基本脚本,调用 fit() 函数时总是失败,我无法找出问题所在。我检查了类,我的输入数据的暗淡,这听起来不错...我尝试在调用 fit() 之前执行 as.array() 转换,但这给出了相同的结果。

df<-read.csv("https://raw.githubusercontent.com/stchln/test/main/prtt.csv",sep=",")
xn<-cbind(df$L1SW,df$L2SW,df$L3SW,df$BOAMSW,df$RFSW,df$ET,df$ST)
yn<-cbind(df$pronto_id)
library(keras)
model = keras_model_sequential() %>% 
   layer_dense(units=64, activation="relu", input_shape=3) %>% 
   layer_dense(units=32, activation = "relu") %>% 
   layer_dense(units=1, activation="linear")
 
model %>% compile(
   loss = "mse",
   optimizer =  "adam", 
   metrics = list("mean_absolute_error")
 )
model %>% summary()

model %>% fit(xn, yn, epochs = 100,verbose = 0)

在 py_call_impl(callable, dots\$args, dots\$keywords) 中得到错误: ValueError: 在用户代码中:

任何想法?

标签: kerasr

解决方案


当您的数据维度不正确/与模型架构不匹配时,通常会发生此错误,另请参阅此 github 问题。在您的情况下,这可能是由于您传入 7 列但将其设置input_shape为 3。尝试将input_shape参数的值更改为 7:

model = keras_model_sequential() %>% 
   layer_dense(units=64, activation="relu", input_shape=7) %>% 
   layer_dense(units=32, activation = "relu") %>% 
   layer_dense(units=1, activation="linear")

推荐阅读