---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
D:\Temp\ipykernel_6580\3729707838.py in <module>
9 num_layers, dropout)
10 net = d2l.EncoderDecoder(encoder, decoder)
---> 11 d2l.train_seq2seq(net, train_iter, lr, num_epochs, tgt_vocab, device)
12
13
~\AppData\Roaming\Python\Python37\site-packages\d2l\torch.py in train_seq2seq(net, data_iter, lr, num_epochs, tgt_vocab, device)
1032 if "weight" in param:
1033 nn.init.xavier_uniform_(m._parameters[param])
-> 1034 net.apply(xavier_init_weights)
1035 net.to(device)
1036 optimizer = torch.optim.Adam(net.parameters(), lr=lr)
~\AppData\Roaming\Python\Python37\site-packages\torch\nn\modules\module.py in apply(self, fn)
~\AppData\Roaming\Python\Python37\site-packages\torch\nn\modules\module.py in apply(self, fn)
~\AppData\Roaming\Python\Python37\site-packages\torch\nn\modules\module.py in apply(self, fn)
~\AppData\Roaming\Python\Python37\site-packages\d2l\torch.py in xavier_init_weights(m)
1029 nn.init.xavier_uniform_(m.weight)
1030 if type(m) == nn.GRU:
-> 1031 for param in m._flat_weights_names:
1032 if "weight" in param:
1033 nn.init.xavier_uniform_(m._parameters[param])
~\AppData\Roaming\Python\Python37\site-packages\torch\nn\modules\module.py in __getattr__(self, name)
属性错误:“GRU”对象没有属性“_flat_weights_names”
属性错误:'GRU'对象没有属性'_flat_weights_names'如何修复?
1条答案
按热度按时间bpzcxfmw1#
代替
type(m) == nn.GRU
尝试
isinstance(m, nn.GRU)