【问题标题】:How to view the functionality of concatenate in Keras?如何在 Keras 中查看 concatenate 的功能?
【发布时间】:2020-06-21 22:36:13
【问题描述】:

我正在查看 keras 合并层 (https://keras.io/layers/merge/),并想了解每个层操作的执行情况。我想它们的功能相当直观,但我想弄清楚如何查看给定示例的输出。

为了说明我的意思,我有两个形状为 (1,10) 的随机输入的数组,并且想看看如果我要连接这两个数组,输出会是什么。但是,当我执行以下操作时,出现以下错误:Layer concatenate_18 was called with an input that isn't a symbolic tensor. Received type: <class 'numpy.ndarray'>...All inputs to the layer should be tensors.

from keras.layers import concatenate
data1 = np.random.normal(0, 1, size = (1, 10))
data2 = np.random.normal(0, 1, size = (1, 10))
concatenation = concatenate([data1, data2])
print(concatenation) # I want to print the output of concatenating data1 and data2

根据该消息,我假设此错误与输入是 numpy 数组这一事实有关,但我不确定应该采用什么适当的格式?如何查看在示例中使用 concatenate 的输出?谢谢!

【问题讨论】:

    标签: python numpy keras concatenation tensor


    【解决方案1】:

    我想我想出了如何做到这一点。我使用的数据与我上面描述的不同,但应该实现相同的行为。看起来我需要指定输入张量,实例化模型,并对数据调用预测。

    input1 = Input(shape=(3,))
    input2 = Input(shape=(3,))
    merge = concatenate([input1, input2])
    model = Model([input1, input2], merge)
    
    a = np.array([[1,1,1]])
    b = np.array([[1,1,1]])
    model.predict([a,b])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-31
      • 1970-01-01
      • 1970-01-01
      • 2023-03-09
      • 2021-11-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多