源占位符与另一个使用十的占位符

2024-09-28 05:18:22 发布

您现在位置:Python中文网/ 问答频道 /正文

以下情况: 有一个运行TysFoeFund的生产服务器(C++)。那里的代码期望只有一个输入Placeholder,它的输入与feed_dict:{'input':...}相似。我无法更改服务器代码。我只能提供一个新的图,它必须有一个名为input的{}。在

使用tensorflow,我有一些代码可以创建两个范围不同的相同神经网络:

dnn1 = DNN(scope='dnn1')
dnn2 = DNN(scope='dnn2')

两个dnn都有一个输入Placeholder<tf.Tensor 'dnn1/input:0' shape=(50) dtype=float32><tf.Tensor 'dnn2/input:0' shape=(50) dtype=float32>

两个网络应该得到相同的输入。 如何使张量input同时流向图中的dnn1/input和{}?我也不能更改DNN类,所以最后我的图将使用dnn1/inputdnn2/input和{}作为占位符,但是只有{}由生产代码提供。在


Tags: 代码服务器inputtf情况placeholderscopetensor
2条回答

默认情况下,您可以修改DNN占位符以使用生产输入占位符。因此,您仍然可以随时向它们提供自定义值。在

session = tf.Session()
production_input = tf.placeholder(tf.float32, [50])

# Own placeholders
dnn_1_input = tf.placeholder_with_default(production_input, [50])
dnn_2_input = tf.placeholder_with_default(production_input, [50])

# Production environment call
result = session.run([dnn_1_input, dnn_2_input],
                     feed_dict={production_input: np.arange(50)})

创建输入占位符并将其用作两个网络的输入:

例如DNN1: hidden1 = (input * W1) + b1

DNN2型: hidden1 = (input * W1) + b1

你能做到吗?在

相关问题 更多 >

    热门问题