How to create a network with multiple forward routines

Hi,

I would do the following:

class H:
  def __init__(self, *args):
    # init H

  def forward(self, inp):
    # forward of H
    return out

class G:
  def __init__(self, *args):
    # init G

  def forward(self, inp):
    # forward of G
    return out

class F:
  def __init__(self, *args):
    # init F
    self.g = G()
    self.h = H()

  def forward(self, inp):
    # forward of F
    return self.g(self.h(inp))

model = F()

# forward the whole model
model(inp)

# foward only g
model.g(inp)
# get only g's parameters
model.g.paremeters()

# foward only h
model.h(inp)

4 Likes