keras的运行机制

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!


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值