【问题标题】:R Keras concatenate two neural networkR Keras 连接两个神经网络
【发布时间】:2018-12-03 09:08:22
【问题描述】:

我需要连接两个神经网络,如下图所示。但是,我收到以下错误消息:

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")

【问题讨论】:

  • 首先,尝试将“int32”更改为“float32”。

标签: r neural-network keras lstm


【解决方案1】:

你可以这样做:

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))

This link 也有类似的例子。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-21
    • 1970-01-01
    • 1970-01-01
    • 2017-12-09
    • 1970-01-01
    • 2017-03-17
    • 2020-02-25
    相关资源
    最近更新 更多