Error in py_call_impl(callable, dots\$args, dots\$keywords) - case similar to Leprechault but

Viewed 2519

I am facing an issue that I am not able to solve for hours... and I think I need some help. I am starting from an example Keras in R example that is working fine in my environment

Then I am using basic script below that is always failing when calling fit() function and I am not able to figure out what is wrong. I have checked the class, dim of my input data and this sounds ok... I tried to do an as.array() to convert before calling fit() but this gives same result.

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)

and I get Error in py_call_impl(callable, dots\$args, dots\$keywords) : ValueError: in user code:

Any idea?

1 Answers

This error often occurs when the dimensions of your data are incorrect/do not match with the model architecture, see also this github issue. In your case it may be caused by the fact that you are passing in 7 columns but are setting the input_shape to 3. Try changing the value for the input_shape argument to 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")
Related