guard

paddle.fluid.dygraph.guard(place=None)[source]

This context will create a dygraph context for dygraph to run, using python with statement.

Parameters

place (fluid.CPUPlace or fluid.CUDAPlace, optional) – Place to execute dygraph. If None, the running place will be determined according to the way of paddle compilation. Default: None

Returns

None

Examples

import numpy as np
import paddle.fluid as fluid

with fluid.dygraph.guard():
    inp = np.ones([3, 32, 32], dtype='float32')
    t = fluid.dygraph.base.to_variable(inp)
    fc1 = fluid.FC('fc1', size=4, bias_attr=False, num_flatten_dims=1)
    fc2 = fluid.FC('fc2', size=4)
    ret = fc1(t)
    dy_ret = fc2(ret)