[英]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:简而言之:
.yaml
..yaml
为后缀。 I do not fully understand why, but it gave me some headaches to find this problem knowing that kfp OutputPath do not suffix the paths... 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.