初始化针对部署在云ML

时间:2019-01-15 12:13:09

标签: r deployment keras google-cloud-ml

我已经在R版本的keras中构建了一个模型,并通过Google Cloud ML进行了部署

该模型在从字符串转换为数字的输入上进行训练

在进行预测时,我使用查找表将字符串转换为数字,然后将数字输入传递给模型

这很容易在本地计算机上完成:

library(tidyverse)
library(cloudml)

# lookup table 
lookup <- tibble(int = c(1, 2, 3),
                 str = c('A1', 'B1', 'C1'))

# input strings
 a <- 'A1'
 b <- 'B1'

# convert to numeric 
a_ <- lookup %>% filter(str == a) %>% select(int) %>% pull()
b_ <- lookup %>% filter(str == b) %>% select(int) %>% pull()

# send to deployed model and receive predictions
cloudml_predict(
  instances = list(c(a_, b_)),
  name = "size_predictor",
  version = "a_1",
  verbose = T
)

但是,我无法确定将查找表放在云ml上的位置。它长几百万行。我是否需要在开始时就在keras模型中添加另一层?

或者我可以将查询表存储在BigQuery中,并预先通过该请求转移输入吗?

到目前为止,我发现的答案仅适用于python,例如:Add Tensorflow pre-processing to existing Keras model (for use in Tensorflow Serving)

1 个答案:

答案 0 :(得分:0)

在Keras的输入函数中,可以使用tf.gather()将接收到的字符串转换为int吗?然后,它是模型的一部分,将透明地工作。