Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't build model on Rstudio #613

Closed
edwardfung2018 opened this issue Dec 10, 2018 · 11 comments
Closed

Can't build model on Rstudio #613

edwardfung2018 opened this issue Dec 10, 2018 · 11 comments

Comments

@edwardfung2018
Copy link

Error in py_call_impl(callable, dots$args, dots$keywords) :
ValueError: Layer vgg16 was called with an input that isn't a symbolic tensor. Received type: <class 'keras.engine.sequential.Sequential'>. Full input: [<keras.engine.sequential.Sequential object at 0x000000002DFAB9E8>]. All inputs to the layer should be tensors.

@skeydan
Copy link

skeydan commented Dec 10, 2018

Hi, please post a minimal reproducible example.

@edwardfung2018
Copy link
Author

I follow this example https://tensorflow.rstudio.com/keras/ . When I run following code the error was shown.

model <- keras_model_sequential()
model %>%
layer_dense(units = 256, activation = 'relu', input_shape = c(784)) %>%
layer_dropout(rate = 0.4) %>%
layer_dense(units = 128, activation = 'relu') %>%
layer_dropout(rate = 0.3) %>%
layer_dense(units = 10, activation = 'softmax')

@skeydan
Copy link

skeydan commented Dec 10, 2018

Please post the complete code you're executing, and point out at which point the error occurs.

@edwardfung2018
Copy link
Author

edwardfung2018 commented Dec 10, 2018

install.packages("keras")
library(keras)
install_keras()

library(keras)
mnist <- dataset_mnist()
x_train <- mnist$train$x
y_train <- mnist$train$y
x_test <- mnist$test$x
y_test <- mnist$test$y

x_train <- array_reshape(x_train, c(nrow(x_train), 784))
x_test <- array_reshape(x_test, c(nrow(x_test), 784))

x_train <- x_train / 255
x_test <- x_test / 255

y_train <- to_categorical(y_train, 10)
y_test <- to_categorical(y_test, 10)

model <- keras_model_sequential()
model %>%
layer_dense(units = 256, activation = 'relu', input_shape = c(784)) %>%
layer_dropout(rate = 0.4) %>%
layer_dense(units = 128, activation = 'relu') %>%
layer_dropout(rate = 0.3) %>%
layer_dense(units = 10, activation = 'softmax')

All script is as above. when it run to the last part "model" then error was shown.

@skeydan
Copy link

skeydan commented Dec 10, 2018

Hi,

that code alone can't be throwing the above error. Try restarting R and then, just start with library(keras) and what follows.

The reason I'm saying this is that the error says something about "Layer vgg16 ".
VGG16 is a pretrained model that can be obtained like so

model <- application_vgg16()

which does not appear in the above code.

@skeydan skeydan closed this as completed Dec 17, 2018
@cak925
Copy link

cak925 commented Jan 24, 2019

I am also getting an error similar to this when I run:

library(keras)

model <- keras_model_sequential()

model %>%
layer_flatten( input_shape = c(28, 28)) %>%
layer_dense(units = 128, activation = 'relu') %>%
layer_dense(units = 10, activation = 'softmax')

I obtain the error:
" Error in py_call_impl(callable, dots$args, dots$keywords) :
ValueError: Layer flatten_1 was called with an input that isn't a symbolic tensor. Received type: <class 'keras.engine.sequential.Sequential'>. Full input: [<keras.engine.sequential.Sequential object at 0x0000000006BFA978>]. All inputs to the layer should be tensors. "

@cak925
Copy link

cak925 commented Jan 24, 2019

I have also tried to run the same example as edwardfung2018, and received the exact error he did.

@msmith01
Copy link

Obtaining the following error after running:

library(keras)
max_features <- 10000
maxlen <- 20

imdb <- dataset_imdb(num_words = max_features)

c(c(x_train, y_train), c(x_test, y_test)) %<-% imdb
x_train <- pad_sequences(x_train, maxlen = maxlen)
x_test <- pad_sequences(x_test, maxlen = maxlen)

model <- keras_model_sequential() %>%
  layer_embedding(input_dim = 10000, output_dim = 8,
                  input_length = maxlen) %>%
  layer_flatten() %>%
  layer_dense(units = 1, activation = "sigmoid")

Error:

Error in py_call_impl(callable, dots$args, dots$keywords) : 
 ValueError: Layer embedding_1 was called with an input that isn't a symbolic tensor. Received type: <class 'keras.engine.sequential.Sequential'>. Full input: [<keras.engine.sequential.Sequential object at 0x000000001854BB70>]. All inputs to the layer should be tensors. 

My example comes from the book "Deep Learning with R" - Page 176; Part " Listing 6.7 Using an embedding layer and classifier on the IMDB data "

@msmith01
Copy link

What appeared to work for me is to reinstall keras. I think the reticulate package is an older version which might be causing problems. Running the following solved the issue for me

require(devtools)
install_github("rstudio/reticulate")
install_github("rstudio/tensorflow")
install_github("rstudio/keras")

library(keras)
install_keras()

@Divya-Swaroopini
Copy link

I've got the exact same error now and none of the solutions seem to be working for me

@t-kalinowski
Copy link
Member

Hi, this thread is quite old, and likely stale. Can you please open a new issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants