是否可以使用多个输入定义TensorFlow图?
例如,我想给图形提供两个图像和一个文本,每个图像都由一堆层处理,最后是fc层。然后有一个计算有损函数的节点,该节点考虑了三种表示形式。目的是考虑到联合表示有损,让这三个网络反向传播。
可能吗?任何例子/教程吗?
提前致谢!

最佳答案

这完全是直截了当的事情。对于“一个输入”,您将具有以下内容:

def build_column(x, input_size):

    w = tf.Variable(tf.random_normal([input_size, 20]))
    b = tf.Variable(tf.random_normal([20]))
    processing1 = tf.nn.sigmoid(tf.matmul(x, w) + b)

    w = tf.Variable(tf.random_normal([20, 3]))
    b = tf.Variable(tf.random_normal([3]))
    return tf.nn.sigmoid(tf.matmul(processing1, w) + b)

input1 = tf.placeholder(tf.float32, [None, 2])
output1 = build_column(input1, 2) # 2-20-3 network


您可以简单地添加更多此类“列”,并在需要时将其合并

input1 = tf.placeholder(tf.float32, [None, 2])
output1 = build_column(input1, 2)

input2 = tf.placeholder(tf.float32, [None, 10])
output2 = build_column(input1, 10)

input3 = tf.placeholder(tf.float32, [None, 5])
output3 = build_column(input1, 5)


whole_model = output1 + output2 + output3 # since they are all the same size


您将获得如下所示的网络:

 2-20-3\
        \
10-20-3--SUM (dimension-wise)
        /
 5-20-3/


或进行单值输出

w1 = tf.Variable(tf.random_normal([3, 1]))
w2 = tf.Variable(tf.random_normal([3, 1]))
w3 = tf.Variable(tf.random_normal([3, 1]))

whole_model = tf.matmul(output1, w1) + tf.matmul(output2, w2) + tf.matmul(output3, w3)


要得到

 2-20-3\
        \
10-20-3--1---
        /
 5-20-3/

08-25 05:46