Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
406 views
in Technique[技术] by (71.8m points)

class - 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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

_call_ is python magic method (or dunder method) which make class objects callable. but on the other hand call is user defined method in Keras which at the background use mentioned _call_ method but before using it this user defined call do some extra things like building weight and bias tensors based on the input tensor shape.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...