简体   繁体   English

为 Vertex AI model 评估生成实例和预测模式文件(谷歌云管道组件)

[英]Generate instances and prediction schema files for Vertex AI model evaluation (Google Cloud pipeline components)

I build a custom model and try to use Google Cloud pipeline components for model evaluation on Vertex AI.我构建了一个自定义 model 并尝试使用 Google Cloud 管道组件在 Vertex AI 上进行 model 评估。 According to the model_upload_predict_evaluate notebook sample, I need to prepare instance_schema.yaml and prediction_schema.yaml to import unmanaged model.根据model_upload_predict_evaluate笔记本示例,我需要准备 instance_schema.yaml 和 prediction_schema.yaml 以导入非托管 model。

So how to generate the instance and prediction schema files programmatically?那么如何以编程方式生成实例和预测模式文件呢?

For custom models, instances and prediction schemas are not required:对于自定义模型,不需要实例和预测模式:

"predictSchemata": {
    "predictionSchemaUri": MODEL_URI + "/prediction_schema.yaml",
    "instanceSchemaUri": MODEL_URI + "/instance.yaml",
},

In short:简而言之:

Now to build programmatically, it depends on your use case and what you start from.现在以编程方式构建,这取决于您的用例和您的起点。 I'm sure it is feasible to build yourself the yaml content from your source data.我确信从源数据中为自己构建 yaml 内容是可行的。 In my case, I built my custom image to run my predictor using Pydantic models , from which you can automatically generate its openapi schema in a json format, which can then be transformed into a yaml file.在我的例子中,我构建了自定义图像以使用Pydantic 模型运行我的预测器,您可以从中自动生成 json 格式的 openapi 模式,然后可以将其转换为 yaml 文件。 Using a different dataset than yours (I'm using the sushi dataset ), my code example is:使用与您不同的数据集(我使用的是sushi 数据集),我的代码示例是:

import yaml
from pydantic import BaseModel, Field


class InstanceModel(BaseModel):
    age: int = Field(..., ge=0, le=5)
    east_west_id_now: int = Field(..., ge=0, le=1)
    east_west_id_until_15yo: int = Field(..., ge=0, le=1)
    gender: int = Field(..., ge=0, le=1)
    prefecture_id_now: int = Field(..., ge=0, le=47)
    prefecture_id_until_15yo: int = Field(..., ge=0, le=47)
    region_id_now: int = Field(..., ge=0, le=11)
    region_id_until_15yo: int = Field(..., ge=0, le=11)
    same_prefecture_id_over_time: int = Field(..., ge=0, le=1)
    time_fill_form: int = Field(..., ge=0)

schema_file_path = "..." #  where you want your yaml file
model_json_string = InstanceModel.schema_json()
model_dict = json.loads(model_json_string)
example = {}
for key in model_dict['properties']:
    example[key] = 0
model_dict['example'] = example
with open(schema_file_path, 'w', encoding='utf8') as f:
    yaml.dump(model_dict, f)

which creates the following:这会创建以下内容:

example:
  age: 0
  east_west_id_now: 0
  east_west_id_until_15yo: 0
  gender: 0
  prefecture_id_now: 0
  prefecture_id_until_15yo: 0
  region_id_now: 0
  region_id_until_15yo: 0
  same_prefecture_id_over_time: 0
  time_fill_form: 0
properties:
  age:
    maximum: 5
    minimum: 0
    title: Age
    type: integer
  east_west_id_now:
    maximum: 1
    minimum: 0
    title: East West Id Now
    type: integer
  east_west_id_until_15yo:
    maximum: 1
    minimum: 0
    title: East West Id Until 15Yo
    type: integer
  gender:
    maximum: 1
    minimum: 0
    title: Gender
    type: integer
  prefecture_id_now:
    maximum: 47
    minimum: 0
    title: Prefecture Id Now
    type: integer
  prefecture_id_until_15yo:
    maximum: 47
    minimum: 0
    title: Prefecture Id Until 15Yo
    type: integer
  region_id_now:
    maximum: 11
    minimum: 0
    title: Region Id Now
    type: integer
  region_id_until_15yo:
    maximum: 11
    minimum: 0
    title: Region Id Until 15Yo
    type: integer
  same_prefecture_id_over_time:
    maximum: 1
    minimum: 0
    title: Same Prefecture Id Over Time
    type: integer
  time_fill_form:
    minimum: 0
    title: Time Fill Form
    type: integer
required:
- age
- east_west_id_now
- east_west_id_until_15yo
- gender
- prefecture_id_now
- prefecture_id_until_15yo
- region_id_now
- region_id_until_15yo
- same_prefecture_id_over_time
- time_fill_form
title: InstanceModel
type: object

Now my issue is that I have no clue where it is actually used... I cannot see it in the model version/details/request example from the console... so I may have done something wrong after that lol.现在我的问题是我不知道它实际在哪里使用...我在控制台的 model 版本/详细信息/请求示例中看不到它...所以在那之后我可能做错了什么大声笑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Vertex AI(谷歌云平台)中使用 model 进行预测 - Using model for prediction in Vertex AI (Google Cloud Platform) 将 spaCy model 训练为 Vertex AI 管道“组件” - Training spaCy model as a Vertex AI Pipeline "Component" 在 Google Cloud Vertex AI 上部署客户处理程序 - Deployment with customer handler on Google Cloud Vertex AI Google Vertex AI 预测:为什么 TorchServe 显示 0 个 GPU? - Google Vertex AI Prediction: Why is TorchServe showing 0 GPUs? Vertex AI管道中DeployModelRequest中的deployed_model应该使用什么? - What should be used for deployed_model in DeployModelRequest in Vertex AI pipeline? Google Cloud Platform - 使用自定义数据格式进行 Vertex AI 训练 - Google Cloud Platform - Vertex AI training with custom data format 从 Vertex AI 和谷歌云存储读取文件 - Reading File from Vertex AI and Google Cloud Storage 使用自定义训练容器和 model 服务容器构建 Vertex AI 管道 - Constructing a Vertex AI Pipeline with a custom training container and a model serving container 如何在 Vertex AI 管道中获取 model id? - How do I get a model id in a a Vertex AI pipeline? 谷歌云顶点 AI 工作台笔记本卡在“启动” - Google cloud vertex AI workbench notebook stuck on "starting"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM