如何将我的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
            )
        )

我们将不胜感激。

解决方法

可能您的依赖项不兼容,这在protobuf中似乎很常见。我假设您的requirements.txt文件(或任何具有依赖项的文件)中都有类似“ protobuf == xx.yy.zz”的内容-您可以将其替换为“ protobuf”吗?