r - R Keras 连接两个神经网络
问题描述
我需要连接两个神经网络,如下图所示。但是,我收到以下错误消息:
Op 的 float32 类型与参数的 int32 类型不匹配
如何连接两个网络?
源代码:
layer1 <- layer_input(shape = c(MAX), dtype = "int32")
output_tensor <- layer1 %>%
layer_dense(units = 32, activation = "relu") %>%
layer_dense(units = 32, activation = "relu")
解决方案
你可以这样做:
library(keras)
max_words <- 20
nb_words <- 1000
text_one_hot <- layer_input(nb_words)
text_as_int <- layer_input(max_words)
vec_1 <- text_one_hot %>%
layer_dense(100)
vec_2 <- layer_embedding(
input_dim = nb_words, output_dim = 128,
input_length = max_words
) %>%
layer_lstm(128)
out <- layer_concatenate(list(vect_1, vec_2))
model <- keras_model(list(input_1, input_2))
这个链接有一个类似的例子。
推荐阅读
- c# - 在 C# WPF 中读取 CSV 文件
- jquery - 获取“ReadMore”脚本以使用段落(
) 文本
- .net - 如何在 WinUI 3 中使用 DrawingVisual 类?
- c# - 世界空间拖放中的 UI 与鼠标不对齐
- javascript - 如何将历史记录从我们打开的选项卡复制到新打开的选项卡?[Javascript,反应]
- javascript - 在本机反应中设置状态会冻结应用程序
- javascript - 如何从 JSON 数据中获取站点名称数据
- python - 除非输入搜索查询,否则隐藏 Django admin 中的所有记录
- python - 传递值的形状与使用 init 函数的索引不同
- python - 如何检查 asyncio.wait 后完成了什么协程