Leo Chen
08/06/2024, 2:49 AMpydantic_core._pydantic_core.PydanticSerializationError: Unable to serialize unknown type: <class 'numpy.ndarray'>
Traceback (most recent call last):
File "/opt/conda/lib/python3.10/site-packages/_bentoml_impl/server/app.py", line 561, in api_endpoint_wrapper
resp = await self.api_endpoint(name, request)
File "/opt/conda/lib/python3.10/site-packages/_bentoml_impl/server/app.py", line 660, in api_endpoint
response = await method.output_spec.to_http_response(output, serde)
File "/opt/conda/lib/python3.10/site-packages/_bentoml_sdk/io_models.py", line 259, in to_http_response
payload = serde.serialize_model(ins)
File "/opt/conda/lib/python3.10/site-packages/_bentoml_impl/serde.py", line 150, in serialize_model
model.model_dump_json(
File "/opt/conda/lib/python3.10/site-packages/pydantic/main.py", line 415, in model_dump_json
return self.__pydantic_serializer__.to_json(
Could someone explain what this means? I am confused since my output is not a numpy array, it is a list with json format elements in it.
@bentoml.service(
resources={"cpu": "2"},
)
class BentoService:
bento_model_ref = bentoml.models.get("classification-model:latest")
def __init__(self):
self.model = bentoml.mlflow.load_model(self.bento_model_ref)
@bentoml.api
def predict(self, test_data: str) -> list:
test_data_df = pd.read_json(test_data, orient="split")
predictions = self.model.predict(test_data_df)
return predictionsJian Shen Yap
08/06/2024, 9:25 AMLeo Chen
08/06/2024, 9:59 AMJian Shen Yap
08/06/2024, 10:00 AMLeo Chen
08/06/2024, 10:18 AMLeo Chen
08/06/2024, 10:20 AMJian Shen Yap
08/06/2024, 10:33 AMLeo Chen
08/06/2024, 11:01 AMJiang
08/06/2024, 12:50 PMJiang
08/06/2024, 12:51 PM@bentoml.api
def predict(self, test_data: str) -> list:
test_data_df = pd.read_json(test_data, orient="split")
predictions = self.model.predict(test_data_df)
return predictions
Just replace this with
@bentoml.api
def predict(self, test_data: str) -> list:
test_data_df = pd.read_json(test_data, orient="split")
predictions = self.model.predict(test_data_df)
return predictions.tolist()Jiang
08/06/2024, 12:52 PMpredict(self, test_data: str) -> list: told bentoml the return value will be list, but it actually returned a numpy ndarray object.Jiang
08/06/2024, 12:54 PMLeo Chen
08/07/2024, 3:50 AMAttributeError: 'list' object has no attribute 'tolist'
I believe the prediction output is a list.Jiang
08/07/2024, 4:13 AMLeo Chen
08/07/2024, 7:48 AM