Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. library(keras)
  2.  
  3. FLAGS <- flags(
  4. flag_numeric("dropout_rate", 0.4)
  5. )
  6.  
  7. mnist <- dataset_mnist()
  8. x_train <- mnist$train$x
  9. y_train <- mnist$train$y
  10. x_test <- mnist$test$x
  11. y_test <- mnist$test$y
  12.  
  13. x_train <- array_reshape(x_train, c(nrow(x_train), 784))
  14. x_test <- array_reshape(x_test, c(nrow(x_test), 784))
  15. x_train <- x_train / 255
  16. x_test <- x_test / 255
  17.  
  18. y_train <- to_categorical(y_train, 10)
  19. y_test <- to_categorical(y_test, 10)
  20.  
  21. model <- keras_model_sequential()
  22.  
  23. model %>%
  24. layer_dense(units = 256, activation = 'relu', input_shape = c(784)) %>%
  25. layer_dropout(rate = FLAGS$dropout_rate) %>%
  26. layer_dense(units = 128, activation = 'relu') %>%
  27. layer_dropout(rate = 0.3) %>%
  28. layer_dense(units = 10, activation = 'softmax')
  29.  
  30. model %>% compile(
  31. loss = 'categorical_crossentropy',
  32. optimizer = optimizer_rmsprop(),
  33. metrics = c('accuracy')
  34. )
  35.  
  36. model %>% fit(
  37. x_train, y_train,
  38. epochs = 20, batch_size = 128,
  39. validation_split = 0.2
  40. )
  41.  
  42. model %>% evaluate(x_test, y_test)
  43. model %>% predict_classes(x_test)
  44.  
  45. # everything works fine till above line
  46.  
  47. export_savedmodel(model, "savedmodel") # Error line
  48.  
  49. Error in export_savedmodel.keras.engine.training.Model(model, "savedmodel") :
  50. 'export_savedmodel()' is currently unsupported under the TensorFlow Keras implementation, consider using 'tfestimators::keras_model_to_estimator()'
  51.  
  52. #export_savedmodel(model, "savedmodel") <-- replace this line with below code
  53. tfe_model <- tfestimators::keras_model_to_estimator(model)
  54. export_savedmodel(tfe_model, "savedmodel")
  55.  
  56. Error in export_savedmodel.tf_estimator(tfe_model, "savedmodel") :
  57. Currently only classifier and regressor are supported. Please specify a custom serving_input_receiver_fn.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement