garmentiq.segmentation.model_definition.birefnet.load_birefnet_config

 1import os
 2import json
 3from .BiRefNet_config import BiRefNetConfig
 4
 5def load_birefnet_config():
 6    """
 7    Reads and loads the bundled configuration for the BiRefNet model.
 8
 9    This function facilitates strictly offline initialization by dynamically locating the 
10    `config.json` file associated with BiRefNet within the local package directory. It 
11    securely reads the local JSON file and unpacks its contents directly into a Hugging Face 
12    `BiRefNetConfig` object, ensuring the package remains completely air-gapped and independent 
13    of external network requests.
14
15    Raises:
16        FileNotFoundError: If the corresponding offline `config.json` file cannot be located 
17                           in the module directory.
18
19    Returns:
20        BiRefNetConfig: The loaded configuration object ready to be passed into the model loader.
21    """
22    # Locate the directory this specific python file lives in
23    current_dir = os.path.dirname(os.path.abspath(__file__))
24    config_path = os.path.join(current_dir, "config.json")
25    
26    # Read the local json securely
27    with open(config_path, 'r') as f:
28        config_dict = json.load(f)
29        
30    # Unpack the dictionary directly into the Config class
31    return BiRefNetConfig(**config_dict)
32
33__all__ = ["load_birefnet_config"]
def load_birefnet_config():
 6def load_birefnet_config():
 7    """
 8    Reads and loads the bundled configuration for the BiRefNet model.
 9
10    This function facilitates strictly offline initialization by dynamically locating the 
11    `config.json` file associated with BiRefNet within the local package directory. It 
12    securely reads the local JSON file and unpacks its contents directly into a Hugging Face 
13    `BiRefNetConfig` object, ensuring the package remains completely air-gapped and independent 
14    of external network requests.
15
16    Raises:
17        FileNotFoundError: If the corresponding offline `config.json` file cannot be located 
18                           in the module directory.
19
20    Returns:
21        BiRefNetConfig: The loaded configuration object ready to be passed into the model loader.
22    """
23    # Locate the directory this specific python file lives in
24    current_dir = os.path.dirname(os.path.abspath(__file__))
25    config_path = os.path.join(current_dir, "config.json")
26    
27    # Read the local json securely
28    with open(config_path, 'r') as f:
29        config_dict = json.load(f)
30        
31    # Unpack the dictionary directly into the Config class
32    return BiRefNetConfig(**config_dict)

Reads and loads the bundled configuration for the BiRefNet model.

This function facilitates strictly offline initialization by dynamically locating the config.json file associated with BiRefNet within the local package directory. It securely reads the local JSON file and unpacks its contents directly into a Hugging Face BiRefNetConfig object, ensuring the package remains completely air-gapped and independent of external network requests.

Raises:
  • FileNotFoundError: If the corresponding offline config.json file cannot be located in the module directory.
Returns:

BiRefNetConfig: The loaded configuration object ready to be passed into the model loader.