首页 > 解决方案 > 如何将我的 auto ml python 客户端连接到我的应用程序以进行推理?

问题描述

我使用 google cloud auto ml 训练了一个模型。然后我开始使用 streamlit 构建一个应用程序,该应用程序可以使用 Google AutoML 提供的 python 客户端代码进行预测。但我得到了错误ValueError: Protocol message FieldDescriptorProto has no "proto3_optional" field

下面是代码片段

 uploaded_file = st.file_uploader("Choose an image...", type="jpg")
if uploaded_file is not None:
    image = Image.open(uploaded_file)
    st.image(image, caption='Uploaded Image.', use_column_width=True)
    st.write("")
    st.write("Classifying...")

    from google.cloud import automl_v1beta1
    from google.cloud import service_pb2
    from google.cloud import vision
    from google.cloud.vision import types
    import base64
    from google.cloud import automl


def list_model_evaluations(project_id, model_id):
    from google.cloud import automl
    project_id = "xxxx"
    model_id = "xxxx"

    client = automl.AutoMlClient()
    model_full_id = client.model_path(project_id, "us-central1", model_id)

    print("List of model evaluations:")
    for evaluation in client.list_model_evaluations(parent=model_full_id, filter=""):
        print("Model evaluation name: {}".format(evaluation.name))
        print(
            "Model annotation spec id: {}".format(
                evaluation.annotation_spec_id
            )
        )
        print("Create Time: {}".format(evaluation.create_time))
        print(
            "Evaluation example count: {}".format(
                evaluation.evaluated_example_count
            )
        )

        print(
            "Classification model evaluation metrics: {}".format(
                evaluation.classification_evaluation_metrics
            )
        )

帮助将不胜感激。

标签: pythongoogle-api-python-clientgoogle-cloud-automlstreamlit

解决方案


可能你有一些依赖不兼容,这在 protobuf 中似乎很常见。我认为您的 requirements.txt 文件(或您拥有的任何依赖项文件)中有类似 'protobuf==xx.yy.zz' 的内容 - 您能否将其换成 'protobuf'。


推荐阅读