I am currently trying to deploy my Machine Learning model using BentoML.
I have wrapped my model in a runner using estimator_runner = bentoml.keras.get(BENTO_MODEL_TAG).to_runner()
However, when the service runs estimator_runner.predict(input_data)
the process returns with the error:
"An error has occurred in BentoML user code when handling this request, find the error details in server logs"
The server logs show the following:
return estimator_runner.predict(input_data)
TypeError: 'RunnerMethod' object is not callable
2022-11-23T17:09:47+0100 [INFO] [dev_api_server] 127.0.0.1:60377 (scheme=http,method=POST,path=/predict,type=application/json,length=294) (status=500,type=application/json,length=110) 3.932ms (trace=28b577785679ee4866ff6cbd61589e24,span=722cdd8b6467bfb6,sampled=0)
Sadly I couldn't really find any leads on what can cause this error to happen and how I can potentially fix it. Has anyone run into this before and/or knows what I could do about this?
Edit:
service code:
import numpy as np
import bentoml
from bentoml.io import NumpyNdarray
BENTO_MODEL_TAG = "mmrt_model:p2ya6otlggzx4me4"
estimator_runner = bentoml.keras.get(BENTO_MODEL_TAG).to_runner()
MMRT_service = bentoml.Service("MMRT_Estimator", runners=[estimator_runner])
@MMRT_service.api(input=NumpyNdarray(), output=float)
def predict(input_data: np.ndarray) -> float:
return estimator_runner.predict(input_data)
service request code:
import json
from sys import argv
import numpy as np
import requests
SERVICE_URL = "http://localhost:3000/predict"
def make_request_to_bento_service(service_url: str, input_array: np.ndarray) -> str:
serialized_input_data = json.dumps(input_array.tolist())
response = requests.post(
service_url,
data=serialized_input_data,
headers={"Content-Type": "application/json"}
)
return response.text
def main():
# Read the data from argv as an np.ndarray
input_data = np.array([float(x) for x in argv[1:]])
print(input_data)
prediction = make_request_to_bento_service(SERVICE_URL, input_data)
print(prediction)
if __name__ == "__main__":
main()
Try using
estimator_runner.predict.run(input_data)