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

[BUG]: 'NS2Trainer' object has no attribute '_count_parameters' #182

Open
a897456 opened this issue Apr 13, 2024 · 14 comments
Open

[BUG]: 'NS2Trainer' object has no attribute '_count_parameters' #182

a897456 opened this issue Apr 13, 2024 · 14 comments
Assignees
Labels
bug Something isn't working

Comments

@a897456
Copy link

a897456 commented Apr 13, 2024

self.logger.info(
f"Model parameters: {self._count_parameters(self.model)/1e6:.2f}M"
)

Traceback (most recent call last):
File "E:\00\Amphion-main_old\bins\tts\train.py", line 130, in
main()
File "E:\00\Amphion-main_old\bins\tts\train.py", line 104, in main
trainer = build_trainer(args, cfg)
File "E:\00\Amphion-main_old\bins\tts\train.py", line 26, in build_trainer
trainer = trainer_class(args, cfg)#NS2Trainer
File "E:\00\Amphion-main_old\models\tts\naturalspeech2\ns2_trainer.py", line 135, in init
f"Model parameters: {self._count_parameters(self.model)/1e6:.2f}M"
AttributeError: 'NS2Trainer' object has no attribute '_count_parameters'

@a897456 a897456 added the bug Something isn't working label Apr 13, 2024
@a897456
Copy link
Author

a897456 commented Apr 13, 2024

"read_metadata": true,

I think it is false.

@netagl
Copy link

netagl commented Apr 14, 2024

I changes the __count_parameters(model) in TTSTrainer class, to _count_parameters(model)
@a897456

@a897456
Copy link
Author

a897456 commented Apr 14, 2024

I changes the __count_parameters(model) in TTSTrainer class, to _count_parameters(model) @a897456

Yes, _dump_cfg is also.
And do you ever met : FileNotFoundError: [Errno 2] No such file or directory: 'data\libritts\code\19\train-clean-100#19#198#19_198_000004_000000.npy' in there:

if self.cfg.preprocess.read_metadata:
metadata_uid_path = os.path.join(
self.cfg.preprocess.processed_dir,
self.cfg.preprocess.metadata_dir,
dataset,
# utt_info["speaker"],
uid + ".pkl",
)
with open(metadata_uid_path, "rb") as f:
metadata_uid = pickle.load(f)

@netagl
Copy link

netagl commented Apr 14, 2024

yes, also _dump_cfg.

yeah. @a897456
I changed self.cfg.preprocess.read_metadata: to False, and used acoustic_extractor to create this files:

            # code
            code = np.load(self.utt2code_path[utt])
            # frame_nums
            frame_nums = code.shape[1]
            # pitch
            pitch = np.load(self.utt2pitch_path[utt])
            # duration
            duration = np.load(self.utt2duration_path[utt])
            # phone_id
            phone_id = np.array(
                [
                    *map(
                        self.phone2id.get,
                        self.utt2phone[utt].replace("{", "").replace("}", "").split(),
                    )
                ]
            )

@a897456
Copy link
Author

a897456 commented Apr 15, 2024

yeah. @a897456 I changed self.cfg.preprocess.read_metadata: to False, and used acoustic_extractor to create this files:

used acoustic_extractor to create this files?
How?

            # code
            code = np.load(self.utt2code_path[utt])
            # frame_nums
            frame_nums = code.shape[1]
            # pitch
            pitch = np.load(self.utt2pitch_path[utt])
            # duration
            duration = np.load(self.utt2duration_path[utt])
            # phone_id
            phone_id = np.array(
                [
                    *map(
                        self.phone2id.get,
                        self.utt2phone[utt].replace("{", "").replace("}", "").split(),
                    )
                ]
            )

This is the code in which part of if self.cfg.preprocess.read_metadata is false, so can you show the code of how use acoustic_extractor to create this files?

@netagl
Copy link

netagl commented Apr 15, 2024

code:

        if cfg.preprocess.extract_acoustic_token:
            print('extract_acoustic_token')
            if cfg.preprocess.acoustic_token_extractor == "Encodec":
                codes = extract_encodec_token(wav_path)
                save_feature(
                    dataset_output, cfg.preprocess.acoustic_token_dir, uid, codes
                )

pitch:

        if cfg.preprocess.extract_pitch:
            pitch = f0.get_f0(wav, cfg.preprocess)
            save_feature(dataset_output, cfg.preprocess.pitch_dir, uid, pitch)

            if cfg.preprocess.extract_uv:
                assert isinstance(pitch, np.ndarray)
                uv = pitch != 0
                save_feature(dataset_output, cfg.preprocess.uv_dir, uid, uv)

phones:

from g2p_en import G2p
preprocess_english(res["Text"], lexicon, g2p)

@a897456

@a897456
Copy link
Author

a897456 commented Apr 15, 2024

THS,but :AttributeError: 'list' object has no attribute 'replace'

# phone_id
phone_id = np.array(
[
*map(
self.phone2id.get,
self.utt2phone[utt].replace("{", "").replace("}", "").split(),
)

@netaglazer
Copy link

netaglazer commented Apr 15, 2024

Set True in cfg
@a897456

      assert cfg.preprocess.use_phone == True
        if cfg.preprocess.use_phone:
            self.utt2phone = {}
            for utt_info in self.metadata:
                dataset = utt_info["Dataset"]
                uid = utt_info["Uid"]
                utt = "{}_{}".format(dataset, uid)
                self.utt2phone[utt] = utt_info["phones"]

@a897456
Copy link
Author

a897456 commented Apr 15, 2024

Set True in cfg @a897456

      assert cfg.preprocess.use_phone == True
        if cfg.preprocess.use_phone:
            self.utt2phone = {}
            for utt_info in self.metadata:
                dataset = utt_info["Dataset"]
                uid = utt_info["Uid"]
                utt = "{}_{}".format(dataset, uid)
                self.utt2phone[utt] = utt_info["phones"]

Yes, and I changed the phone_id =...
phone_id = np.array( [ *map( self.phone2id.get, self.utt2phone[utt].replace("{", "").replace("}", "").split(), ) ] )

@a897456
Copy link
Author

a897456 commented Apr 15, 2024

phone_nums = len(phone_id)
clip_phone_nums = np.random.randint(
int(phone_nums * 0.1), int(phone_nums * 0.5) + 1
)
clip_phone_nums = max(clip_phone_nums, 1)
assert clip_phone_nums < phone_nums and clip_phone_nums >= 1

in this code:
phone_nums =len(phone_id)=len(tensor(1,X))=1, so phone_nums always=1
because: phone_id = torch.from_numpy(phone_id).unsqueeze(0)
so clip_phone_nums=1
but assert clip_phone_nums < phone_nums and clip_phone_nums >= 1
How to solve it,please?

1 similar comment
@a897456
Copy link
Author

a897456 commented Apr 15, 2024

phone_nums = len(phone_id)
clip_phone_nums = np.random.randint(
int(phone_nums * 0.1), int(phone_nums * 0.5) + 1
)
clip_phone_nums = max(clip_phone_nums, 1)
assert clip_phone_nums < phone_nums and clip_phone_nums >= 1

in this code:
phone_nums =len(phone_id)=len(tensor(1,X))=1, so phone_nums always=1
because: phone_id = torch.from_numpy(phone_id).unsqueeze(0)
so clip_phone_nums=1
but assert clip_phone_nums < phone_nums and clip_phone_nums >= 1
How to solve it,please?

@CreepJoye
Copy link

Hi,@a897456
I meet the same problem and can't fix it,have you solved the problem?
Any advice will be appreciated!!!

@a897456
Copy link
Author

a897456 commented May 27, 2024

Hi,@a897456 I meet the same problem and can't fix it,have you solved the problem? Any advice will be appreciated!!!

我在群里看到你问了,这个BUG作者应该还没修复。

@CreepJoye
Copy link

Hi,@a897456 I meet the same problem and can't fix it,have you solved the problem? Any advice will be appreciated!!!

我在群里看到你问了,这个BUG作者应该还没修复。
方便的话可以在群里加个微信吗,想交流学习一下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants