Skip to content

Automatic model weight download using HuggingFace Hub #36

@MihinP

Description

@MihinP

Currently, PartiNet requires users to manually download model weights and specify their path via command-line arguments. This adds friction to the user experience and can be error-prone.

Proposed Enhancement
Implement automatic model weight downloading using the huggingface_hub library, similar to how PyTorch models can be loaded with automatic downloading.

Suggested Implementation

from huggingface_hub import hf_hub_download
def load_partinet_weights(model_type="denoised_micrographs", cache_dir=None):
    """
    Automatically download and load PartiNet weights from HuggingFace Hub.
    
    Args:
        model_type: Either "denoised_micrographs" or "raw_micrographs"
        cache_dir: Optional custom cache directory
    """
    filename = f"{model_type}.pt"
    weight_path = hf_hub_download(
        repo_id="MihinP/PartiNet",
        filename=filename,
        cache_dir=cache_dir
    )
    return torch.load(weight_path)

Backwards Compatibility

Keep existing manual path specification as an option
If no path provided, automatically download from HuggingFace
Add huggingface_hub as a dependency (or optional dependency)

Additional Considerations

Add progress bar for downloads
Handle offline scenarios gracefully
Document the caching behavior for users

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions