default_main_program

paddle.fluid.default_main_program()[source]

This API can be used to get default main program which store the descriptions of op and variable.

For example z = fluid.layers.elementwise_add(x, y) will create a new elementwise_add op and a new z variable, and they will be recorded in default main program

The default_main_program is the default value for Program parameter in a lot of fluid APIs. For example, the Executor.run() will execute the default_main_program when the program is not specified.

If you want to replace the default main program, you can use program_guard

Returns

a Program which holding the descriptions of ops and variables in the network.

Return type

Program

Examples

import paddle.fluid as fluid

# Sample Network:
data = fluid.data(name='image', shape=[None, 3, 224, 224], dtype='float32')
label = fluid.data(name='label', shape=[None, 1], dtype='int64')

conv1 = fluid.layers.conv2d(data, 4, 5, 1, act=None)
bn1 = fluid.layers.batch_norm(conv1, act='relu')
pool1 = fluid.layers.pool2d(bn1, 2, 'max', 2)
conv2 = fluid.layers.conv2d(pool1, 16, 5, 1, act=None)
bn2 = fluid.layers.batch_norm(conv2, act='relu')
pool2 = fluid.layers.pool2d(bn2, 2, 'max', 2)

fc1 = fluid.layers.fc(pool2, size=50, act='relu')
fc2 = fluid.layers.fc(fc1, size=102, act='softmax')

loss = fluid.layers.cross_entropy(input=fc2, label=label)
loss = fluid.layers.mean(loss)
opt = fluid.optimizer.Momentum(
    learning_rate=0.1,
    momentum=0.9,
    regularization=fluid.regularizer.L2Decay(1e-4))
opt.minimize(loss)

#print the number of blocks in the program, 1 in this case
print(fluid.default_main_program().num_blocks)

#print the description of variable 'image'
print(fluid.default_main_program().blocks[0].var('image'))