load_from_file

paddle.static. load_from_file ( path: str ) → bytes [source]

Load file in binary mode.

Parameters

path (str) – Path of an existed file.

Returns

Content of file.

Return type

bytes

Examples

>>> 
>>> import paddle
>>> paddle.enable_static()
>>> path_prefix = "./infer_model"

# Define user network, here a softmax regression example
>>> image = paddle.static.data(name='img', shape=[None, 28, 28], dtype='float32')
>>> label = paddle.static.data(name='label', shape=[None, 1], dtype='int64')
>>> predict = paddle.static.nn.fc(image, 10, activation='softmax')
>>> loss = paddle.nn.functional.cross_entropy(predict, label)
>>> exe = paddle.static.Executor(paddle.CPUPlace())
>>> exe.run(paddle.static.default_startup_program())

# Serialize parameters
>>> serialized_params = paddle.static.serialize_persistables([image], [predict], exe)

# Save serialized parameters to file
>>> params_path = path_prefix + ".params"
>>> paddle.static.save_to_file(params_path, serialized_params)

# Load serialized parameters from file
>>> serialized_params_copy = paddle.static.load_from_file(params_path)