2016-10-29 3 views
6

두 개 이상의 입력이있는 TensorFlow 그래프를 정의 할 수 있습니까? 예를 들어, 그래프에 두 개의 이미지와 텍스트를 제공하고 싶습니다. 각 이미지는 끝에 fc 레이어가있는 레이어 묶음으로 처리됩니다. 그런 다음 세 가지 표현을 고려한 손실 함수를 계산하는 노드가 있습니다. 목표는 3 개의 그물을 공동 표현의 손실을 고려하여 역 전파하도록하는 것입니다. 가능합니까? 그것에 대한 모든 예제/튜토리얼? 미리 감사드립니다. !텐서 흐름을 사용하여 다중 입력 그래프를 작성하는 방법은 무엇입니까?

답변

9

이것은 완전히 직선적 인 것입니다. "하나 개의 입력"을 위해 당신은 같은 것이다 :

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(x, 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) 
,691,363 이 2 년 전이지만210

나는 윈의 실행에 관한 질문이,

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

를 얻을 수 있습니다. 입력이 여러 개인 경우 nn을 실행하려면 어떻게해야합니까? 각각의 입력이 공급되는 단순한 sess.run (옵티 마이저, {input1 : getBatch1, input2 : getBatch2, input3 : getBatch3})입니까? 그리고 최적화 프로그램이 트레이닝되면 TF는 자동으로 다른 감사합니다. – Luna

+0

질문이 있으면 @Luna입니다. 답변에 대한 의견을 게시하는 대신 질문하십시오. – lejlot