首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >typeError:__init__()得到了一个意外的关键字参数'text_len‘

typeError:__init__()得到了一个意外的关键字参数'text_len‘
EN

Stack Overflow用户
提问于 2020-12-12 08:33:17
回答 1查看 1.1K关注 0票数 0

我试着在colab里运行他科隆模型..。

代码语言:javascript
复制
def prepare_dataloaders(hparams):
    # Get data, data loaders and collate function ready
        
    trainset = TextMelLoader(hparams.training_files, hparams)
    valset = TextMelLoader(hparams.validation_files, hparams)
    collate_fn = TextMelCollate(1, text_len = 190, mel_len = 890)

    train_loader = DataLoader(trainset,
                          num_workers=2,
                          sampler=HkSampler(trainset),
                          batch_size=hparams.batch_size,
                          pin_memory=False,
                          drop_last=True,
                          collate_fn=collate_fn)
    return train_loader, valset, collate_fn

class TextMelCollate():
    """ Zero-pads model inputs and targets based on number of frames per setep
    """
    def __init__(self, n_frames_per_step, text_len=20, mel_len=100):
        # we only support one frame per step
        print('we are in TextMelCollage ==> ', text_len)
        assert (n_frames_per_step == 1)
        self.n_frames_per_step = n_frames_per_step
        print(text_len)
        self.text_len = text_len
        self.mel_len = mel_len

    def __call__(self, batch):
        """Collate's training batch from normalized text and mel-spectrogram
        PARAMS
        ------
        batch: [text_normalized, mel_normalized]
        """
        # Right zero-pad all one-hot text sequences to max input length
        text_len = max([len(x[0]) for x in batch]) // 5 * 5 + 5
        self.text_len = max(self.text_len, text_len)

        text_padded = torch.LongTensor(len(batch), self.text_len)
        text_padded.zero_()
        input_lengths = torch.LongTensor([len(x[0]) for x in batch])
        for i in range(len(batch)):
            text = batch[i][0]
            text_padded[i, :text.size(0)] = text

        # Right zero-pad mel-spec
        num_mels = batch[0][1].size(0)
        mel_len = max([x[1].size(1) for x in batch]) // 5 * 5 + 5
        self.mel_len = max(self.mel_len, mel_len)

        # include mel padded and gate padded
        mel_padded = torch.FloatTensor(len(batch), num_mels, self.mel_len)
        mel_padded.zero_()
        gate_padded = torch.FloatTensor(len(batch), self.mel_len)
        gate_padded.zero_()
        output_lengths = torch.LongTensor(len(batch))
        for i in range(len(batch)):
            mel = batch[i][1]
            mel_padded[i, :, :mel.size(1)] = mel
            gate_padded[i, mel.size(1) - 1:] = 1
            output_lengths[i] = mel.size(1)

        return text_padded, input_lengths, mel_padded, gate_padded, \
            output_lengths

但我的错误如下所示

init of TextMelCollate中,text_len是int类型。

我不知道为什么会出现类型错误。

您可以在colab中运行此代码。

https://colab.research.google.com/drive/1XU4SWsybhuUYqooyLcFHXmyX3pOOWJON#scrollTo=UxGBm1FdJhlW&uniqifier=2

%tensorflow_versiononly switches the major version: 1.x or 2.x.<br> You set:1.15. This will be interpreted as: 1.x‘. 选择TensorFlow 1.x。 tpu后端: grpc://10.92.95.162:8470 grpc://10.92.95.162:8470 解析命令行hparams: batch_size=128 回溯(最近一次调用): 文件"hk_train.py",第220行,在 ( args.warm_start,hparams) 文件"hk_train.py",第116行,在火车上 train_loader,valset,collate_fn = prepare_dataloaders(hparams) 文件"hk_train.py",第56行,prepare_dataloaders collate_fn = TextMelCollate(1,text_len = 190,mel_len = 890) TypeError: init()有一个意外的关键字参数'text_len'

在这里输入图像描述

EN

回答 1

Stack Overflow用户

发布于 2020-12-12 08:41:01

医生们中可以看出,TextMelCollate只接受n_frames_per_step作为初始化参数。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65263017

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档