I am doing the CNN part of the tutorial. I keep running into this error. It doesn’t like me passing anything into layer_conv_2d() for the object parameter which is the first parameter.
https://www.datacamp.com/tutorial/neural-network-models-r?irclickid=VGI1xYwGFxyNUkix4pXmXUxOUkHTigXgrR3RUg0&irgwc=1&utm_medium=affiliate&utm_source=impact&utm_campaign=000000_1-2003851_2-mix_3-all_4-na_5-na_6-na_7-mp_8-affl-ip_9-na_10-bau_11-Bing%20Rebates%20by%20Microsoft&utm_content=BANNER&utm_term=EdgeBingFlow
library(keras)
library(tensorflow)
# Load CIFAR-10 dataset
data <- dataset_cifar10()
# Split the dataset into train and test sets
x_train <- data$train$x / 255
y_train <- data$train$y
x_test <- data$test$x / 255
y_test <- data$test$y
# Define the sequential model
model <- keras_model_sequential()
# Add the first convolutional layer
model %>%
layer_conv_2d(
filters = 16,
kernel_size = c(3, 3),
padding = "same",
input_shape = c(32, 32, 3),
activation = 'relu'
)
Error in py_call_impl(callable, call_args$unnamed, call_args$named) :
ValueError: Only input tensors may be passed as positional arguments. The following argument value should be passed as a keyword argument: <Sequential name=sequential_2, built=False> (of type <class 'keras.src.models.sequential.Sequential'>)
Run `reticulate::py_last_error()` for details.
── R Traceback ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
▆
1. ├─model %>% ...
2. └─keras::layer_conv_2d(...)
3. └─keras::create_layer(keras$layers$Conv2D, object, args)
4. ├─keras:::compose_layer(object, layer)
5. └─keras:::compose_layer.default(object, layer)
6. └─reticulate (local) layer(object, ...)
7. └─reticulate:::py_call_impl(callable, call_args$unnamed, call_args$named)
> reticulate::py_last_error()$r_trace$full_call
[[1]]
model %>% layer_conv_2d(filters = 16, kernel_size = c(3, 3),
padding = "same", input_shape = c(32, 32, 3), activation = "relu")
[[2]]
layer_conv_2d(., filters = 16, kernel_size = c(3, 3), padding = "same",
input_shape = c(32, 32, 3), activation = "relu")
[[3]]
create_layer(keras$layers$Conv2D, object, args)
[[4]]
compose_layer(object, layer)
[[5]]
compose_layer.default(object, layer)
[[6]]
layer(object, ...)
[[7]]
py_call_impl(callable, call_args$unnamed, call_args$named)
I tried this one too. SAME ERROR nothing works.
# Install the keras package
install.packages("keras")
# Load the keras library
library(keras)
# Initialize the CNN
model <- keras_model_sequential()
# Add the first layer
model %>%
layer_conv_2d(filters = 32, kernel_size = c(3,3), activation = 'relu', input_shape = c(64,64,3)) %>%
layer_max_pooling_2d(pool_size = c(2,2))
https://reintech.io/blog/convolutional-neural-networks-with-r