1.keras tensor计算的举例说明:
maxpool = MaxPool2D((2, 2))(input)
首先
MaxPool2D((2, 2))
是将MaxPool2D class实例化, (2, 2)是class中def __init__()(也可能是通过super方法引用基类Layer class中的初始化方法__init__) 初始化方法(method)的实参,实例化之后, input(keras tensor)作为class中__call__()方法(从Layer class继承,并且在实例化的时候被自动调用)的实参,被进行计算,并且返回output tensor
def __call__(self, inputs, **kwargs):# Layer class(object)的函数
"""Wrapper around self.call(), for handling internal references.
If a Keras tensor is passed:
- We call self._add_inbound_node().
- If necessary, we `build` the layer to match
the _keras_shape of the input(s).
- We update the _keras_shape of every input tensor with
its new shape (obtained via self.compute_output_shape).
This is done as part of _add_inbound_node().
- We update the _keras_history of the output tensor(s)
with the current layer.
This is done as part of _add_inbound_node().
# Arguments
inputs: Can be a tensor or list/tuple of tensors.
**kwargs: Additional keyword arguments to be passed to `call()`.
# Returns
Output of the layer's `call` method.
# Raises
ValueError: in case the layer is missing shape information
for its `build` call.
"""
python中的特殊函数call : http://blog.csdn.net/autoliuweijie/article/details/50469007
概要
Python中,如果在创建class的时候写了call()方法, 那么该class实例化出实例后, 实例名()就是调用call()方法。
例子
class Animal(object):
__call__(self, words):
print "Hello: ", words
if __name__ == "__main__":
cat = Animal()
cat("I am cat!")
>>> Hello: I am cat!