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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
网站不错 人气很旺了 加油
[***.192.178.218]2024年03月30日 23时36分38秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
android学习笔记----简易音乐播放器原理
2019-04-27
Unity编辑器扩展——标签属性Attribute
2019-04-27
Unity中实现拖拽操作
2019-04-27
Unity中的UGUI事件系统
2021-06-30
C#中的常量
2021-06-30
C#中的静态变量与非静态变量
2021-06-30
C#中的ref、out、params关键字
2021-06-30
C#中的多态性
2019-04-27
C#中的命名空间
2019-04-27
设计模式——状态模式
2019-04-27
设计模式——工厂模式
2019-04-27
Unity中实现有限状态机FSM
2019-04-27
Unity中实现反弹
2019-04-27
U3D游戏开发框架(九)——事件序列
2019-04-27
Unity中解决“SetDestination“ can only be called on an active agent that has been placed on a NavMesh
2019-04-27
Unity中的刚体
2019-04-27
Unity中的坐标转换
2019-04-27
Unity中为什么不能对transform.position.x直接赋值?
2019-04-27
Unity中物体移动方法详解
2019-04-27