A
A
Asya2020-06-03 12:11:48
Python
Asya, 2020-06-03 12:11:48

How to correctly run a pretrained model with pytorch?

I want to use the pretrained model from here

, but I get this error:

Missing key(s) in state_dict: "gru_1.weight_ih_l1", "gru_1.weight_hh_l1", "gru_1.bias_ih_l1", "gru_1.bias_hh_l1", "gru_1.weight_ih_l2", "gru_1.weight_hh_l2", "gru_1.bias_ih_l2", "gru_1.bias_hh_l2". 
Unexpected key(s) in state_dict: "gru_2.weight_ih_l0", "gru_2.weight_hh_l0", "gru_2.bias_ih_l0", "gru_2.bias_hh_l0", "gru_3.weight_ih_l0", "gru_3.weight_hh_l0", "gru_3.bias_ih_l0", "gru_3.bias_hh_l0".


when I try
decoder = MolDecoder(c=len(charset))
    # decoder = WrappedModel(decoder)
    decoder.apply(initialize_weights)
    checkpoint = torch.load('./ref/ref_model.pth.tar',  map_location={"cuda:0" : "cpu"})
    decoder.load_state_dict(checkpoint['decoder'])


class MolDecoder(nn.Module):

    def __init__(self, i=292, o=120, c=35):
        super(MolDecoder, self).__init__()

        self.latent_input = nn.Sequential(nn.Linear(i, i),
                                          SELU(inplace=True))
        self.repeat_vector = Repeat(o)
        self.gru_1 = nn.GRU(i, 501, 3, batch_first=True)
        # self.gru_2 = nn.GRU(501, 501, 3, batch_first=True)
        # self.gru_3 = nn.GRU(501, 501, 3, batch_first=True)
        self.decoded_mean = TimeDistributed(nn.Sequential(nn.Linear(501, 55), nn.Softmax()))

    def forward(self, x):
        out = self.latent_input(x)
        out = self.repeat_vector(out)
        out, h = self.gru_1(out)
        return self.decoded_mean(out)


How to fix? run on cpu

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question