tests/testthat/model-building/keras-1.13.1.R

reticulate::use_virtualenv("tf-1.13.1")

# Packages ----------------------------------------------------------------

library(tensorflow)
library(keras)


mnist <- readRDS("data/mnist.rds")
next_batch <- function() {
  ids <- sample.int(nrow(mnist$train$x), size = 32)
  list(
    x = mnist$train$x[ids,],
    y = mnist$train$y[ids,]
  )
}

model <- keras_model_sequential() %>% 
  layer_dense(units = 10, input_shape = 784, activation = "softmax")

model %>% compile(optimizer = "sgd", loss = "categorical_crossentropy", 
                  metrics = "accuracy")

model %>% fit(mnist$train$x, mnist$train$y, epochs = 1)

evaluate(model, mnist$test$x, mnist$test$y)

export_savedmodel(
  model,
  "models/keras-1.13.1/"
  )

Try the tfdeploy package in your browser

Any scripts or data that you put into this service are public.

tfdeploy documentation built on June 14, 2019, 5:04 p.m.