Unable to upload creme model
kleekaai opened this issue · 1 comments
I have trained a binary classifier on the Spam Dataset and trying to deploy it using Chantilly. First, I load my trained model and upload it using a POST request. But, while doing classifications, the response says there is no "creme_model" model.
import dill
import requests
import os
if __name__ == '__main__':
model_path = './models/creme_model.pkl'
with open(os.path.join(model_path), 'rb') as file:
creme_model = dill.load(file)
url = 'http://localhost:5000'
config = {'flavor': 'binary'}
requests.post(f'{url}/api/init', json=config)
requests.post(f'{url}/api/model', data=dill.dumps(creme_model)) # uploads the model
r = requests.post(f'{url}/api/predict', json={
'id':1,
'model': 'creme_model',
'features':{'title': 'dun say so early hor... U c already then say...'}
})
print(r.json())
r_get_models = requests.get(f'{url}/api/models')
print(r_get_models.json())
r_get_model_metrics = requests.get(f'{url}/api/metrics')
print(r_get_model_metrics.json())
r_get_model_stats = requests.get(f'{url}/api/stats')
print(r_get_model_stats.json())
Output
{'message': "No model named 'creme_model'."}
{'default': 'vacuous-strawberry', 'models': ['vacuous-strawberry', 'cumbersome-passion', 'tedious-watermelon', 'exuberant-strawberry', 'picayune-strawberry', 'spiffy-passion', 'wrathful-papaya', 'diligent-coconut', 'amuck-ratatouille', 'bewildered-watermelon', 'capricious-pear', 'illustrious-cherry', 'hapless-grape', 'abrasive-pineapple', 'direful-banana', 'feeble-quince', 'earthy-pizza', 'noxious-melon', 'momentous-grape']}
{'Accuracy': 0.0, 'F1': 0.0, 'LogLoss': 0.0, 'Precision': 0.0, 'Recall': 0.0}
{'learn': {'ewm_duration': 0, 'ewm_duration_human': '0ns', 'mean_duration': 0, 'mean_duration_human': '0ns', 'n_calls': 0}, 'predict': {'ewm_duration': 921484, 'ewm_duration_human': '921μs484ns', 'mean_duration': 921484, 'mean_duration_human': '921μs484ns', 'n_calls': 1}}
When you upload a model without giving it a name, a default one is chosen for you. In this case, the given name is 'vacuous-strawberry'
. You've specified the 'creme_model'
name in your request to /api/predict
, but that's not correct. Indeed, 'creme_model'
is the name of the model in your script, not on the chantilly server.
You can set your own model name as so:
requests.post(f'{url}/api/model/<insert_name>', data=dill.dumps(creme_model))
Note that the default model is the latest one you have uploaded. Therefore, if you only have one model, you don't have to worry about the name.
Hope this helps.