so far wrote mlp,rnn , cnn in keras+tf pytorch gaining popularity inside deep learning communities , started learn framework. biggest fan of sequential models of keras allow make simple models fast. seen pytorch has functionality dont know how code one. tried way
import torch import torch.nn nn net = nn.sequential() net.add(nn.linear(3, 4)) net.add(nn.sigmoid()) net.add(nn.linear(4, 1)) net.add(nn.sigmoid()) net.float() print(net)
but giving error.
attributeerror: 'sequential' object has no attribute 'add'
also if possible can give simple examples rnn , cnn models in pytorch sequenctial model.
sequential
not have add
method @ moment, though there debate adding functionality.
as can read in documentation nn.sequential
takes argument layers separeted sequence of arguments or ordereddict
.
if have model lots of layers, can create list first , use *
operator expand list positional arguments, this:
layers = [] layers.append(nn.linear(3, 4)) layers.append(nn.sigmoid()) layers.append(nn.linear(4, 1)) layers.append(nn.sigmoid()) net = nn.sequential(*layers)
this result in similar structure of code, adding directly.
Comments
Post a Comment