Askar Zhanaliyev
Askar Zhanaliyev

Reputation: 1

AttributeError: 'lstm' object has no attribute 'layers'

I am pretty new to building models and python in general. I was trying to use Ann_visualizer to see my network. Here is how I defined the model (p.s. I have used it from open-source github code for experimentation):

import torch
from torch.optim import Adam
import torch.nn as nn
#lstm model
class lstm(nn.Module):
    def __init__(self, vocab_size, embed_size, hidden_size):
        super().__init__()
        #simple lookup table that stores embeddings of a fixed dictionary and size.
        self.embed = nn.Embedding(vocab_size, embed_size)
        
        #lstm 
        self.lstm = nn.LSTM(embed_size, hidden_size, num_layers=2, bidirectional=False)
        
        #fully connected layer
        self.linear = nn.Linear(hidden_size*seq_length,vocab_size)
    
    def forward(self, input_word):
        #input sequence to embeddings
        embedded = self.embed(input_word)
        
        #passing the embedding to lstm model
        output, hidden = self.lstm(embedded)
        
        #reshaping
        output=output.view(output.size(0), -1)
        
        #fully connected layer
        output = self.linear(output)
        return output,hidden
model=lstm(vocab_size=vocabulary_size,embed_size=128, hidden_size=256)

The model itself worked fine, but later when I want to visualize it running this code

from ann_visualizer.visualize import ann_viz
ann_viz(model, view=True,title="My first neural network")

I get the following error: AttributeError: 'lstm' object has no attribute 'layers'

I can see that when I define lstm class, there are no layers in def_init_ , but still, I lack the skills to resolve this error on my own and wanted some assistance.

Upvotes: 0

Views: 1723

Answers (1)

ki-ljl
ki-ljl

Reputation: 509

As of now, ann_visualizer only supports ANN and CNN, not RNN.

ann_visualizer-github

Upvotes: 1

Related Questions