mindspore.parse_print

mindspore.parse_print(print_file_name)[source]

Parse saved data generated by mindspore.ops.Print. Print is used to print data to screen in graph mode. It can also been turned off by setting the parameter print_file_path in context, and the data will be saved in a file specified by print_file_path. parse_print is used to parse the saved file. For more information please refer to mindspore.context.set_context() and mindspore.ops.Print.

Parameters

print_file_name (str) – The file name of saved print data.

Returns

List, element of list is Tensor.

Raises

ValueError – The print file may be empty, please make sure enter the correct file name.

Examples

>>> import numpy as np
>>> import mindspore
>>> import mindspore.ops as ops
>>> from mindspore import nn
>>> from mindspore import Tensor, context
>>> context.set_context(mode=context.GRAPH_MODE, print_file_path='log.data')
>>> class PrintInputTensor(nn.Cell):
...         def __init__(self):
...             super().__init__()
...             self.print = ops.Print()
...
...         def construct(self, input_pra):
...             self.print('print:', input_pra)
...             return input_pra
>>> x = np.array([[1, 2, 3, 4], [5, 6, 7, 8]]).astype(np.float32)
>>> input_pra = Tensor(x)
>>> net = PrintInputTensor()
>>> net(input_pra)
>>> import mindspore
>>> data = mindspore.parse_print('./log.data')
>>> print(data)
['print:', Tensor(shape=[2, 4], dtype=Float32, value=
[[ 1.00000000e+00,  2.00000000e+00,  3.00000000e+00,  4.00000000e+00],
[ 5.00000000e+00,  6.00000000e+00,  7.00000000e+00,  8.00000000e+00]])]