Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(hash_checkpoint): create the directory if not exist #2273

Merged
merged 6 commits into from
Oct 18, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions ignite/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,11 @@ def hash_checkpoint(checkpoint_path: Union[str, Path], output_dir: Union[str, Pa

Args:
checkpoint_path: Path to the checkpoint file.
output_dir: Output directory to store the hashed checkpoint file.
output_dir: Output directory to store the hashed checkpoint file
(will be created if not exist).

Returns:
Path to the hashed checkpoint file, The 8 digits of SHA256 hash.
Path to the hashed checkpoint file, the first 8 digits of SHA256 hash.

.. versionadded:: 0.5.0
"""
Expand All @@ -305,6 +306,7 @@ def hash_checkpoint(checkpoint_path: Union[str, Path], output_dir: Union[str, Pa

if isinstance(output_dir, str):
output_dir = Path(output_dir)
output_dir.mkdir(parents=True, exist_ok=True)

sha_hash = hashlib.sha256(checkpoint_path.read_bytes()).hexdigest()
ydcjeff marked this conversation as resolved.
Show resolved Hide resolved
old_filename = checkpoint_path.stem
Expand Down