张量流乘以两层

时间:2020-02-21 01:59:54

标签: tensorflow input tensor

我的网络确实有两个输入。一个输入经过几个线性层,然后应与另一个输入逐个相乘。

    input_a = Input(shape=input_a_shape)
    x = Dense(side_channel_speed_output_dimension, activation="relu")(x)
    x = tf.reshape(x, [input_shape_image[0], input_shape_image[1]])

    x = tf.expand_dims(x, input_shape_image[2])
    x = tf.repeat(x, repeats=input_shape_image[2], axis=2)

    input_b = Input(shape=input_shape_b)

在这个阶段,我想将input_a和input_b相乘。我该怎么办?

我尝试过:

input = keras.layers.multiply([input_b, input_a])

我收到此错误:

ValueError: Graph disconnected: cannot obtain value for tensor Tensor("input_2:0", shape=(None, 60, 40, 2), dtype=float32) at layer "input_2". The following previous layers were accessed without issue: ['input_1', 'dense', 'tf_op_layer_Reshape', 'tf_op_layer_ExpandDims', 'tf_op_layer_Repeat/Shape', 'tf_op_layer_Repeat/strided_slice', 'tf_op_layer_Repeat/strided_slice_1', 'tf_op_layer_Repeat/ExpandDims', 'tf_op_layer_Repeat/Tile', 'tf_op_layer_Repeat/concat']

我也只尝试了tf.multipy(a,b)。也不行。

有人知道如何解决吗? 谢谢

1 个答案:

答案 0 :(得分:0)

我现在明白了。我需要使用此功能:

x = keras.layers.multiply([input_image, x])