-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding container to update models on a schedule (#46)
* adding container to update models on a schedule * Automatically reformatting code with black and isort * dockerfile * clean up * update deployment * udpate images * Automatically reformatting code with black and isort * update cicd * clean up * pr feedback * reorganize stuff * update image * try/except block * dict method error solved * new image * Automatically reformatting code with black and isort * remove unnecessary change * error log if refresh rates are different * update image --------- Co-authored-by: Auto-format Bot <autoformatbot@groundlight.ai>
- Loading branch information
1 parent
3affb15
commit 9e32f1f
Showing
8 changed files
with
78 additions
and
27 deletions.
There are no files selected for viewing
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
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
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
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
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
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import os | ||
import logging | ||
import time | ||
from app.core.app_state import load_edge_config | ||
from app.core.configs import RootEdgeConfig | ||
from app.core.edge_inference import EdgeInferenceManager | ||
|
||
log_level = os.environ.get("LOG_LEVEL", "INFO").upper() | ||
logging.basicConfig(level=log_level) | ||
|
||
|
||
def update_models(edge_inference_manager: EdgeInferenceManager): | ||
if not os.environ.get("DEPLOY_DETECTOR_LEVEL_INFERENCE", None) or not edge_inference_manager.inference_config: | ||
return | ||
|
||
inference_config = edge_inference_manager.inference_config | ||
|
||
# All detectors should have the same refresh rate. | ||
refresh_rates = [config.refresh_rate for config in inference_config.values()] | ||
if set(refresh_rates) != 1: | ||
logging.error(f"Detectors have different refresh rates.") | ||
|
||
refresh_rate = refresh_rates[0] | ||
|
||
while True: | ||
for detector_id, config in inference_config.items(): | ||
if config.enabled: | ||
try: | ||
edge_inference_manager.update_model(detector_id=detector_id) | ||
except Exception as e: | ||
logging.error(f"Failed to update model for {detector_id}. {e}", exc_info=True) | ||
|
||
time.sleep(refresh_rate) | ||
|
||
|
||
if __name__ == "__main__": | ||
edge_config: RootEdgeConfig = load_edge_config() | ||
edge_inference_templates = edge_config.local_inference_templates | ||
inference_config = { | ||
detector.detector_id: edge_inference_templates[detector.local_inference_template] | ||
for detector in edge_config.detectors | ||
} | ||
edge_inference_manager = EdgeInferenceManager(config=inference_config, verbose=True) | ||
|
||
update_models(edge_inference_manager=edge_inference_manager) |
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