from threading import Thread
def model_training():
global status
for i in range(1, 11):
status = i
sleep(1)
@app.route('/retrain/', methods=['GET', 'POST'])
def retrain():
for th in threading.enumerate():
if th.name == "training":
print("Thread still running")
message = "Training is in already in progress"
break
else:
print("Starting a new job thread")
message = "Training started"
t1 = Thread(target=model_training, name="training")
t1.start()
return render_template('retrain.html', message=message, models=model_files, num_images=id)
I am trying to use threading in flask to train a model in parallel. Above is the sample code of what I am trying to do. With model_training()
called in thread returns a status as its in a far loop and works fine as expected. But, I would like to train a model by using model_train()
(below code). In this case it doesn't run in parallel. It waits for the model to complete all epochs.
def model_train():
dataset, model_config, label_mapping = load_config()
print("Training: start.")
model = model_config.model
model.fit()
print("Training: end.")
Can someone guide me to a right direction? Am I missing something here? Thanks in advance