多program互相影响的问题
Created by: shuoyin
hi 我下边这个程序,定义了两个Program,分别在两个Program里定义了一个FC层,名字相同但是输出不同。我理解这两个program里的变量应该是互相不影响的,所以两个program的输出应该也是不同的(虽然他们名字一样),但是实际输出并不是。
import paddle.fluid as fluid
import numpy as np
prog1 = fluid.Program()
start_prog1 = fluid.Program()
with fluid.program_guard(prog1, start_prog1):
with fluid.unique_name.guard():
x = fluid.layers.data(name='x', shape=[-1, 4], dtype='float32')
y1 = fluid.layers.fc(x, size=1)
prog2 = fluid.Program()
start_prog2 = fluid.Program()
with fluid.program_guard(prog2, start_prog2):
with fluid.unique_name.guard():
x = fluid.layers.data(name='x', shape=[-1, 4], dtype='float32')
y2 = fluid.layers.fc(x, size=2)
place = fluid.CPUPlace()
exe = fluid.Executor(place)
exe.run(start_prog1)
exe.run(start_prog2)
feed_x = np.random.rand(3,4).astype('float32')
print feed_x
print exe.run(prog1, feed={'x':feed_x}, fetch_list=[y1])[0]
print exe.run(prog2, feed={'x':feed_x}, fetch_list=[y2])[0]
输出如下:
[[0.15301736 0.47217232 0.43869737 0.00271489]
[0.4223052 0.5610767 0.5118477 0.180553 ]
[0.0171026 0.61575365 0.324812 0.45415097]]
[[-0.45586294 0.14294818]
[-0.71337724 0.3381655 ]
[-0.23540677 0.6197809 ]]
[[-0.45586294 0.14294818]
[-0.71337724 0.3381655 ]
[-0.23540677 0.6197809 ]]
看起来prog2把prog1覆盖了。请问这是什么情况,要怎么解决使得两个program各自分别输出互不影响啊 谢谢