首页 > 解决方案 > 在 Azure ML 中为注册的 R 模型部署 Web 服务

问题描述

我对使用azureml-sdk-for-r有一个绝对的噩梦。所以我尝试通过 UI ( https://ml.azure.com/ ) 来实现一切。我在 R 4.0.5 中像这样在本地训练了一个模型

library(datasets)
library(caret)

data(iris)

setwd("C:/Data")

index <- createDataPartition(iris$Species, p=0.80, list=FALSE)
testset <- iris[-index,]
trainset <- iris[index,]

model = train(Species ~ ., 
                  data=trainset, 
                  method="rpart", 
                  trControl = trainControl(method = "cv"))

saveRDS(model, "model.rds")

我通过 UI 部署/注册了它,没问题。我尝试用来删除模型依赖项的“评分脚本”如下(唯一的依赖项实际上是 jsonlite)。

library(jsonlite)

init <- function()
{
  message("model is loaded")
  
  function(data)
  {
    prediction_data <- as.data.frame(fromJSON(data))
    return('{"result": "Hello world"}')
  }
}

我使用以下 yml 文件作为此屏幕的 conda 依赖文件:

在此处输入图像描述

name: scoring_environment
channels:
  - defaults
dependencies:
  - r-base=4.0.5
  #- r-essentials=4.0.5
  # whatever other dependencies you have
  - jsonlite=1.7.2 

但立即得到这个:

在此处输入图像描述

我怎样才能调试发生了什么?conda依赖文件错了吗?就目前而言,Azure ML 对我作为具有本地训练模型的 R 用户来说绝对没用)-:

PS:

我也尝试像这样在本地部署它:

library(azuremlsdk)

interactive_auth <- interactive_login_authentication(tenant_id="296bf094-bdb4-488f-8ebd-92b2dd1464c2")

ws <- get_workspace(
        name = "xxx", 
        subscription_id = "xxx", 
        resource_group ="xxx", 
        auth = interactive_auth
)

model <- get_model(ws, name = "iris")

r_env <- r_environment(name = "r_env")

# Create inference config
inference_config <- inference_config(
  entry_script = "score1.R",
  source_directory = ".",
  environment = r_env)

local_deployment_config <- local_webservice_deployment_config()

service <- deploy_model(ws, 
                        'rservice-local', 
                        list(model), 
                        inference_config, 
                        local_deployment_config)
# Wait for deployment
wait_for_deployment(service, show_output = TRUE)

# Show the port of local service
message(service$port)

它将注册模型下载到我的本地机器。所以这个位有效,但随后出现此错误:

/azureml-envs/azureml_da3e97fcb51801118b8e80207f3e01ad/lib/python3.6/site-packages/rpy2/rinterface/__init__.py:146: RRuntimeWarning:  cannot open file '/var/azureml-app/iris/score1.R': No such file or directory

所以我尝试特意创建了一个相对文件夹:

/var/azureml-app/iris/

上面的脚本所在的位置并将 score1.r(见上文)放在那里。还是一样的错误。我搞不清楚了!

标签: razure-machine-learning-studioazure-machine-learning-serviceazuremlazuremlsdk

解决方案


推荐阅读