SyntaxError: invalid syntax

class net(nn.Module):
  def __init__(self):
    super().__init__()
    self.l1=nn.Linear(200,200)
    self.b1=nn.BatchNorm1d(200)
    self.d1=nn.Dropout(p=.3)
    self.l2=nn.Linear(200,200)
    self.b2=nn.BatchNorm1d(200)
    self.d2=nn.Dropout(p=.3)
    
    self.l3=nn.Linear(200,100)
    self.b3=nn.BatchNorm1d(100)
    self.d3=nn.Dropout(p=.3)
    self.l4=nn.Linear(100,100)
    self.b4=nn.BatchNorm1d(100)
    self.d4=nn.Dropout(p=.3)
    
    self.l5=nn.Linear(100,50)
    self.b5=nn.BatchNorm1d(50)
    self.d5=nn.Dropout(p=.3)
    self.l6=nn.Linear(50,50)
    self.b6=nn.BatchNorm1d(50)
    self.d6=nn.Dropout(p=.3)
    
    self.l7=nn.Linear(50,10)
    
  def forward(self,x):
    x200=self.d2(self.b2(F.relu(self.l2(self.d1(self.b1(F.relu(self.l1(x)))))))+x
    
    x100=F.relu(self.l3(x200))
    
    x100x=self.b4(self.d4(F.relu(self.l4(self.b3(self.d3(x100)))))+x100
    
    x50=F.relu(self.l5(x100x))
    
    x50_=self.b6(self.d6(F.relu(self.l5(self.b5(self.d5(x50)))))+x50
    
    x10=F.relu(self.l7(x50_))
    
    return x10
File "<ipython-input-14-8f4102c2f059>", line 30
    x100=F.relu(self.l3(x200))
       ^
SyntaxError: invalid syntax

how to fix it?strong text

Some closing parentheses are missing.
Also, you are reusing self.l5, which should probably be self.l6 for the calculation of x50_.
This code should work:

  def forward(self,x):
    x200=self.d2(self.b2(F.relu(self.l2(self.d1(self.b1(F.relu(self.l1(x))))))))+x
    
    x100=F.relu(self.l3(x200))
    
    x100x=self.b4(self.d4(F.relu(self.l4(self.b3(self.d3(x100))))))+x100
    
    x50=F.relu(self.l5(x100x))
    
    x50_=self.b6(self.d6(F.relu(self.l6(self.b5(self.d5(x50))))))+x50
    
    x10=F.relu(self.l7(x50_))
    
    return x10

PS: I’ve formatted your code so that I could easily copy it. You can add code snippets using three backticks ``` :wink:

1 Like

you are awosome… thanks

1 Like

Class NN:
def__intit__(self,numIn,numOut,setWeights):
self.inp = [N(‘inp’) for i in range(numIn)]
self.out = [N(‘out’) for i on range(numOut)]
self.hid = [N(‘hid’), N(‘hid’),N(‘hid’) ]
self.setWeights = setWeights
self.score = 0
self.fitness = 0.0

def rollWeights(self):
    nodes = []
    for n in self.inp:
        nodes.append(n)
    for n in self.hid:
        nodes.append(n)
    for n in seld.out:
        nodes.append(n)
    weightList =[]
    for n in nodes:
        for w in n.weights:
            weightList.append(w)
    return  weightList

def unrollWeights(self,node,weightList):
    for c in node.connectBack:
        node.weights,append(weightsList[0])
        weightList.pop(0)

Class NN:
      ^

SyntaxError: invalid syntax

Class NN: is invalid as the class type uses lowercase letters.