AIFSH / ComfyUI-GPT_SoVITS

a comfyui custom node for GPT-SoVITS! you can voice cloning and tts in comfyui now
Other
197 stars 17 forks source link

Can't get attribute 'HParams' on <module 'utils' from 'E:\\ComfyUI-aki-v1.3\\comfy\\utils.py'> #12

Closed niudvb closed 7 months ago

niudvb commented 7 months ago

image E:\ComfyUI-aki-v1.3\input\vocal_man_0.flac_0000000000_0000135680.wav !!! Exception during processing!!! Can't get attribute 'HParams' on <module 'utils' from 'E:\ComfyUI-aki-v1.3\comfy\utils.py'> Traceback (most recent call last): File "E:\ComfyUI-aki-v1.3\execution.py", line 151, in recursive_execute output_data, output_ui = get_output_data(obj, input_data_all) File "E:\ComfyUI-aki-v1.3\execution.py", line 81, in get_output_data return_values = map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True) File "E:\ComfyUI-aki-v1.3\execution.py", line 74, in map_node_over_list results.append(getattr(obj, func)(**slice_dict(input_data_all, i))) File "E:\ComfyUI-aki-v1.3\custom_nodes\ComfyUI-GPT_SoVITS\nodes.py", line 201, in get_tts_wav get_tts_wav(refer_wav,refer_text,prompt_language, File "E:\ComfyUI-aki-v1.3\custom_nodes\ComfyUI-GPT_SoVITS\inference.py", line 128, in get_tts_wav vq_model, hps = change_sovits_weights(sovits_weight) File "E:\ComfyUI-aki-v1.3\custom_nodes\ComfyUI-GPT_SoVITS\inference.py", line 84, in change_sovits_weights dict_s2 = torch.load(sovits_path, map_location="cpu") File "E:\ComfyUI-aki-v1.3\python\lib\site-packages\torch\serialization.py", line 1026, in load return _load(opened_zipfile, File "E:\ComfyUI-aki-v1.3\python\lib\site-packages\torch\serialization.py", line 1438, in _load result = unpickler.load() File "E:\ComfyUI-aki-v1.3\python\lib\site-packages\torch\serialization.py", line 1431, in find_class return super().find_class(mod_name, name) AttributeError: Can't get attribute 'HParams' on <module 'utils' from 'E:\ComfyUI-aki-v1.3\comfy\utils.py'>

请问,这样的错误是什么原因导致的?

AIFSH commented 7 months ago

try Linux or readme Windows

erjihaoshi commented 7 months ago

这个问题是你的soviet模型只保留了权重参数,没有保留图结构,dict_s2 = torch.load(sovits_path, map_location="cpu")在原本的webui中作者写了utils.py函数可以读取这样的模型,而comfyui自带utils.py这个模块,torch_load会去使用comfy的utils.py。 想个办法绕过comfy的utils.py不知道可不可以,大佬能不能解决一下呀?

erjihaoshi commented 7 months ago

class HParams:
    def __init__(self, **kwargs):
        for k, v in kwargs.items():
            if type(v) == dict:
                v = HParams(**v)
            self[k] = v

    def keys(self):
        return self.__dict__.keys()

    def items(self):
        return self.__dict__.items()

    def values(self):
        return self.__dict__.values()

    def __len__(self):
        return len(self.__dict__)

    def __getitem__(self, key):
        return getattr(self, key)

    def __setitem__(self, key, value):
        return setattr(self, key, value)

    def __contains__(self, key):
        return key in self.__dict__

    def __repr__(self):
        return self.__dict__.__repr__()

拷贝到comfy/utils.py末尾就可以了

niudvb commented 7 months ago

class HParams:
    def __init__(self, **kwargs):
        for k, v in kwargs.items():
            if type(v) == dict:
                v = HParams(**v)
            self[k] = v

    def keys(self):
        return self.__dict__.keys()

    def items(self):
        return self.__dict__.items()

    def values(self):
        return self.__dict__.values()

    def __len__(self):
        return len(self.__dict__)

    def __getitem__(self, key):
        return getattr(self, key)

    def __setitem__(self, key, value):
        return setattr(self, key, value)

    def __contains__(self, key):
        return key in self.__dict__

    def __repr__(self):
        return self.__dict__.__repr__()

拷贝到comfy/utils.py末尾就可以了

真的是这个问题,感谢感谢!!!!

AIFSH commented 7 months ago

这个问题是你的soviet模型只保留了权重参数,没有保留图结构,dict_s2 = torch.load(sovits_path, map_location="cpu")在原本的webui中作者写了utils.py函数可以读取这样的模型,而comfyui自带utils.py这个模块,torch_load会去使用comfy的utils.py。 想个办法绕过comfy的utils.py不知道可不可以,大佬能不能解决一下呀?

这个是在用原 gpt_sovits 项目微调的模型才会出现的问题,目前还真只能这样修改

感谢贡献 fix