【问题标题】:TypeError: predict() takes from 1 to 2 positional arguments but 4 were given, google cloud shellTypeError: predict() 接受 1 到 2 个位置参数,但给出了 4 个,google cloud shell
【发布时间】:2021-05-20 22:27:39
【问题描述】:

我正在尝试运行我的多标签文本分类预测模型,但出现以下错误消息:

TypeError                                 Traceback (most recent call last)
<ipython-input-6-8eeb93c56258> in <module>
----> 1 predecir('Message', 'project name' )
<ipython-input-5-c6a4555e1b30> in predecir(content, model_name)
     25 def predecir(content, model_name):
     26
---> 27   print(get_prediction(content, model_name))
     28
<ipython-input-5-c6a4555e1b30> i
     20
     21   params = {}
---> 22   request = prediction_client.predict(model_name, payload, params)
     23   return request  # waits until request is returned
     24
TypeError: predict() takes from 1 to 2 positional arguments but 4 were given

我对谷歌给你的默认代码做了一些小改动:

   ...: from google.api_core.client_options import ClientOptions
   ...: from google.cloud import automl_v1
   ...: # from google.cloud.automl_v1.proto import service_pb2
   ...: 
   ...: def inline_text_payload(content):
   ...:   return {'text_snippet': {'content': content, 'mime_type': 'text/plain'} }
   ...: 
   ...: def pdf_payload(file_path):
   ...:   return {'document': {'input_config': {'gcs_source': {'input_uris': [file_path] } } } }
   ...: 
   ...: def get_prediction(content, model_name):
   ...:   options = ClientOptions(api_endpoint='automl.googleapis.com')
   ...:   prediction_client = automl_v1.PredictionServiceClient(client_options=options)
   ...: 
   ...:   payload = inline_text_payload(content)
   ...:   # Uncomment the following line (and comment the above line) if want to predict on PDFs.
   ...:   # payload = pdf_payload(file_path)
   ...: 
   ...:   params = {}
   ...:   request = prediction_client.predict(model_name, payload, params)
   ...:   return request  # waits until request is returned
   ...: 
   ...: def predecir(content, model_name):
   ...: 
   ...:   print(get_prediction(content, model_name))

我尝试安装以前版本的 google-cloud-automl 但没有解决方案。

我正在使用的当前版本是:

google-api-core==1.26.0
google-cloud-automl==2.1.0

【问题讨论】:

    标签: python-3.x google-cloud-platform google-cloud-automl


    【解决方案1】:

    错误是无法识别位置参数。只需添加每个参数的名称。您可以查看predict reference中的参数。

    request = prediction_client.predict(name=model_name, payload=payload, params=params)
    

    【讨论】:

      猜你喜欢
      • 2019-04-29
      • 1970-01-01
      • 1970-01-01
      • 2019-12-07
      • 2017-09-06
      • 1970-01-01
      • 2017-01-12
      • 2017-04-22
      • 2019-07-07
      相关资源
      最近更新 更多