|
|
|
@ -3996,7 +3996,7 @@ class Program(object):
|
|
|
|
|
with static.program_guard(main_program=main_program, startup_program=startup_program):
|
|
|
|
|
x = static.data(name="x", shape=[-1, 784], dtype='float32')
|
|
|
|
|
y = static.data(name="y", shape=[-1, 1], dtype='int32')
|
|
|
|
|
z = static.nn.fc(name="fc", input=x, size=10, act="relu")
|
|
|
|
|
z = static.nn.fc(name="fc", x=x, size=10, activation="relu")
|
|
|
|
|
|
|
|
|
|
print("main program is: {}".format(main_program))
|
|
|
|
|
print("start up program is: {}".format(startup_program))
|
|
|
|
@ -4344,7 +4344,7 @@ class Program(object):
|
|
|
|
|
paddle.enable_static()
|
|
|
|
|
|
|
|
|
|
img = static.data(name='image', shape=[None, 784])
|
|
|
|
|
pred = static.nn.fc(input=img, size=10, act='relu')
|
|
|
|
|
pred = static.nn.fc(x=img, size=10, actvation='relu')
|
|
|
|
|
loss = paddle.mean(pred)
|
|
|
|
|
# Here we use clone before Momentum
|
|
|
|
|
test_program = static.default_main_program().clone(for_test=True)
|
|
|
|
@ -4415,10 +4415,10 @@ class Program(object):
|
|
|
|
|
with static.program_guard(train_program, startup_program):
|
|
|
|
|
with utils.unique_name.guard():
|
|
|
|
|
img = static.data(name='image', shape=[None, 784])
|
|
|
|
|
hidden = static.nn.fc(input=img, size=200, act='relu')
|
|
|
|
|
hidden = static.nn.fc(x=img, size=200, activation='relu')
|
|
|
|
|
hidden = F.dropout(hidden, p=0.5)
|
|
|
|
|
loss = F.cross_entropy(
|
|
|
|
|
input=static.nn.fc(hidden, size=10, act='softmax'),
|
|
|
|
|
input=static.nn.fc(x=hidden, size=10, activation='softmax'),
|
|
|
|
|
label=static.data(name='label', shape=[1], dtype='int64'))
|
|
|
|
|
avg_loss = paddle.mean(loss)
|
|
|
|
|
test_program = train_program.clone(for_test=True)
|
|
|
|
@ -4462,10 +4462,10 @@ class Program(object):
|
|
|
|
|
|
|
|
|
|
def network():
|
|
|
|
|
img = static.data(name='image', shape=[None, 784])
|
|
|
|
|
hidden = static.nn.fc(input=img, size=200, act='relu')
|
|
|
|
|
hidden = static.nn.fc(x=img, size=200, activation='relu')
|
|
|
|
|
hidden = F.dropout(hidden, p=0.5)
|
|
|
|
|
loss = F.cross_entropy(
|
|
|
|
|
input=static.nn.fc(hidden, size=10, act='softmax'),
|
|
|
|
|
input=static.nn.fc(x=hidden, size=10, activation='softmax'),
|
|
|
|
|
label=static.data(name='label', shape=[1], dtype='int64'))
|
|
|
|
|
avg_loss = paddle.mean(loss)
|
|
|
|
|
return avg_loss
|
|
|
|
@ -5079,7 +5079,7 @@ class Program(object):
|
|
|
|
|
|
|
|
|
|
program = static.default_main_program()
|
|
|
|
|
data = static.data(name='x', shape=[None, 13], dtype='float32')
|
|
|
|
|
hidden = static.nn.fc(input=data, size=10)
|
|
|
|
|
hidden = static.nn.fc(x=data, size=10)
|
|
|
|
|
loss = paddle.mean(hidden)
|
|
|
|
|
paddle.optimizer.SGD(learning_rate=0.01).minimize(loss)
|
|
|
|
|
|
|
|
|
@ -5347,7 +5347,7 @@ def default_startup_program():
|
|
|
|
|
with paddle.static.program_guard(main_program=main_program, startup_program=startup_program):
|
|
|
|
|
x = paddle.data(name="x", shape=[-1, 784], dtype='float32')
|
|
|
|
|
y = paddle.data(name="y", shape=[-1, 1], dtype='int32')
|
|
|
|
|
z = paddle.static.nn.fc(name="fc", input=x, size=10, act="relu")
|
|
|
|
|
z = paddle.static.nn.fc(name="fc", x=x, size=10, activation="relu")
|
|
|
|
|
|
|
|
|
|
print("main program is: {}".format(paddle.static.default_main_program()))
|
|
|
|
|
print("start up program is: {}".format(paddle.static.default_startup_program()))
|
|
|
|
@ -5389,8 +5389,8 @@ def default_main_program():
|
|
|
|
|
bn2 = paddle.static.nn.batch_norm(conv2, act='relu')
|
|
|
|
|
pool2 = paddle.nn.functional.pool2d(bn2, 2, 'max', 2)
|
|
|
|
|
|
|
|
|
|
fc1 = paddle.static.nn.fc(pool2, size=50, act='relu')
|
|
|
|
|
fc2 = paddle.static.nn.fc(fc1, size=102, act='softmax')
|
|
|
|
|
fc1 = paddle.static.nn.fc(x=pool2, size=50, activation='relu')
|
|
|
|
|
fc2 = paddle.static.nn.fc(x=fc1, size=102, activation='softmax')
|
|
|
|
|
|
|
|
|
|
loss = paddle.nn.functional.loss.cross_entropy(input=fc2, label=label)
|
|
|
|
|
loss = paddle.mean(loss)
|
|
|
|
@ -5467,7 +5467,7 @@ def program_guard(main_program, startup_program=None):
|
|
|
|
|
startup_program = paddle.static.Program()
|
|
|
|
|
with paddle.static.program_guard(main_program, startup_program):
|
|
|
|
|
data = paddle.static.data(name='image', shape=[None, 784, 784], dtype='float32')
|
|
|
|
|
hidden = paddle.static.nn.fc(input=data, size=10, act='relu')
|
|
|
|
|
hidden = paddle.static.nn.fc(x=data, size=10, activation='relu')
|
|
|
|
|
|
|
|
|
|
Notes: The temporary :code:`Program` can be used if the user does not need
|
|
|
|
|
to construct either of startup program or main program.
|
|
|
|
|