2016-08-22 83 views
0

我想在连续的张量流中使用两个模型,以适合第一个,并直接使用它作为第二个输入。但我没有找到这样做的好方法。我试图进行如下以下,tensorflow合并输入和输出

x = tf.placeholder('float', shape=[None, image_size[0] , image_size[1]]) 

y1_ = tf.placeholder('float', shape=[None, image_size[0] , image_size[1], 1]) 
y2_ = tf.placeholder('float', shape=[None, image_size[0] , image_size[1],\ 
                   labels_count]) 
image = tf.reshape(x, [-1,image_size[0] , image_size[1],1]) 
# y1 first output, to fit 
W_conv = weight_variable([1, 1, 1, labels_count]) 
b_conv = bias_variable([labels_count]) 

y1 = conv2d(image, W_conv) + b_conv 

cross_entropy1 = tf.reduce_sum(tf.nn.sigmoid_cross_entropy_with_logits(y1, y1_)) 
train_step1 =\ 
tf.train.GradientDescentOptimizer(LEARNING_RATE).minimize(cross_entropy) 
# Then use as input the folowing 
im_y1 = tf.zeros_initializer([None,image_size[0] , image_size[1],2]) 
im_y1[:,:,:,0]=x 
im_y1[:,:,:,1]=y1 

的事情是减少第一最小化cross_entropy(Y1 y1_)与参数W_conv b_conv然后通过construciting im_y1为描述使用Y1作为参数。

但就像我写的,它的剂量工作,因为tf.zeros_initializer拒绝获得参数无。

在Tensorflow的同一模型中传输不同拟合的好方法是什么?

感谢任何意见!

回答

1

替换为最后三行的例子:

im_y1 = tf.concat(3, [x, y1]) 

它加到xy1沿3挡(0为基础)维。

+0

这完全是我想要的,似乎我在API中看起来不够好,谢谢! –