在RStudio上部署带有cloudml的Keras模型失败

时间:2018-06-09 14:26:40

标签: r tensorflow keras google-cloud-ml

我试图在Google Cloud ML上部署我训练过的keras模型。该模型在我的本地计算机上运行良好,但无法在云中部署。我在macOS High Sierra(10.13.4)上使用RStudio上的cloudml库。

这是一个玩具示例:

model <- keras_model_sequential()

model %>%
  layer_dense(units = 78, activation = "sigmoid", input_shape = c(39)) %>%
  layer_dense(units = 39, activation = "sigmoid") %>%
  layer_dense(units = 20, activation = "sigmoid") %>%
  layer_dense(units = 1, activation = "sigmoid") %>% 
  compile(
    loss = 'mean_squared_error',
    optimizer = optimizer_rmsprop(),
    metrics = c('mean_squared_error')
  )

history <- model %>% fit(
  x_train, y_train,
  epochs = 1000,
  validation_split = 0.2
)

# deploy
export_savedmodel(model, "model")
cloudml_deploy("model", name = "keras_model")

这是我的版本信息:

> R.Version()
$platform
[1] "x86_64-apple-darwin15.6.0"

$arch
[1] "x86_64"

$os
[1] "darwin15.6.0"

$system
[1] "x86_64, darwin15.6.0"   

$status
[1] ""

$major
[1] "3"

$minor
[1] "4.1"

$year
[1] "2017"

$month
[1] "06"

$day
[1] "30"

$`svn rev`
[1] "72865" 

$language
[1] "R"

$version.string
[1] "R version 3.4.1 (2017-06-30)"

$nickname
[1] "Single Candle"

我的RStudio是版本1.1.423。本地R库版本是:

cloudml: 0.5
keras: 2.1.6.9001
tensorflow: 1.5.0.9001

我收到的错误消息是

Creating version (this might take a few minutes)
..............................................
..............................................
..............................................
..............................................
..............................................
...........................failed.
ERROR: (gcloud.ml-engine.versions.create) Bad model 
detected with error:  "Failed to load model: Loading 
servable: {name: default version: 1} failed: Not found: 
Op type not registered 'ClipByValue' in binary running 
on localhost. Make sure the Op and Kernel are registered 
in the binary running in this process.\n\n (Error code: 0

知道什么是错的?

3 个答案:

答案 0 :(得分:1)

let bodyParser=require('body-parser'); app.use(bodyParser.json()) R程序包中,要使用TensorFlow 1.8,可以将cloudml设置为:

cloudml.yml

然后像往常一样trainingInput: runtimeVersion: 1.8 进行部署以使用TensorFlow 1.8运行时进行部署。

答案 1 :(得分:0)

听起来这个图是在较新版本的TensorFlow上生成的,其中包含ClipByValue op(1.8 +),但是在没有版本的旧版本上使用。最简单的解决方案是使用较新版本的TensorFlow进行部署,但可能您可以使用较旧的TensorFlow版本(1.8之前)生成图形。

答案 2 :(得分:0)

创建版本时,请指定标记--runtime-version=1.8