0

我有一个经过训练没有任何问题的 seq2seq 网络(一个类)。我在那个类中只有一个构造函数和一个转发函数。

在测试期间,我正在加载模型状态并尝试调用执行测试但出现以下错误的测试函数。

if model.config.model == 'LSTM':
  File "/if5/wua4nw/anaconda3/lib/python3.5/site-packages/torch/nn/modules/module.py", line 237, in __getattr__
    return object.__getattr__(self, name)
AttributeError: type object 'object' has no attribute '__getattr__'

我在做什么:

model = Sequence2Sequence(dictionary, embeddings_index, args.max_length, args)
if args.cuda:
    model = torch.nn.DataParallel(model).cuda()
helper.load_model_states(model, filename)
test(model, input_sentence)

当程序尝试执行最后一行时,会产生上述错误。知道为什么它不起作用吗?

model.test功能:

if model.config.model == 'LSTM':
    encoder_hidden, encoder_cell = model.encoder.init_weights(batch_sentence.size(0))
    output, hidden = model.encoder(batch_sentence, (encoder_hidden, encoder_cell))
else:
    encoder_hidden = model.encoder.init_weights(batch_sentence.size(0))
    output, hidden = model.encoder(batch_sentence, encoder_hidden)

# rest of the code goes here...
4

0 回答 0