ai: cache model
This commit is contained in:
parent
fe1dccde17
commit
74809305ae
@ -28,6 +28,9 @@ scans_dir = os.path.join(data_dir, 'scans')
|
||||
|
||||
os.makedirs(local_model_dir, exist_ok=True)
|
||||
|
||||
# Cache for loaded models to avoid reloading on every request
|
||||
_model_cache = {}
|
||||
|
||||
def get_file_md5(fname):
|
||||
return hashlib.md5(open(fname, 'rb').read()).hexdigest()
|
||||
|
||||
@ -85,7 +88,10 @@ def do_qr_verify():
|
||||
fd = flask.request.form
|
||||
model_name = fd.get('model', default_model)
|
||||
model_path, model_md5 = download_model(model_name)
|
||||
model, transforms = load_model(model_path)
|
||||
# Cache models by path to avoid reloading on every request
|
||||
if model_path not in _model_cache:
|
||||
_model_cache[model_path] = load_model(model_path)
|
||||
model, transforms = _model_cache[model_path]
|
||||
|
||||
frame_image, clarities = find_best_frame(flask.request.files)
|
||||
frame_qrcode, _ = extract_qr(frame_image)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user