AttributeError: 'GraphNetwork' object has no attribute 'layer_number'

I’m trying to load a created GNN model into an RNN controller and train to get the accuracy but when I run the RNN controller code I get this error “AttributeError: ‘GraphNetwork’ object has no attribute ‘layer_number’” even though “layer_number” is defined in the GNN model code. Any ideas on how to solve this will be greatly appreciated. thanks in advance. Below is a part of my GNN code where I’m getting the error.
The error is from this line “resultant_length = self.layer_number * state_number”

class GraphNetwork(torch.nn.Module):

def __init__(self, actions, num_features, num_labels, dropout=0.6, multi_label=False, batch_normal=False,
             residual=False, state_number=5, layer_number=3): #Hidden dimension absent: state number = 5
    
    # parameters => actions:
    # parameters => multi_labels:

    super(GraphNetwork, self).__init__()
    
    # args
    self.num_labels = num_labels
    self.dropout = dropout
    self.multi_label = multi_label
    self.num_features = num_features
    self.residual = residual
    
    # check architecture of GNN
    self.compute_actions(actions, state_number)
    self.layer_number = layer_number
    
    # layer module
    self.construct_model(actions, batch_normal, dropout, num_features, num_labels, state_number)

def construct_model(self, actions, batch_normal, dropout, num_features, num_labels, state_number):
    self.gates = torch.nn.ModuleList()
    self.layers = torch.nn.ModuleList()
    self.prediction = None
    self.construct_hidden_layers(actions, batch_normal, dropout, self.layer_number, num_features, num_labels, state_number)

def compute_actions(self, actions, state_number):
    state_length = len(actions)
    if not self.residual:
        resultant_length = self.layer_number * state_number
    else:
        resultant_length = sum([state_number+i for i in range(1,self.layer_number+1)])
    if state_length != resultant_length:
        raise RuntimeError("False Input : Unmatched input")
    if actions[-1] == self.num_label: #last action number = no. of labels; pass
        pass
    else:
        raise RuntimeError("False architecture") 

Below is the part of my controller code that loads the created GNN.
1

The error is raised, because you are defining self.layer_number after calling self.compute_actions, which already tries to access this attribute.
Move the assignment of self.layer_number before calling compute_actions and it should work.

Thanks @ptrblck
I already replaced that line of code some days back and It worked fine but I have a follow up issue which I will really appreciate if you can assist.

‘Tensor’ object has no attribute ‘initializer’. And it seems there is a Tensor object in tf.local_variables(), and the code initializing it causes the error.

CiteFast

tf.local_variables() seems to be a TensorFlow operation, so I’m unsure where you are seeing this error.