()
| 126 | |
| 127 | |
| 128 | def load_flowsep(): |
| 129 | global _flowsep_model, _flowsep_preprocessor |
| 130 | device = get_runtime_device() |
| 131 | if _flowsep_model is not None: |
| 132 | _flowsep_model = _flowsep_model.to(device).eval() |
| 133 | return _flowsep_model, _flowsep_preprocessor |
| 134 | |
| 135 | seed_everything(0) |
| 136 | from latent_diffusion.util import instantiate_from_config |
| 137 | |
| 138 | config_file = hf_hub_download(repo_id="ShandaAI/FlowSep-hive", filename="config.yaml") |
| 139 | model_file = hf_hub_download(repo_id="ShandaAI/FlowSep-hive", filename="flowsep_hive.ckpt") |
| 140 | |
| 141 | configs = yaml.load(open(config_file, 'r'), Loader=yaml.FullLoader) |
| 142 | configs["model"]["params"]["first_stage_config"]["params"]["reload_from_ckpt"] = None |
| 143 | |
| 144 | preprocessor = FlowSepPreprocessor(configs) |
| 145 | |
| 146 | model = instantiate_from_config(configs["model"]).to(device) |
| 147 | try: |
| 148 | ckpt = torch.load(model_file, map_location=device, weights_only=False)["state_dict"] |
| 149 | except TypeError: |
| 150 | ckpt = torch.load(model_file, map_location=device)["state_dict"] |
| 151 | model.load_state_dict(ckpt, strict=True) |
| 152 | model.eval() |
| 153 | |
| 154 | _flowsep_model = model |
| 155 | _flowsep_preprocessor = preprocessor |
| 156 | return model, preprocessor |
| 157 | |
| 158 | |
| 159 | AUDIOSEP_SR = 32000 |
no test coverage detected