Accessing output after activation function

def __init__(self ):

super().__init__()

self.seq_model = nn.Sequential(nn.Linear(2, 2),

nn.Sigmoid(),

nn.Linear(2, 4),

nn.Sigmoid(),

nn.Linear(4,1),

nn.Softmax())

How can I access the values directly after the first sigmoid() function? we can access the parameters w, b, but please tell me to how to know the values after 1st layer after the activation function

1 Like

Hi @Prasad,
In that case, you need not use nn.sequential(). You can do it the other way by just simply calling each of the functions separately, and storing the returned value in a temporary variable.
This temporary variable containing returned value from sigmoid can then be used.

1 Like

Can you please explain by example,

def __init__(self):

super(FizBuzNet, self).__init__()

self.hidden = nn.Linear(1, 2)

self.active= nn.Sigmoid()

self.out = nn.Linear(2, 4)

def forward(self, x):

out = self.out(self.active(self.hidden(x)))

return out

Can above way we access the sigmoid output.?

p=FizBuzNet().active

print § # printing P

then it shows Sigmoid(), Not values of Sigmoid() function

You can do the following:

def forward(self, x):
    active = self.active(self.hidden(x))
    out = self.out(self.active)
    return active, out

active, _ = FizBuzNet()
print(active)
1 Like

Thanks.

its working.

Instead

def forward(self, x):

active = self.active(self.hidden(x))

out = self.out(active) # we can write active directly instead of self.active

return active, out

1 Like

Yes, my bad… :slight_smile: