Created
March 3, 2019 15:49
-
-
Save jrzaurin/8870c74a00eecda9430618129c4cf0fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def start(model_id, messages_count, batch_id): | |
for msg in consumer: | |
message = json.loads(msg.value) | |
if is_retraining_message(msg): | |
model_fname = 'model_{}_.p'.format(model_id) | |
model = reload_model(MODELS_PATH/model_fname) | |
print("NEW MODEL RELOADED {}".format(model_id)) | |
elif is_application_message(msg): | |
request_id = message['request_id'] | |
pred = predict(message['data'], column_order) | |
publish_prediction(pred, request_id) | |
append_message(message['data'], MESSAGES_PATH, batch_id) | |
messages_count += 1 | |
if messages_count % RETRAIN_EVERY == 0: | |
model_id = (model_id + 1) % (EXTRA_MODELS_TO_KEEP + 1) | |
send_retrain_message(model_id, batch_id) | |
batch_id += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment