在GAN培训后更改区分层

时间:2019-12-27 13:37:07

标签: python machine-learning deep-learning pytorch generative-adversarial-network

我为Discriminator类编写了以下代码:

class Discriminator_lang(nn.Module):
    def __init__(self, n_chars, seq_len, batch_size, hidden):
        super(Discriminator_lang, self).__init__()
        self.n_chars = n_chars
        self.seq_len = seq_len
        self.batch_size = batch_size
        self.hidden = hidden
        self.block = nn.Sequential(
            ResBlockD(hidden),
            ResBlockD(hidden),
            ResBlockD(hidden),
            ResBlockD(hidden),
            ResBlockD(hidden),
            ResBlockD(hidden),
        )
        self.conv1d = nn.Conv1d(n_chars, hidden, 1)
        self.linear = nn.Linear(seq_len*hidden, 1)

训练结束后,我保存重量。现在,我想通过将线性层替换为新的S型层来重新加载鉴别器,而先前的层保持冻结状态。我已经编写了以下代码:

for param in modelDisc.parameters():
        param.requires_grad = False
        features = list(modelDisc.children())[:-1]
        features.extend([nn.MaxPool2d(5)])
        features.extend([nn.Sigmoid()])
        modelloaded = nn.Sequential(*features)

但是它给出了以下错误:

  

RuntimeError:给定组= 1,权重大小为128 512 5,预期输入[32、160、22]具有512个通道,但改为有160个通道

0 个答案:

没有答案