我构建了一个自定义模型,并尝试使用Google管道组件在顶点AI上进行模型评估。根据评量笔记本示例,我需要准备instance_schema.yaml和prediction_schema.yaml来导入非托管模型。
那么如何以编程方式生成实例和预测模式文件呢?
发布于 2022-10-31 19:44:43
对于自定义模型,不需要实例和预测模式:
"predictSchemata": {
"predictionSchemaUri": MODEL_URI + "/prediction_schema.yaml",
"instanceSchemaUri": MODEL_URI + "/instance.yaml",
},发布于 2022-11-11 05:48:08
简言之:
.yaml。我不完全理解为什么,但当我知道kfp OutputPath不以路径为后缀时,发现这个问题让我有些头疼……现在,要以编程方式进行构建,这取决于您的用例和您从何处开始。我确信从源数据构建自己的yaml内容是可行的。在我的例子中,我构建了我的自定义映像来使用勾股模型运行我的预测器,您可以从该映像中自动生成json格式的openapi模式,然后将其转换为yaml文件。使用与您不同的数据集(我使用的是寿司数据集),我的代码示例如下:
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)它创建了以下内容:
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现在我的问题是我不知道它在哪里被使用..。我在控制台的模型版本/详细信息/请求示例中看不到它.所以在那之后我可能做错了什么。
https://stackoverflow.com/questions/73980694
复制相似问题