How to build a net like this structure in Pytorch?


I want to build a network like this structure, but I just can build unidirectional net. How to deal with this complex item? :cry:

RB has been defined.

You can define a module in this structure

class Net(nn.Module):
    def __init__(self):
        super(Net, self).__init__()
        self.fc0=nn.Linear(...)
        self.fc1=nn.Linear(...)
        self.fc2=nn.Linear(...)
        self.fc3=nn.Linear(...)
        self.Rb0= ...
        self.Rb1= ...
        self.Rb2= ...
        self.Rb3= ...

   def forward(self,x):
        x_1=self.fc0(x)
        x_2=self.fc1(x_1)
        x_3=self.fc2(x_2)
        x_4=self.fc3(x_3)
        
        x_out_1=self.Rb0(x_1)
        x_out_2=self.Rb1(x_2)
        x_out_3=self.Rb2(x_3)
        x_out_4=self.Rb3(x_4)
        ......
        return final_block

Later on you can call this module like this:

model=Net()

Does that solve your problem?

Got it. Thx . :smile: