热门标签 | HotTags
当前位置:  开发笔记 > 人工智能 > 正文

即使我们不使用model.fit,何时应该继承keras.Model而不是keras.layers.Layer?

如何解决《即使我们不使用model.fit,何时应该继承keras.Model而不是keras.layers.Layer?》经验,需要怎么解决?

在一些使用tf2的Tensorflow教程中(例如,具有Attention和Eager要点的神经机器翻译),它们定义了custom tf.keras.Model而不是tf.keras.layers.Layers(例如BahdanauAttention(tf.keras.Model):

另外,模型:组成层文档tf.keras.Model明确使用。本节说:

创建包含其他图层的类似图层的东西时使用的主要类是tf.keras.Model。通过从tf.keras.Model继承来实现一个。

听起来我们需要继承tf.keras.Model以定义组成子图层的图层。

但是,据我检查,即使我将定义ResnetIdentityBlock为的子类,此代码也可以使用tf.keras.layers.Layer。其他两个教程也可以使用Layer。除此之外,另一个教程说

Model is just like a Layer, but with added training and serialization utilities.

Thus, I have no idea what is the real difference between tf.keras.Model and tf.keras.layers.Layer and why those three tutorial with Eager execution uses tf.keras.Model though they don't use training and serialization utilities of tf.keras.Model.

Why do we need to inherit tf.keras.Model in those tutorials?

Additional comment

utilities of Model work only with special subsets of Layer (Layers whose call receive only one input). Thus, I think the idea like "Always extend Model because Model has more features" is not correct. Also, it violates a basic programming program like SRP.


推荐阅读
author-avatar
禁令2502861143
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有