def get_model(model_name): if model_name not in MODEL_CACHE: print("Recreating the %r model in cache" % model_name) try: model = load_model(model_name) except FileNotFoundError: if ALLOW_MISSING_MODELS: print( "Missing %r model, skipping because ALLOW_MISSING_MODELS is set" % model_name ) return None else: raise # Cache the model only if it was last used less than two hours ago. if model_name in MODEL_LAST_LOADED and MODEL_LAST_LOADED[ model_name ] > datetime.now() - relativedelta(hours=2): MODEL_CACHE[model_name] = model else: model = MODEL_CACHE[model_name] MODEL_LAST_LOADED[model_name] = datetime.now() return model
def get_model(model_name): if model_name not in MODEL_CACHE: print("Recreating the model in cache") model = load_model(model_name, MODELS_DIR) MODEL_CACHE[model_name] = model return model return MODEL_CACHE[model_name]
def go(self, model_name): should_download_model = bool(os.getenv("SHOULD_DOWNLOAD_MODEL")) download_url = os.getenv("MODEL_DOWNLOAD_URL") if should_download_model and download_url: download_url = download_model(download_url, f"{model_name}model") # Load the model model = load_model(model_name) # Then call the check method of the model success = model.check() if not success: msg = f"Check of model {model.__class__!r} failed, check the output for reasons why" logger.warning(msg) sys.exit(1)
def get_model(model_name): if model_name not in MODEL_CACHE: print("Recreating the %r model in cache" % model_name) try: model = load_model(model_name, MODELS_DIR) except FileNotFoundError: if ALLOW_MISSING_MODELS: print( "Missing %r model, skipping because ALLOW_MISSING_MODELS is set" % model_name) return None else: raise MODEL_CACHE[model_name] = model return model return MODEL_CACHE[model_name]