Skip to content Skip to sidebar Skip to footer

Calling Forward Function Without .forward()

While looking at some pytorch code on pose estimation AlphaPose I noticed some unfamiliar syntax: Basically, we define a Darknet class which inherits nn.Module properties like so:

Solution 1:

This is nothing torch specific. When you call something as class_object(fn params) it invokes the __call__ method of that class.

If you dig the code of torch, specifically nn.Module you will see that __call__ internally invokes forward but taking care of hooks and states that pytorch allows. So when you are calling self.det_model(img, cuda) you are still calling forward.

See the code for nn.module here.

Post a Comment for "Calling Forward Function Without .forward()"