Skip to content

Commit

Permalink
feat: Add model path validation and error handling (v0.7.0)
Browse files Browse the repository at this point in the history
- Validate model path in `init_model`
- Check model download in `download_model`
- Enhance exception handling
  • Loading branch information
CharlesCNorton committed Jul 31, 2024
1 parent d89b3aa commit 21f0b77
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='yoflo',
version='0.6.0',
version='0.7.0',
packages=find_packages(),
include_package_data=True,
install_requires=[
Expand Down
16 changes: 14 additions & 2 deletions yoflo/yoflo.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,26 @@ def download_model(self):
snapshot_download(
repo_id="microsoft/Florence-2-base-ft", local_dir=local_model_dir
)

if not os.path.exists(local_model_dir):
logging.error(
f"Model download failed, directory {os.path.abspath(local_model_dir)} does not exist."
)
return False
if not os.path.isdir(local_model_dir):
logging.error(
f"Model download failed, path {os.path.abspath(local_model_dir)} is not a directory."
)
return False
logging.info(
f"Model and associated files downloaded and initialized at {os.path.abspath(local_model_dir)}"
)
self.init_model(local_model_dir)
return True
except OSError as e:
logging.error(f"OS error during model download: {e}")
except Exception as e:
logging.error(f"Error downloading model: {e}")
return False

def start_webcam_detection(self):
"""Start separate threads for each specified webcam or RTSP stream."""
Expand Down Expand Up @@ -684,7 +695,8 @@ def main():
rtsp_urls=rtsp_urls,
record=args.record
)
yo_flo.download_model()
if not yo_flo.download_model():
return
else:
if not os.path.exists(args.model_path):
logging.error(f"Model path {args.model_path} does not exist.")
Expand Down

0 comments on commit 21f0b77

Please sign in to comment.