keras的运行机制
发布日期:2021-11-21 04:41:34 浏览次数:49 分类:技术文章

本文共 1646 字,大约阅读时间需要 5 分钟。

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

概要

中,如果在创建class的时候写了call()方法, 那么该class实例化出实例后, 实例名()就是调用call()方法。

例子

class Animal(object):    __call__(self, words):        print "Hello: ", wordsif __name__ == "__main__":    cat = Animal()    cat("I am cat!")>>> Hello: I am cat!

转载地址:https://blog.csdn.net/xiaojiajia007/article/details/75331302 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:keras load model 报错
下一篇:生成对抗网络

发表评论

最新留言

网站不错 人气很旺了 加油
[***.192.178.218]2024年03月30日 23时36分38秒