From b3a2d4bdaa149f876052046c852c9e6af986c4e4 Mon Sep 17 00:00:00 2001 From: yujianfeng Date: Fri, 12 Mar 2021 15:54:56 +0800 Subject: [PATCH] Not print the tensor python object util it has been initialized --- mindspore/common/tensor.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mindspore/common/tensor.py b/mindspore/common/tensor.py index 4bf629e805..b4035b42aa 100644 --- a/mindspore/common/tensor.py +++ b/mindspore/common/tensor.py @@ -67,6 +67,7 @@ class Tensor(Tensor_): """ def __init__(self, input_data=None, dtype=None, shape=None, init=None): + self.init_finished = False # If input data is numpy number, convert it to np array if isinstance(input_data, np_types): input_data = np.array(input_data) @@ -109,6 +110,7 @@ class Tensor(Tensor_): Tensor_.__init__(self, dtype, shape) self._virtual_flag = False self.init = init + self.init_finished = True def __deepcopy__(self, memodict): new_obj = Tensor(self) @@ -117,8 +119,10 @@ class Tensor(Tensor_): return new_obj def __repr__(self): - Tensor_.data_sync(self, False) - return Tensor_.__repr__(self) + if self.init_finished: + Tensor_.data_sync(self, False) + return Tensor_.__repr__(self) + return '' def __add__(self, other): out = tensor_operator_registry.get('__add__')(self, other)