I am using Rstudio on Google cloud platform and want to deploy a trained model but facing error. I am using examples present at https://tensorflow.rstudio.com/keras/
I am unable to export model to google cloud storage , after which I can create model version on google cloud storage and use if for predictions. I am able to do predictions in Rstudio.
Code:
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 = FLAGS$dropout_rate) %>%
layer_dense(units = 128, activation = 'relu') %>%
layer_dropout(rate = 0.3) %>%
layer_dense(units = 10, activation = 'softmax')
model %>% compile(
loss = 'categorical_crossentropy',
optimizer = optimizer_rmsprop(),
metrics = c('accuracy')
)
model %>% fit(
x_train, y_train,
epochs = 20, batch_size = 128,
validation_split = 0.2
)
model %>% evaluate(x_test, y_test)
model %>% predict_classes(x_test)
# everything works fine till above line
export_savedmodel(model, "savedmodel") # Error line
#Error message: for line in Rstudio --> export_savedmodel(model, "savedmodel")
# 'export_savedmodel()' is currently unsupported under the TensorFlow Keras implementation, consider using 'tfestimators::keras_model_to_estimator()'
#After this I tried below code:
#export_savedmodel(model, "savedmodel") <-- replace this line with below code
tfe_model <- tfestimators::keras_model_to_estimator(model)
export_savedmodel(tfe_model, "savedmodel")
#Error message:
# Error in export_savedmodel.tf_estimator(tfe_model, "savedmodel") : Currently only classifier and regressor are supported. Please specify a custom serving_input_receiver_fn.
Regards,
Tokci