Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between call() and __call__() method in python?

In the tensorflow documentation I see the call() method defined when subclassing activations and models. However, in case of subclassing regularizers, initializers and constraints, they define the __class__() method instead.

When playing around with both, I could not find any differences myself.

Could someone tell me what the difference is?

like image 880
tijmenvanetten Avatar asked Mar 20 '26 22:03

tijmenvanetten


1 Answers

__call__ is a python magic method (or dunder method) that makes class objects callable. but on the other hand call is a user-defined method in Keras which in the background uses mentioned __call__ method but before using it this user-defined call does some extra things like building weight and bias tensors based on the input tensor shape.

like image 86
d4riush Avatar answered Mar 22 '26 13:03

d4riush



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!