- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我已经定义了一个名为 CapsuleLayer
的自定义层。实际模型已在单独的类中定义。我已将权重加载到实际模型中,并将模型保存在 .h5
文件中。但是,当我尝试使用 load_model(filepath)
加载模型时,出现错误
ValueError: Unknown layer: CapsuleLayer
如何在加载保存的模型时将自定义层合并到我的模型中。
最佳答案
比照Keras 常见问题解答,"Handling custom layers (or other custom objects) in saved models" :
If the model you want to load includes custom layers or other custom classes or functions, you can pass them to the loading mechanism via the custom_objects argument:
from keras.models import load_model
# Assuming your model includes instance of an "AttentionLayer" class
model = load_model('my_model.h5', custom_objects={'AttentionLayer': AttentionLayer})Alternatively, you can use a custom object scope:
from keras.utils import CustomObjectScope
with CustomObjectScope({'AttentionLayer': AttentionLayer}):
model = load_model('my_model.h5')Custom objects handling works the same way for load_model, model_from_json, model_from_yaml:
from keras.models import model_from_json
model = model_from_json(json_string, custom_objects={'AttentionLayer': AttentionLayer})
在您的情况下,model = load_model('my_model.h5', custom_objects={'CapsuleLayer': CapsuleLayer})
应该可以解决您的问题。
关于python - 值错误 : Unknown layer: CapsuleLayer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50837728/
我是 Keras 新手,我正在尝试获取 Keras 中的权重。我知道如何在 Python 中的 Tensorflow 中执行此操作。 代码: data = np.array(attributes, '
我正在尝试为上下文强盗问题 (https://medium.com/emergent-future/simple-reinforcement-learning-with-tensorflow-part
我尝试在单击时向 map 添加新标记,并尝试保存标题和描述以在标记悬停时显示,但出现以下错误: Cannot read property 'add Layer' of undefined Javasc
我想要一个传单图层控件,我可以在其中选择一个基础图层,并使这个基础图层本身成为一个 LayerGroup,我可以从中选择要显示的子图层。我正在考虑一个设置,我单击一个单选按钮来选择基础层(层组),然后
我在 GIMP Script-fu 和过程浏览器中遇到了一个简单的问题。 我正在尝试在具有 40 层的图像中向上/向下移动一个层。让我们调用图像 test.xcf 和所述层 Chromask-snap
我有一个(非常大的)脚本在 InDesign 中运行,该脚本在某一时刻将库资源放置到页面上,然后将其移动到特定图层。此脚本在我们这里的所有计算机上都运行良好,但仅当当时 InDesign 中没有打开其
在一些使用 tf2 的 Tensorflow 教程(例如 Neural Machine Translation with Attention 和 Eager essentials )中,他们定义了自定
现在我无法解决依赖性,怎么了? 公司会更改名称吗?但是,我在他们的网站上看到它,但没有“com.layer.atlas:layer-atlas”,但是我的应用程序包含此依赖项,谁能告诉我原因? 最佳答
我使用 Keras 并尝试将两个不同的层连接成一个向量(向量的第一个值是第一层的值,另一部分是第二层的值)。 其中一层是密集层,另一层是嵌入层。 我知道如何合并两个嵌入层或两个密集层,但我不知道如何合
我正在开发一个类来创建各种对称 AE。我现在把这个类移植到TF 2.0,比我想象的要复杂。但是,我使用层和模型的子类来实现此目的。因此,我想将多个 keras 层分组为一个 keras 层。但如果我想
我正在为 CAGradient 设置动画 let gradientChangeAnimation = CABasicAnimation(keyPath: "colors") gradientC
什么是使用 OOP 在业务逻辑对象和数据库之间分层的良好设计? 最佳答案 这些中的任何一个都可以( from Fowler's POEAA ): 数据源架构模式: 表数据网关:充当数据库表网关的对象。
我正在尝试将一些 UIImages 渲染成一张我可以保存在我的相册中的图像。但是好像 layer.renderInContext 没有考虑图层蒙版? 当前行为:照片保存,我看到了 mosaicLaye
哇,这完全令人困惑,而且 dojo 1.8 文档似乎是围绕构建层的完整 clusterf**k。有人知道那里发生了什么吗? 在构建脚本示例配置文件中,示例 amd.profile.js 有 profi
我的 spacemacs 是 0.200.3@25.1.1 每次启动spacemacs时都会收到警告,如何解决? Warnings: - dotspacemacs-configuration-laye
引用是这样的: There's no problem in Computer Science that can't be solved by adding another layer of abstr
我正在使用 Keras 并且有一个自定义层,但是当我使用它时,会发生以下错误,我不知道问题是什么。你能帮我解决这个问题吗?奇怪的是,当我在另一个系统上使用相同的代码时,没有出现此错误! import
我应该什么时候使用 Input我什么时候应该使用 InputLayer ?在 source code有一个描述,但我不确定它是什么意思。 输入层: Layer to be used as an ent
我正在尝试构建一个可以在音频和视频样本上进行训练的模型,但出现此错误 ValueError:请使用“Layer”实例初始化“TimeDistributed”层。您传递了:Tensor("input_1
我正在实现一个需要支持 mask 的自定义 tf.keras.layers.Layer。 考虑以下场景 embedded = tf.keras.layer.Embedding(input_dim=vo
我是一名优秀的程序员,十分优秀!