TypeError: predict() takes from 1 to 2 positional arguments but 4 were given, google cloud shell
TypeError: predict() takes from 1 to 2 positional arguments but 4 were given, google cloud shell
我正在尝试 运行 我的多标签文本分类预测模型,但出现以下错误消息:
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
我对 google 给你的默认代码做了一些小改动:
...: 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
错误是无法识别位置参数。只需添加每个参数的名称。您可以查看predict reference.
中的参数
request = prediction_client.predict(name=model_name, payload=payload, params=params)
我正在尝试 运行 我的多标签文本分类预测模型,但出现以下错误消息:
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
我对 google 给你的默认代码做了一些小改动:
...: 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
错误是无法识别位置参数。只需添加每个参数的名称。您可以查看predict reference.
中的参数request = prediction_client.predict(name=model_name, payload=payload, params=params)